summaryrefslogtreecommitdiff
path: root/node_modules/@11ty/dependency-tree
diff options
context:
space:
mode:
authorShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
committerShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
commit7a52ddeba2a68388b544f529d2d92104420f77b0 (patch)
tree15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/@11ty/dependency-tree
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/@11ty/dependency-tree')
-rw-r--r--node_modules/@11ty/dependency-tree/LICENSE21
-rw-r--r--node_modules/@11ty/dependency-tree/README.md94
-rw-r--r--node_modules/@11ty/dependency-tree/main.js132
-rw-r--r--node_modules/@11ty/dependency-tree/package.json41
4 files changed, 288 insertions, 0 deletions
diff --git a/node_modules/@11ty/dependency-tree/LICENSE b/node_modules/@11ty/dependency-tree/LICENSE
new file mode 100644
index 0000000..bad6417
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019 Zach Leatherman
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/node_modules/@11ty/dependency-tree/README.md b/node_modules/@11ty/dependency-tree/README.md
new file mode 100644
index 0000000..110ab3a
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree/README.md
@@ -0,0 +1,94 @@
+# `dependency-tree`
+
+Returns an unordered array of local paths to dependencies of a CommonJS node JavaScript file (everything it or any of its dependencies `require`s).
+
+* See also: [`dependency-tree-esm`](https://github.com/11ty/eleventy-dependency-tree-esm) for ES Modules.
+
+Reduced feature (faster) alternative to the [`dependency-tree` package](https://www.npmjs.com/package/dependency-tree). This is used by Eleventy to find dependencies of a JavaScript file to watch for changes to re-run Eleventy’s build.
+
+## Big Huge Caveat
+
+⚠ A big caveat to this plugin is that it will require the file in order to build a dependency tree. So if your module has side effects and you don’t want it to execute—do not use this!
+
+## Installation
+
+```
+npm install --save-dev @11ty/dependency-tree
+```
+
+## Features
+
+* Ignores `node_modules`
+* Or, use `nodeModuleNames` to control whether or not `node_modules` package names are included (added in v2.0.1)
+* Ignores Node’s built-ins (e.g. `path`)
+* Handles circular dependencies (Node does this too)
+
+## Usage
+
+```js
+// my-file.js
+
+// if my-local-dependency.js has dependencies, it will include those too
+const test = require("./my-local-dependency.js");
+
+// ignored, is a built-in
+const path = require("path");
+```
+
+```js
+const DependencyTree = require("@11ty/dependency-tree");
+
+DependencyTree("./my-file.js");
+// returns ["./my-local-dependency.js"]
+```
+
+### `allowNotFound`
+
+```js
+const DependencyTree = require("@11ty/dependency-tree");
+
+DependencyTree("./this-does-not-exist.js"); // throws an error
+
+DependencyTree("./this-does-not-exist.js", { allowNotFound: true });
+// returns []
+```
+
+### `nodeModuleNames`
+
+(Added in v2.0.1) Controls whether or not node package names are included in the list of dependencies.
+
+* `nodeModuleNames: "include"`: included alongside the local JS files.
+* `nodeModuleNames: "exclude"` (default): node module package names are excluded.
+* `nodeModuleNames: "only"`: only node module package names are returned.
+
+```js
+// my-file.js:
+
+require("./my-local-dependency.js");
+require("@11ty/eleventy");
+```
+
+```js
+const DependencyTree = require("@11ty/dependency-tree");
+
+DependencyTree("./my-file.js");
+// returns ["./my-local-dependency.js"]
+
+DependencyTree("./my-file.js", { nodeModuleNames: "exclude" });
+// returns ["./my-local-dependency.js"]
+
+DependencyTree("./my-file.js", { nodeModuleNames: "include" });
+// returns ["./my-local-dependency.js", "@11ty/eleventy"]
+
+DependencyTree("./my-file.js", { nodeModuleNames: "only" });
+// returns ["@11ty/eleventy"]
+```
+
+#### (Deprecated) `nodeModuleNamesOnly`
+
+(Added in v2.0.0) Changed to use `nodeModuleNames` option instead. Backwards compatibility is maintained automatically.
+
+* `nodeModuleNamesOnly: false` is mapped to `nodeModuleNames: "exclude"`
+* `nodeModuleNamesOnly: true` is mapped to `nodeModuleNames: "only"`
+
+If both `nodeModuleNamesOnly` and `nodeModuleNames` are included in options, `nodeModuleNames` takes precedence.
diff --git a/node_modules/@11ty/dependency-tree/main.js b/node_modules/@11ty/dependency-tree/main.js
new file mode 100644
index 0000000..9edf2be
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree/main.js
@@ -0,0 +1,132 @@
+const path = require("path");
+const { TemplatePath } = require("@11ty/eleventy-utils");
+
+function getAbsolutePath(filename) {
+ let normalizedFilename = path.normalize(filename); // removes dot slash
+ let hasDotSlash = filename.startsWith("./");
+ return hasDotSlash ? path.join(path.resolve("."), normalizedFilename) : normalizedFilename;
+}
+
+function getRelativePath(filename) {
+ let normalizedFilename = path.normalize(filename); // removes dot slash
+ let workingDirectory = path.resolve(".");
+ let result = "./" + (normalizedFilename.startsWith(workingDirectory) ? normalizedFilename.substr(workingDirectory.length + 1) : normalizedFilename);
+ return result;
+}
+
+function getNodeModuleName(filename) {
+ let foundNodeModules = false;
+ let moduleName = [];
+
+ let s = filename.split(path.sep);
+ for(let entry of s) {
+ if(entry === '.pnpm') {
+ foundNodeModules = false;
+ }
+
+ if(foundNodeModules) {
+ moduleName.push(entry);
+ if(!entry.startsWith("@")) {
+ return moduleName.join("/");
+ }
+ }
+
+ if(entry === "node_modules") {
+ foundNodeModules = true;
+ }
+ }
+
+ return false;
+}
+
+/* unordered */
+function getDependenciesFor(filename, avoidCircular, optionsArg = {}) {
+ // backwards compatibility with `nodeModuleNamesOnly` boolean option
+ // Using `nodeModuleNames` property moving forward
+ if(("nodeModuleNamesOnly" in optionsArg) && !("nodeModuleNames" in optionsArg)) {
+ if(optionsArg.nodeModuleNamesOnly === true) {
+ optionsArg.nodeModuleNames = "only";
+ }
+ if(optionsArg.nodeModuleNamesOnly === false) {
+ optionsArg.nodeModuleNames = "exclude";
+ }
+ }
+
+ let options = Object.assign({
+ allowNotFound: false,
+ nodeModuleNames: "exclude", // also "include" or "only"
+ }, optionsArg);
+ let absoluteFilename = getAbsolutePath(filename)
+
+ try {
+ require(absoluteFilename);
+ } catch(e) {
+ if(e.code === "MODULE_NOT_FOUND" && options.allowNotFound) {
+ // do nothing
+ } else {
+ throw e;
+ }
+ }
+
+
+ let mod;
+ for(let entry in require.cache) {
+ if(entry === absoluteFilename) {
+ mod = require.cache[entry];
+ break;
+ }
+ }
+
+ let dependencies = new Set();
+
+ if(!mod) {
+ if(!options.allowNotFound) {
+ throw new Error(`Could not find ${filename} in @11ty/dependency-tree`);
+ }
+ } else {
+ let relativeFilename = getRelativePath(mod.filename);
+ if(!avoidCircular) {
+ avoidCircular = {};
+ } else if(options.nodeModuleNames !== "only") {
+ dependencies.add(relativeFilename);
+ }
+
+ avoidCircular[relativeFilename] = true;
+
+ if(mod.children) {
+ for(let child of mod.children) {
+ let relativeChildFilename = getRelativePath(child.filename);
+ let nodeModuleName = getNodeModuleName(child.filename);
+
+ if(options.nodeModuleNames !== "exclude" && nodeModuleName) {
+ dependencies.add(nodeModuleName);
+ }
+ // Add dependencies of this dependency (not top level node_modules)
+ if(nodeModuleName === false) {
+ if(!dependencies.has(relativeChildFilename) && // avoid infinite looping with circular deps
+ !avoidCircular[relativeChildFilename] ) {
+ for(let dependency of getDependenciesFor(relativeChildFilename, avoidCircular, options)) {
+ dependencies.add(dependency);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return dependencies;
+}
+
+function getCleanDependencyListFor(filename, options = {}) {
+ let deps = Array.from( getDependenciesFor(filename, null, options) );
+
+ return deps.map(filePath => {
+ if(filePath.startsWith("./")) {
+ return TemplatePath.standardizeFilePath(filePath);
+ }
+ return filePath; // node_module name
+ });
+}
+
+module.exports = getCleanDependencyListFor;
+module.exports.getNodeModuleName = getNodeModuleName; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree/package.json b/node_modules/@11ty/dependency-tree/package.json
new file mode 100644
index 0000000..0c24b6c
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree/package.json
@@ -0,0 +1,41 @@
+{
+ "name": "@11ty/dependency-tree",
+ "version": "4.0.0",
+ "description": "Finds all JavaScript CommmonJS require() dependencies from a filename.",
+ "main": "main.js",
+ "files": [
+ "main.js",
+ "!test",
+ "!test/**"
+ ],
+ "scripts": {
+ "test": "npx ava"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/11ty/eleventy-dependency-tree.git"
+ },
+ "author": {
+ "name": "Zach Leatherman",
+ "email": "zach@zachleat.com",
+ "url": "https://zachleat.com/"
+ },
+ "license": "MIT",
+ "ava": {
+ "files": [
+ "./test/*.js"
+ ],
+ "watchMode": {
+ "ignoreChanged": [
+ "./test/stubs/**"
+ ]
+ }
+ },
+ "devDependencies": {
+ "@sindresorhus/is": "^4.6.0",
+ "ava": "^6.2.0"
+ },
+ "dependencies": {
+ "@11ty/eleventy-utils": "^2.0.1"
+ }
+}