Join us to discuss the challenges, solutions and best practices for in-house JavaScript code sharing. Tuesday, 12/17 at 10am PT/1pm ET.Sign up here »

@11ty/dependency-tree

1.0.0 • Public • Published

dependency-tree

Returns an unordered array of local paths to dependencies of a node JavaScript file (everything it or any of its dependencies requires).

Reduced feature (faster) alternative to the dependency-tree package that only works with stock node JS. 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

Features

  • Ignores node_modules
  • Ignores Node’s built-ins (e.g. path)
  • Handles circular dependencies (Node does this too)

Usage

// 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");
const DependencyTree = require("@11ty/dependency-tree");
 
DependencyTree("./my-file.js");
// returns ["./my-local-dependency.js"]

allowNotFound

const DependencyTree = require("@11ty/dependency-tree");
 
DependencyTree("./this-does-not-exist.js"); // throws an error
 
DependencyTree("./this-does-not-exist.js", { allowNotFound: true });
// returns []

Keywords

none

Install

npm i @11ty/dependency-tree

DownloadsWeekly Downloads

39

Version

1.0.0

License

MIT

Unpacked Size

7.53 kB

Total Files

19

Last publish

Collaborators

  • avatar