npm-package-walker
v7.0.7
Published
Walks down the local npm package dependency tree and calls a visitor function for each package
Downloads
6,032
Readme
npm-package-walker
Walks down the local npm package dependency tree and calls a visitor function for each package.
import { packageWalker } from "npm-package-walker";
async function collectPackageNames() {
const names = new Set();
await packageWalker(
async (pkg, base, modulePath) => {
names.add(pkg.name);
return true;
},
process.cwd(),
["dependencies"]
);
return names;
}
collectPackageNames().then(names => console.log(names));
API
Table of Contents
defaultDependencyTypes
Dependency types used by default
- dependencies
- devDependencies
- optionalDependencies
- peerDependencies
packageVisitor
Type: Function
Parameters
package
Object package.json contentdirectory
string package base dirpackagePath
Array<string> how deep in the dependency tree are we (starting with 0 for the root package)
Returns Promise<boolean> true to continue traversing dependencies of this package
packageWalker
Walks the local package dependency tree and calls a visitor function. The visitor function recives the decoded package.json, its directory, and the nesting level starting with 0 for the base package. Descending the dependency tree continues until the visitor function returns false or no more dependencies are declared in a package.
Parameters
visitor
packageVisitor async to be called for each packagebase
string directory where to start crawling package.json (optional, defaultprocess.cwd()
)dependencyTypes
Array<string> dig into dependency dev and/or prod (optional, defaultdefaultDependencyTypes
)
Returns Promise<boolean> when resolving to true further dig into the dependencies
install
With npm do:
npm install npm-package-walker
license
BSD-2-Clause