Walks down the local npm package dependency tree and calls a visitor function for each package
npm install npm-package-walker
Walks down the local npm package dependency tree and calls a visitor function
for each package.
``js
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));
`
* defaultDependencyTypes
* packageVisitor
* Parameters
* packageWalker
* Parameters
Dependency types used by default
* dependencies
* devDependencies
* optionalDependencies
* peerDependencies
Type: Function
* 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
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.
* visitor packageVisitor async to be called for each packagebase
* string directory where to start crawling package.json (optional, default process.cwd())dependencyTypes
* Array<string> dig into dependency dev and/or prod (optional, default defaultDependencyTypes)
Returns Promise<boolean> when resolving to true further dig into the dependencies
With npm do:
`shell``
npm install npm-package-walker
BSD-2-Clause