resolve-tree
Recursively resolve node.js modules and its dependencies looking in node_modules
trees.
The module resolution algorithm behavies like require.resolve
in node.js.
It also mimics the recursive module resolution behavior used by npm
.
Features
- Recursively resolves a node_modules dependency tree
- Proper error reporting if some package cannot be resolved or is missing
- Detects repeated and circular dependencies across nested dependency trees.
- Module lookup algorithm behavies like
require.resolve
- Produces a detailed abstract dependency tree representation
- Provides convenient helpers that you will love
- Almost dependency free (only uses some stable tiny modules)
- Fast: all the I/O operations are executed asynchronously in parallel
Not supported yet
- Semantic version operator based resolution
Installation
npm install resolve-tree
Usage
const resolve = // Names of the packages to resolveconst names = 'foo' 'bar' // Custom optional params for the resolutionconst opts = basedir: process lookups: 'dependencies' 'devDependencies' resolve
The resolved dependency tree serialized to JSON looks like this:
API
Supported options
- basedir
string
- Base directory path to start lookups. Default toprocess.cwd()
. - lookups
array<string>
- Dependency types to lookup. Allowed values are:dependencies
,devDependencies
,peerDependencies
. Defaults to:dependencies
resolve.packages(names, [ opts, ] cb)
Alias: byName()
Find and resolve modules and its dependencies recursively looking by package name.
resolve.manifest(pkgManifest, [ opts, ] cb)
Resolve dependencies recursively reading the package.json
metadata.
array<pkg>
resolve.flatten(tree) => Flatten dependency tree to one level structure tree.
array<mixed>
resolve.flattenMap(tree, [ field ]) => Flatten the given dependency tree mapping by dependency value field or custom mapper function.
object
resolve.resolutions = Map of packages resolution mappings.
'mz': 'mz/fs'
resolve.packagesSync(names, [ opts ])
Alias: byNameSync
Synchronous version of packages
.
Find and resolve modules and its dependencies recursively looking by package name.
resolve.manifestSync(pkgManifest, [ opts ])
Synchronous version of manifest
.
Resolve dependencies recursively reading the package.json
metadata.
License
MIT - Tomas Aparicio