Skip to content

Commit

Permalink
Fixes #182
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Sep 12, 2018
1 parent 89681c8 commit 86368a8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
const chalk = require("chalk");
const TemplateConfig = require("./TemplateConfig");
const EleventyErrorHandler = require("./EleventyErrorHandler");
const debug = require("debug")("Eleventy:Config");

debug("Setting up global TemplateConfig.");
let config = new TemplateConfig();
let config;
try {
config = new TemplateConfig();
} catch (e) {
console.log("\n" + chalk.red("Problem with Eleventy configuration: "));

EleventyErrorHandler.log(e);
}

module.exports = config;
2 changes: 1 addition & 1 deletion src/Engines/Liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const LiquidLib = require("liquidjs");
const TemplateEngine = require("./TemplateEngine");
const lodashMerge = require("lodash.merge");
const config = require("../Config");
const debug = require("debug")("Eleventy:Liquid");
// const debug = require("debug")("Eleventy:Liquid");

class Liquid extends TemplateEngine {
constructor(name, inputDir) {
Expand Down
13 changes: 8 additions & 5 deletions src/TemplateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const chalk = require("chalk");
const fs = require("fs-extra");
const lodashMerge = require("lodash.merge");
const TemplatePath = require("./TemplatePath");
const EleventyBaseError = require("./EleventyBaseError");
const EleventyErrorHandler = require("./EleventyErrorHandler");
const eleventyConfig = require("./EleventyConfig");
const debug = require("debug")("Eleventy:TemplateConfig");

class EleventyConfigError extends EleventyBaseError {}

class TemplateConfig {
constructor(customRootConfig, localProjectConfigPath) {
this.overrides = {};
Expand Down Expand Up @@ -78,11 +82,10 @@ class TemplateConfig {
localConfig = require(path);
// debug( "localConfig require return value: %o", localConfig );
} catch (err) {
// TODO if file does exist, rethrow the error or console.log the error (file has syntax problem)

// if file does not exist, return empty obj
localConfig = {};
debug(chalk.red("Problem getting localConfig file, %o"), err);
throw new EleventyConfigError(
`Error in your Eleventy config file '${path}'`,
err
);
}
} else {
debug("Eleventy local project config file not found, skipping.");
Expand Down
9 changes: 9 additions & 0 deletions test/TemplateConfigTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,12 @@ test("libraryOverrides", t => {
t.truthy(cfg.libraryOverrides.md);
t.deepEqual(mdLib, cfg.libraryOverrides.md);
});

test("Properly throws error on missing module #182", t => {
t.throws(function() {
new TemplateConfig(
require("../config.js"),
"./test/stubs/broken-config.js"
);
});
});
9 changes: 9 additions & 0 deletions test/stubs/broken-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const missingModule = require("this-is-a-module-that-does-not-exist");

module.exports = function(eleventyConfig) {
eleventyConfig.addFilter("cssmin", function(code) {
return missingModule(code);
});

return {};
};

0 comments on commit 86368a8

Please sign in to comment.