Socket
Book a DemoInstallSign in
Socket

dependency-tree

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dependency-tree

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

Source
npmnpm
Version
4.0.0
Version published
Weekly downloads
2.2M
-4.82%
Maintainers
1
Weekly downloads
 
Created
Source

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({
  filename: 'path/to/a/file',
  root: '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({
  filename: 'path/to/a/file',
  root: 'path/to/all/files'
});
  • Works for JS (AMD, CommonJS, ES6 modules) and CSS preprocessors (Sass, Stylus); basically, any filetype supported by Precinct.
    • For CommonJS modules, 3rd party dependencies (npm installed dependencies) are included in the tree by default
    • Dependency path resolutions are handled by filing-cabinet
  • 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

  • config: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
  • visited: object used for avoiding redundant subtree generations via memoization.

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.

Keywords

dependency

FAQs

Package last updated on 01 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts