JSPM

@11ty/dependency-tree-esm

2.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 87163
  • Score
    100M100P100Q176331F
  • License MIT

Finds all JavaScript ES Module dependencies from a filename.

Package Exports

  • @11ty/dependency-tree-esm
  • @11ty/dependency-tree-esm/main.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@11ty/dependency-tree-esm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dependency-tree-esm

Returns an unordered array of local paths to dependencies of a Node ES module JavaScript file.

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

// 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";
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 instance:

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"]