get-dep-tree
v3.1.0
Published
Use npm's Arborist to get a dependency tree for a package.
Maintainers
Readme
get-dep-tree 
Use npm's Arborist to get a dependency tree for a package.
Example
const getDepTree = require('get-dep-tree');
const { Node } = require('@npmcli/arborist');
const assert = require('assert');
getDepTree().then((tree) => {
assert.ok(tree instanceof Node);
});API
getDepTree(mode, options = {})
Returns a Promise for an Arborist Node representing the root of the tree.
mode is one of:
'actual': load the tree fromnode_moduleson disk'virtual': load the tree frompackage-lock.json(a v1 lockfile is used to build an ideal tree)'ideal': build an ideal tree frompackage.json, using the registry'auto':'actual'ifpathhas anode_modulesdirectory, otherwise'virtual'if it has apackage-lock.json, otherwise'ideal'
options:
path: the package directory to load. Default:process.cwd()dev: keep dev dependencies. Default:falseproduction: keep production dependencies; whenfalse, only nodes needed by the dev hierarchy are kept (so withdev: falseas well, every dependency is pruned). Default:truepeer: keep peer dependencies. Default:trueoptional: keep optional dependencies. Default:truefullMetadata: passed through to@npmcli/arboristandpacote, for registry fetches. Default:false. Note that@npmcli/arboristalways fetches full manifests while building an ideal tree, that top-level nodes from a v1 lockfile are always given full manifests, and that'actual'and'virtual'modes otherwise do not fetch from the registry, sonode.packageonly has what is on disk (seeforceActual) or in the lockfile.packumentCache: aMapto cache packuments in; share one across calls to avoid refetching. Default: a newMaplogger: a function called with progress messages. Default:console.logforceActual: when loading fromnode_modules('actual'mode, or'auto'mode whennode_modulesexists), ignore the hidden lockfile (node_modules/.package-lock.json), so each node'spackageis its realpackage.json, rather than the subset of fields the hidden lockfile stores. Default:falseregistry: the registry URL. Default:'https://registry.npmjs.org/'- any other flattened npm config options (eg,
cache,offline, or'//registry.example.com/:_authToken') are passed through to@npmcli/arboristandpacote. Note that.npmrcfiles are not read; use@npmcli/configto load and flatten them.
Pruning applies to every node in the tree, at any depth, based on arborist's dev, optional, devOptional, and peer flags. dev: false, peer: false, and optional: false use arborist's node.shouldOmit, the same check as npm install --omit=dev/--omit=peer/--omit=optional; so, for example, a dependency needed by both the dev and the optional hierarchies is only pruned when both dev and optional are false.

