JSPM

  • Created
  • Published
  • Downloads 1736553
  • Score
    100M100P100Q221870F
  • License MIT

Get the dependency tree of a module (as a list)

Package Exports

  • dependency-tree

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 (dependency-tree) 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 npm npm

Get the dependency tree of a module

npm install dependency-tree

Usage

var dependencyTree = require('dependency-tree');

// Returns a dependency tree object for the given file
var tree = dependencyTree('path/to/a/file', 'path/to/all/files');

// Returns a post-order traversal (list form) of the tree with duplicate sub-trees pruned.
// This is useful for bundling source files, because the list gives the concatenation order.
var list = dependencyTree.toList('path/to/a/file', 'path/to/all/files');
  • Works for AMD, CommonJS, ES6 modules, and SASS files, basically, any filetype supported by Precinct.
  • All core Node modules (assert, path, fs, etc) are removed from the dependency list by default

The object form is a mapping of the dependency tree to the filesystem – where every key is an absolute filepath and the value is another object/subtree.

Example:

{
  '/Users/mrjoelkemp/Documents/node-dependency-tree/test/example/extended/a.js': {
    '/Users/mrjoelkemp/Documents/node-dependency-tree/test/example/extended/b.js': {
      '/Users/mrjoelkemp/Documents/node-dependency-tree/test/example/extended/d.js': {},
      '/Users/mrjoelkemp/Documents/node-dependency-tree/test/example/extended/e.js': {}
    },
    '/Users/mrjoelkemp/Documents/node-dependency-tree/test/example/extended/c.js': {
      '/Users/mrjoelkemp/Documents/node-dependency-tree/test/example/extended/f.js': {},
      '/Users/mrjoelkemp/Documents/node-dependency-tree/test/example/extended/g.js': {}
    }
  }
}

This structure was chosen to serve as a visual representation of the dependency tree for use in the Dependents plugin.

Optional

  • cache: 3rd argument that's an empty object (or shared across multiple runs of this module) used for avoiding redundant subtree generations.

Shell version (assuming npm install -g dependency-tree):

tree --directory=path/to/all/supported/files [--list-form] filename

Prints the dependency tree of the given filename as stringified json (by default).

  • You can alternatively print out the list form one element per line using the --list-form option.