Skip to content

Walks down the local npm package dependency tree and calls a visitor function for each package

License

Notifications You must be signed in to change notification settings

arlac77/npm-package-walker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maintainability

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 content
  • directory string package base dir
  • packagePath 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 package
  • base 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

install

With npm do:

npm install npm-package-walker

license

BSD-2-Clause

About

Walks down the local npm package dependency tree and calls a visitor function for each package

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published