diff --git a/src/Eleventy.js b/src/Eleventy.js index fa8595141..c368321ef 100644 --- a/src/Eleventy.js +++ b/src/Eleventy.js @@ -68,6 +68,7 @@ Eleventy.prototype.restart = async function() { this.eleventyFiles.restart(); // reload package.json values (if applicable) + // TODO only reset this if it changed delete require.cache[TemplatePath.localPath("package.json")]; this.initDirs(); @@ -226,8 +227,9 @@ Eleventy.prototype._watch = async function(path) { this.active = true; + let localProjectConfigPath = config.getLocalProjectConfigFile(); // reset and reload global configuration :O - if (path === config.getLocalProjectConfigFile()) { + if (path === localProjectConfigPath) { this.resetConfig(); } config.resetOnWatch(); @@ -271,14 +273,23 @@ Eleventy.prototype.watch = async function() { ignored: this.eleventyFiles.getGlobWatcherIgnores() }); + async function watchRun(path) { + try { + await this._watch(path); + } catch (e) { + EleventyErrorHandler.fatal(e, "Eleventy fatal watch error"); + watcher.close(); + } + } + watcher.on("change", async path => { console.log("File changed:", path); - this._watch(path); + await watchRun.call(this, path); }); watcher.on("add", async path => { console.log("File added:", path); - this._watch(path); + await watchRun.call(this, path); }); }; diff --git a/src/EleventyErrorHandler.js b/src/EleventyErrorHandler.js index b22a67542..3c3e92c95 100644 --- a/src/EleventyErrorHandler.js +++ b/src/EleventyErrorHandler.js @@ -20,22 +20,29 @@ class EleventyErrorHandler { static log(e, type = "log", prefix = ">") { let ref = e; while (ref) { + let nextRef = ref.originalError; EleventyErrorHandler.message( (process.env.DEBUG ? "" : `${prefix} `) + - `${ref.message} (${ref.name})`, + `${ref.message} (${ref.name})${!nextRef ? ":" : ""}`, type ); - debug(`(${type} stack): ${ref.stack}`); - ref = ref.originalError; + if (process.env.DEBUG) { + debug(`(${type} stack): ${ref.stack}`); + } else if (!nextRef) { + // last error in the loop + let prefix = " "; + console.error( + prefix + (ref.stack || "").split("\n").join("\n" + prefix) + ); + } + ref = nextRef; } } static initialMessage(message, type = "log", chalkColor = "blue") { if (message) { EleventyErrorHandler.message( - message + - ":" + - (process.env.DEBUG ? "" : " (full stack in DEBUG output)"), + message + ":" + (process.env.DEBUG ? "" : " (more in DEBUG output)"), type, chalkColor );