diff --git a/package.json b/package.json index 7e4a91820..74edc61c8 100755 --- a/package.json +++ b/package.json @@ -91,12 +91,12 @@ "vue-server-renderer": "^2.6.12" }, "dependencies": { - "@11ty/dependency-tree": "^1.0.0", "browser-sync": "^2.26.14", "chalk": "^4.1.0", "chokidar": "^3.5.1", "debug": "^4.3.1", "dependency-graph": "^0.10.0", + "dependency-tree": "^8.0.0", "ejs": "^3.1.5", "fast-glob": "^3.2.5", "fs-extra": "^9.1.0", diff --git a/src/Eleventy.js b/src/Eleventy.js index 29f71911b..fdba984a2 100644 --- a/src/Eleventy.js +++ b/src/Eleventy.js @@ -630,21 +630,21 @@ Arguments: } // Template files .11ty.js - this.watchTargets.addDependencies(this.eleventyFiles.getWatchPathCache()); + await this.watchTargets.addDependencies(this.eleventyFiles.getWatchPathCache()); // Config file dependencies - this.watchTargets.addDependencies( + await this.watchTargets.addDependencies( config.getLocalProjectConfigFile(), filterOutGlobalDataFiles ); // Deps from Global Data (that aren’t in the global data directory, everything is watched there) - this.watchTargets.addDependencies( + await this.watchTargets.addDependencies( this.templateData.getWatchPathCache(), filterOutGlobalDataFiles ); - this.watchTargets.addDependencies( + await this.watchTargets.addDependencies( await this.eleventyFiles.getWatcherTemplateJavaScriptDataFiles() ); } diff --git a/src/EleventyWatchTargets.js b/src/EleventyWatchTargets.js index 0079a3213..eb1271a73 100644 --- a/src/EleventyWatchTargets.js +++ b/src/EleventyWatchTargets.js @@ -1,4 +1,4 @@ -const dependencyTree = require("@11ty/dependency-tree"); +const dependencyTree = require("dependency-tree"); const TemplatePath = require("./TemplatePath"); const deleteRequireCache = require("./Util/DeleteRequireCache"); @@ -69,13 +69,13 @@ class EleventyWatchTargets { } // add only a target’s dependencies - addDependencies(targets, filterCallback) { + async addDependencies(targets, filterCallback) { if (!this.watchJavaScriptDependencies) { return; } targets = this._normalizeTargets(targets); - let deps = this.getJavaScriptDependenciesFromList(targets); + let deps = await this.getJavaScriptDependenciesFromList(targets); if (filterCallback) { deps = deps.filter(filterCallback); } @@ -87,22 +87,33 @@ class EleventyWatchTargets { this.writer = templateWriter; } - getJavaScriptDependenciesFromList(files = []) { + async getJavaScriptDependenciesFromList(files = []) { let depSet = new Set(); - files - .filter(file => file.endsWith(".js") || file.endsWith(".cjs")) // TODO does this need to work with aliasing? what other JS extensions will have deps? - .forEach(file => { - dependencyTree(file, { allowNotFound: true }) - .map(dependency => { - return TemplatePath.addLeadingDotSlash( - TemplatePath.relativePath(dependency) - ); - }) - .forEach(dependency => { - depSet.add(dependency); - }); + + const depfiles = files + .filter(file => file.endsWith(".js") || file.endsWith(".cjs")); + // TODO does this need to work with aliasing? what other JS extensions will have deps? + + for (const file of depfiles) { + const tree = dependencyTree({ + filename: file, + directory: TemplatePath.absolutePath('.'), + filter: path => path.indexOf('node_modules') === -1, + isListForm: true, }); + // remove the last item (self) + const esTree = tree.slice(0,tree.length-1); + + esTree.map(dependency => { + return TemplatePath.addLeadingDotSlash( + TemplatePath.relativePath(dependency) + ); + }) + .forEach(dependency => { + depSet.add(dependency); + }); + } return Array.from(depSet); }