Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arlac77/npm-package-walker
Walks down the local npm package dependency tree and calls a visitor function for each package
https://github.com/arlac77/npm-package-walker
dependency-tree npm
Last synced: 27 days ago
JSON representation
Walks down the local npm package dependency tree and calls a visitor function for each package
- Host: GitHub
- URL: https://github.com/arlac77/npm-package-walker
- Owner: arlac77
- License: bsd-2-clause
- Created: 2017-10-13T17:59:04.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T09:26:53.000Z (7 months ago)
- Last Synced: 2024-04-14T07:00:52.450Z (7 months ago)
- Topics: dependency-tree, npm
- Language: JavaScript
- Homepage:
- Size: 2.1 MB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Maintainability](undefined)](undefined)
# 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));
```# API
### Table of Contents
* [defaultDependencyTypes](#defaultdependencytypes)
* [packageVisitor](#packagevisitor)
* [Parameters](#parameters)
* [packageWalker](#packagewalker)
* [Parameters](#parameters-1)## defaultDependencyTypes
Dependency types used by default
* dependencies
* devDependencies
* optionalDependencies
* peerDependencies## packageVisitor
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
### Parameters
* `package` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** package.json content
* `directory` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** package base dir
* `packagePath` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** how deep in the dependency tree are we (starting with 0 for the root package)Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](#packagevisitor)** async to be called for each package
* `base` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** directory where to start crawling package.json (optional, default `process.cwd()`)
* `dependencyTypes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** dig into dependency dev and/or prod (optional, default `defaultDependencyTypes`)Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** when resolving to true further dig into the dependencies
# install
With [npm](http://npmjs.org) do:
```shell
npm install npm-package-walker
```# license
BSD-2-Clause