summaryrefslogtreecommitdiff
path: root/node_modules/@11ty/dependency-tree-esm
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@11ty/dependency-tree-esm')
-rw-r--r--node_modules/@11ty/dependency-tree-esm/.github/workflows/ci.yml22
-rw-r--r--node_modules/@11ty/dependency-tree-esm/.github/workflows/release.yml24
-rw-r--r--node_modules/@11ty/dependency-tree-esm/LICENSE21
-rw-r--r--node_modules/@11ty/dependency-tree-esm/README.md40
-rw-r--r--node_modules/@11ty/dependency-tree-esm/main.js98
-rw-r--r--node_modules/@11ty/dependency-tree-esm/package.json38
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/circular-child.js1
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/circular-parent.js1
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/circular-self.js2
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/empty.js0
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/file.js2
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/import-attributes.js3
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/imported-secondary.js3
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/imported.js3
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/imported.json3
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/nested-grandchild.js1
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/stubs/nested.js2
-rw-r--r--node_modules/@11ty/dependency-tree-esm/test/test.js35
18 files changed, 299 insertions, 0 deletions
diff --git a/node_modules/@11ty/dependency-tree-esm/.github/workflows/ci.yml b/node_modules/@11ty/dependency-tree-esm/.github/workflows/ci.yml
new file mode 100644
index 0000000..cccfbd7
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/.github/workflows/ci.yml
@@ -0,0 +1,22 @@
+on:
+ push:
+ branches-ignore:
+ - "gh-pages"
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: ["ubuntu-latest", "macos-latest", "windows-latest"]
+ node: ["18", "20", "22"]
+ name: Node.js ${{ matrix.node }} on ${{ matrix.os }}
+ steps:
+ - uses: actions/checkout@v3
+ - name: Setup node
+ uses: actions/setup-node@v3
+ with:
+ node-version: ${{ matrix.node }}
+ - run: npm install
+ - run: npm test
+env:
+ YARN_GPG: no
diff --git a/node_modules/@11ty/dependency-tree-esm/.github/workflows/release.yml b/node_modules/@11ty/dependency-tree-esm/.github/workflows/release.yml
new file mode 100644
index 0000000..d527272
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/.github/workflows/release.yml
@@ -0,0 +1,24 @@
+name: Publish Release to npm
+on:
+ release:
+ types: [published]
+permissions: read-all
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ id-token: write
+ steps:
+ - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # 4.1.7
+ - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # 4.0.3
+ with:
+ node-version: "20"
+ registry-url: 'https://registry.npmjs.org'
+ - run: npm ci
+ - run: npm test
+ - if: ${{ github.event.release.tag_name != '' && env.NPM_PUBLISH_TAG != '' }}
+ run: npm publish --provenance --access=public --tag=${{ env.NPM_PUBLISH_TAG }}
+ env:
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+ NPM_PUBLISH_TAG: ${{ contains(github.event.release.tag_name, '-beta.') && 'beta' || 'latest' }}
diff --git a/node_modules/@11ty/dependency-tree-esm/LICENSE b/node_modules/@11ty/dependency-tree-esm/LICENSE
new file mode 100644
index 0000000..cb72e93
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2023 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-esm/README.md b/node_modules/@11ty/dependency-tree-esm/README.md
new file mode 100644
index 0000000..56b0f56
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/README.md
@@ -0,0 +1,40 @@
+# `dependency-tree-esm`
+
+Returns an unordered array of local paths to dependencies of a Node ES module JavaScript file.
+
+* See also: [`dependency-tree`](https://github.com/11ty/eleventy-dependency-tree) for the CommonJS version.
+
+This is used by Eleventy to find dependencies of a JavaScript file to watch for changes to re-run Eleventy’s build.
+
+## Installation
+
+```
+npm install --save-dev @11ty/dependency-tree-esm
+```
+
+## Features
+
+* Ignores bare specifiers (e.g. `import "my-package"`)
+* Ignores Node’s built-ins (e.g. `import "path"`)
+* Handles circular dependencies
+* Returns an empty set if the file does not exist.
+
+## Usage
+
+```js
+// my-file.js
+
+// if my-local-dependency.js has dependencies, it will include those too
+import "./my-local-dependency.js";
+
+
+// ignored, is a built-in
+import path from "path";
+```
+
+```js
+const { find } = require("@11ty/dependency-tree-esm");
+
+await find("./my-file.js");
+// returns ["./my-local-dependency.js"]
+```
diff --git a/node_modules/@11ty/dependency-tree-esm/main.js b/node_modules/@11ty/dependency-tree-esm/main.js
new file mode 100644
index 0000000..ad2e0d0
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/main.js
@@ -0,0 +1,98 @@
+const path = require("path");
+const { existsSync } = require("fs");
+const { readFile } = require("fs/promises");
+
+const acorn = require("acorn");
+const normalizePath = require("normalize-path");
+const { TemplatePath } = require("@11ty/eleventy-utils");
+
+// Is *not* a bare specifier (e.g. 'some-package')
+// https://nodejs.org/dist/latest-v18.x/docs/api/esm.html#terminology
+function isNonBareSpecifier(importSource) {
+ // Change \\ to / on Windows
+ let normalized = normalizePath(importSource);
+ // Relative specifier (e.g. './startup.js')
+ if(normalized.startsWith("./") || normalized.startsWith("../")) {
+ return true;
+ }
+ // Absolute specifier (e.g. 'file:///opt/nodejs/config.js')
+ if(normalized.startsWith("file:")) {
+ return true;
+ }
+
+ return false;
+}
+
+function normalizeFilePath(filePath) {
+ return TemplatePath.standardizeFilePath(path.relative(".", filePath));
+}
+
+function normalizeImportSourceToFilePath(filePath, source) {
+ let { dir } = path.parse(filePath);
+ let normalized = path.join(dir, source);
+ return normalizeFilePath(normalized);
+}
+
+function getImportAttributeType(attributes = []) {
+ for(let node of attributes) {
+ if(node.type === "ImportAttribute" && node.key.type === "Identifier" && node.key.name === "type") {
+ return node.value.value;
+ }
+ }
+}
+
+async function findByContents(contents, filePath, alreadyParsedSet) {
+ // Should we use dependency-graph for these relationships?
+ let sources = new Set();
+ let nestedSources = new Set();
+
+ let ast = acorn.parse(contents, {sourceType: "module", ecmaVersion: "latest"});
+
+ for(let node of ast.body) {
+ if(node.type === "ImportDeclaration" && isNonBareSpecifier(node.source.value)) {
+ let importAttributeType = getImportAttributeType(node?.attributes);
+ let normalized = normalizeImportSourceToFilePath(filePath, node.source.value);
+ if(normalized !== filePath) {
+ sources.add(normalized);
+
+ // Right now only `css` and `json` are valid but others might come later
+ if(!importAttributeType) {
+ nestedSources.add(normalized);
+ }
+ }
+ }
+ }
+
+ // Recurse for nested deps
+ for(let source of nestedSources) {
+ let s = await find(source, alreadyParsedSet);
+ for(let p of s) {
+ if(sources.has(p) || p === filePath) {
+ continue;
+ }
+
+ sources.add(p);
+ }
+ }
+
+ return Array.from(sources);
+}
+
+async function find(filePath, alreadyParsedSet = new Set()) {
+ // TODO add a cache here
+ // Unfortunately we need to read the entire file, imports need to be at the top level but they can be anywhere 🫠
+ let normalized = normalizeFilePath(filePath);
+ if(alreadyParsedSet.has(normalized) || !existsSync(filePath)) {
+ return [];
+ }
+ alreadyParsedSet.add(normalized);
+
+ let contents = await readFile(normalized, { encoding: 'utf8' });
+ let sources = await findByContents(contents, normalized, alreadyParsedSet);
+
+ return sources;
+}
+
+module.exports = {
+ find
+}; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/package.json b/node_modules/@11ty/dependency-tree-esm/package.json
new file mode 100644
index 0000000..d49a094
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/package.json
@@ -0,0 +1,38 @@
+{
+ "name": "@11ty/dependency-tree-esm",
+ "version": "2.0.0",
+ "description": "Finds all JavaScript ES Module dependencies from a filename.",
+ "main": "main.js",
+ "scripts": {
+ "test": "npx ava"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/11ty/eleventy-dependency-tree-esm.git"
+ },
+ "author": {
+ "name": "Zach Leatherman",
+ "email": "zach@zachleat.com",
+ "url": "https://zachleat.com/"
+ },
+ "license": "MIT",
+ "dependencies": {
+ "@11ty/eleventy-utils": "^2.0.1",
+ "acorn": "^8.14.0",
+ "dependency-graph": "^1.0.0",
+ "normalize-path": "^3.0.0"
+ },
+ "devDependencies": {
+ "ava": "^6.2.0"
+ },
+ "ava": {
+ "files": [
+ "./test/*.js"
+ ],
+ "watchMode": {
+ "ignoreChanges": [
+ "./test/stubs/**"
+ ]
+ }
+ }
+}
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-child.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-child.js
new file mode 100644
index 0000000..1b9ba5e
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-child.js
@@ -0,0 +1 @@
+import "./circular-parent.js"; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-parent.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-parent.js
new file mode 100644
index 0000000..3153b84
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-parent.js
@@ -0,0 +1 @@
+import "./circular-child.js"; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-self.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-self.js
new file mode 100644
index 0000000..267b293
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/circular-self.js
@@ -0,0 +1,2 @@
+import "./circular-self.js";
+import "./empty.js"; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/empty.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/empty.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/empty.js
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/file.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/file.js
new file mode 100644
index 0000000..c97bcbb
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/file.js
@@ -0,0 +1,2 @@
+import fs from "fs";
+import * as fdklsjf from "./imported-secondary.js"; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/import-attributes.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/import-attributes.js
new file mode 100644
index 0000000..a4584e4
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/import-attributes.js
@@ -0,0 +1,3 @@
+import eleventyPackage from "./imported.json" with { type: 'json' };
+
+console.log( eleventyPackage ); \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/imported-secondary.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/imported-secondary.js
new file mode 100644
index 0000000..b70cefb
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/imported-secondary.js
@@ -0,0 +1,3 @@
+import "fs";
+
+export function hello() {} \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/imported.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/imported.js
new file mode 100644
index 0000000..479ee82
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/imported.js
@@ -0,0 +1,3 @@
+import * as fdklsjf from "./imported-secondary.js";
+
+export function hello() {} \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/imported.json b/node_modules/@11ty/dependency-tree-esm/test/stubs/imported.json
new file mode 100644
index 0000000..f2aed13
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/imported.json
@@ -0,0 +1,3 @@
+{
+ "foo": "bar"
+} \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/nested-grandchild.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/nested-grandchild.js
new file mode 100644
index 0000000..b533597
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/nested-grandchild.js
@@ -0,0 +1 @@
+import * as fdklsjf from "./nested.js"; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/stubs/nested.js b/node_modules/@11ty/dependency-tree-esm/test/stubs/nested.js
new file mode 100644
index 0000000..26618f6
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/stubs/nested.js
@@ -0,0 +1,2 @@
+import fs from "fs";
+import * as fdklsjf from "./imported.js"; \ No newline at end of file
diff --git a/node_modules/@11ty/dependency-tree-esm/test/test.js b/node_modules/@11ty/dependency-tree-esm/test/test.js
new file mode 100644
index 0000000..c777857
--- /dev/null
+++ b/node_modules/@11ty/dependency-tree-esm/test/test.js
@@ -0,0 +1,35 @@
+const test = require("ava");
+const { find } = require("../main.js");
+
+test("Empty", async t => {
+ t.deepEqual(await find("./test/stubs/empty.js"), []);
+});
+
+test("Doesn’t exist", async t => {
+ t.deepEqual(await find("./test/stubs/THIS_FILE_DOES_NOT_EXIST.js"), []);
+});
+
+test("Simple", async t => {
+ t.deepEqual(await find("./test/stubs/file.js"), ["./test/stubs/imported-secondary.js"]);
+});
+
+test("Nested two deep", async t => {
+ t.deepEqual(await find("./test/stubs/nested.js"), ["./test/stubs/imported.js", "./test/stubs/imported-secondary.js"]);
+});
+
+test("Nested three deep", async t => {
+ t.deepEqual(await find("./test/stubs/nested-grandchild.js"), ["./test/stubs/nested.js", "./test/stubs/imported.js", "./test/stubs/imported-secondary.js"]);
+});
+
+test("Circular", async t => {
+ t.deepEqual(await find("./test/stubs/circular-parent.js"), ["./test/stubs/circular-child.js"]);
+});
+
+test("Circular Self Reference", async t => {
+ t.deepEqual(await find("./test/stubs/circular-self.js"), ["./test/stubs/empty.js"]);
+});
+
+// https://github.com/11ty/eleventy-dependency-tree-esm/issues/2
+test("Import Attributes, issue #2", async t => {
+ t.deepEqual(await find("./test/stubs/import-attributes.js"), ["./test/stubs/imported.json"]);
+});