Initial commit: 11ty website with Fire/Frost branding
This commit is contained in:
21
node_modules/@11ty/dependency-tree-esm/LICENSE
generated
vendored
Normal file
21
node_modules/@11ty/dependency-tree-esm/LICENSE
generated
vendored
Normal file
@@ -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.
|
||||
53
node_modules/@11ty/dependency-tree-esm/README.md
generated
vendored
Normal file
53
node_modules/@11ty/dependency-tree-esm/README.md
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
# `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
|
||||
import { find } from "@11ty/dependency-tree-esm";
|
||||
// CommonJS is fine too
|
||||
// const { find } = require("@11ty/dependency-tree-esm");
|
||||
|
||||
await find("./my-file.js");
|
||||
// returns ["./my-local-dependency.js"]
|
||||
```
|
||||
|
||||
Return a [dependency-graph](https://github.com/jriecken/dependency-graph) instance:
|
||||
|
||||
```js
|
||||
import { findGraph } from "@11ty/dependency-tree-esm";
|
||||
// CommonJS is fine too
|
||||
// const { find } = require("@11ty/dependency-tree-esm");
|
||||
|
||||
(await findGraph("./my-file.js")).overallOrder();
|
||||
// returns ["./my-local-dependency.js", "./my-file.js"]
|
||||
```
|
||||
173
node_modules/@11ty/dependency-tree-esm/main.js
generated
vendored
Normal file
173
node_modules/@11ty/dependency-tree-esm/main.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
const path = require("node:path");
|
||||
const { readFileSync, existsSync } = require("node:fs");
|
||||
|
||||
const acorn = require("acorn");
|
||||
const normalizePath = require("normalize-path");
|
||||
const { TemplatePath } = require("@11ty/eleventy-utils");
|
||||
const { DepGraph } = require("dependency-graph");
|
||||
|
||||
// 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 getSources(filePath, contents, options = {}) {
|
||||
let { parserOverride } = Object.assign({}, options);
|
||||
let sources = new Set();
|
||||
let sourcesToRecurse = new Set();
|
||||
|
||||
let ast = (parserOverride || 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);
|
||||
|
||||
// Recurse typeless (JavaScript) import types only
|
||||
// Right now only `css` and `json` are valid but others might come later
|
||||
if(!importAttributeType) {
|
||||
sourcesToRecurse.add(normalized);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
sources,
|
||||
sourcesToRecurse,
|
||||
}
|
||||
}
|
||||
|
||||
// second argument used to be `alreadyParsedSet = new Set()`, keep that backwards compat
|
||||
async function find(filePath, options = {}) {
|
||||
if(options instanceof Set) {
|
||||
options = {
|
||||
alreadyParsedSet: options
|
||||
};
|
||||
}
|
||||
|
||||
if(!options.alreadyParsedSet) {
|
||||
options.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(options.alreadyParsedSet.has(normalized) || !existsSync(filePath)) {
|
||||
return [];
|
||||
}
|
||||
options.alreadyParsedSet.add(normalized);
|
||||
|
||||
let contents = readFileSync(normalized, { encoding: 'utf8' });
|
||||
let { sources, sourcesToRecurse } = await getSources(filePath, contents, options);
|
||||
|
||||
// Recurse for nested deps
|
||||
for(let source of sourcesToRecurse) {
|
||||
let s = await find(source, options);
|
||||
for(let p of s) {
|
||||
if(sources.has(p) || p === filePath) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sources.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(sources);
|
||||
}
|
||||
|
||||
function mergeGraphs(rootGraph, ...graphs) {
|
||||
if(!(rootGraph instanceof DepGraph)) {
|
||||
throw new Error("Incorrect type passed to mergeGraphs, expected DepGraph");
|
||||
}
|
||||
for(let g of graphs) {
|
||||
for(let node of g.overallOrder()) {
|
||||
if(!rootGraph.hasNode(node)) {
|
||||
rootGraph.addNode(node);
|
||||
}
|
||||
for(let dep of g.directDependenciesOf(node)) {
|
||||
rootGraph.addDependency(node, dep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// second argument used to be `alreadyParsedSet = new Set()`, keep that backwards compat
|
||||
async function findGraph(filePath, options = {}) {
|
||||
if(options instanceof Set) {
|
||||
options = {
|
||||
alreadyParsedSet: options
|
||||
};
|
||||
}
|
||||
if(!options.alreadyParsedSet) {
|
||||
options.alreadyParsedSet = new Set();
|
||||
}
|
||||
|
||||
let graph = new DepGraph();
|
||||
let normalized = normalizeFilePath(filePath);
|
||||
graph.addNode(filePath);
|
||||
|
||||
if(options.alreadyParsedSet.has(normalized) || !existsSync(filePath)) {
|
||||
return graph;
|
||||
}
|
||||
options.alreadyParsedSet.add(normalized);
|
||||
|
||||
let contents = readFileSync(normalized, "utf8");
|
||||
let { sources, sourcesToRecurse } = await getSources(filePath, contents, options);
|
||||
for(let source of sources) {
|
||||
if(!graph.hasNode(source)) {
|
||||
graph.addNode(source);
|
||||
}
|
||||
graph.addDependency(normalized, source);
|
||||
}
|
||||
|
||||
// Recurse for nested deps
|
||||
for(let source of sourcesToRecurse) {
|
||||
let recursedGraph = await findGraph(source, options);
|
||||
mergeGraphs(graph, recursedGraph);
|
||||
}
|
||||
|
||||
return graph;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
find,
|
||||
findGraph,
|
||||
mergeGraphs,
|
||||
};
|
||||
26
node_modules/@11ty/dependency-tree-esm/package.json
generated
vendored
Normal file
26
node_modules/@11ty/dependency-tree-esm/package.json
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@11ty/dependency-tree-esm",
|
||||
"version": "2.0.4",
|
||||
"description": "Finds all JavaScript ES Module dependencies from a filename.",
|
||||
"main": "main.js",
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: run tests from root directory\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/11ty/eleventy-utils.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Zach Leatherman",
|
||||
"email": "zach@zachleat.com",
|
||||
"url": "https://zachleat.com/"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@11ty/eleventy-utils": "^2.0.7",
|
||||
"acorn": "^8.15.0",
|
||||
"dependency-graph": "^1.0.0",
|
||||
"normalize-path": "^3.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user