5.3.1 • Published 5 years ago

read-package-tree v5.3.1

Weekly downloads
2,496,873
License
ISC
Repository
github
Last release
5 years ago

read-package-tree

Build Status

Read the contents of node_modules.

USAGE

var rpt = require ('read-package-tree')
rpt('/path/to/pkg/root', function (node, kidName) {
  // optional filter function– if included, each package folder found is passed to
  // it to see if it should be included in the final tree
  // node is what we're adding children to
  // kidName is the directory name of the module we're considering adding
  // return true -> include, false -> skip
}, function (er, data) {
  // er means that something didn't work.
  // data is a structure like:
  // {
  //   package: <package.json data, or an empty object>
  //   package.name: defaults to `basename(path)`
  //   children: [ <more things like this> ]
  //   parent: <thing that has this in its children property, or null>
  //   path: <path loaded>
  //   realpath: <the real path on disk>
  //   isLink: <set if this is a Link>
  //   target: <if a Link, then this is the actual Node>
  //   error: <if set, the error we got loading/parsing the package.json>
  // }
})

// or promise-style
rpt('/path/to/pkg/root').then(data => { ... })

That's it. It doesn't figure out if dependencies are met, it doesn't mutate package.json data objects (beyond what read-package-json already does), it doesn't limit its search to include/exclude devDependencies, or anything else.

Just follows the links in the node_modules hierarchy and reads the package.json files it finds therein.

Symbolic Links

When there are symlinks to packages in the node_modules hierarchy, a Link object will be created, with a target that is a Node object.

For the most part, you can treat Link objects just the same as Node objects. But if your tree-walking program needs to treat symlinks differently from normal folders, then make sure to check the object.

In a given read-package-tree run, a specific path will always correspond to a single object, and a specific realpath will always correspond to a single Node object. This means that you may not be able to pass the resulting data object to JSON.stringify, because it may contain cycles.

Errors

Errors parsing or finding a package.json in node_modules will result in a node with the error property set. We will still find deeper node_modules if any exist. Prior to 5.0.0 these aborted tree reading with an error callback.

Only a few classes of errors are fatal (result in an error callback):

  • If the top level location is entirely missing, that will error.
  • if fs.realpath returns an error for any path its trying to resolve.
@megasaur/bootstrapkilli8n-react-native-fast-image@cashremit/cr-streamline-iconsdemo-hyext@frxf/frxfpulumi-testcogoportutils@infinitebrahmanuniverse/nolb-read-@everything-registry/sub-chunk-2628test-miniprogramwinx-form-winxwedmasterwuchuansabersshaocongwangsame-authorthanksminiprogram-ciminiprogram-mp-cilibrary-analyzerlicense-lslicensezerojamuskalimjmpr-jpmhyexthyext-oldinno-dependency-resolverhubot-budagulp-mp-npmjameslinenode.js1l2forlernagit-nmnaver-npmluojia-cli-devnode4-module-pathsnodupdepsnst-cliorbital-loaderorbital.jspown-modulesnpm-verifiedoiunpm5npm5vnpm_cache_sharenpmcng-search-dropdownpicogwpath-pkgqxf2006hf0216react-picky-with-clearnpm-idempotent-rebuildnpm-msys2npm-prognpm-sustainabilitynoticemenot-bundled-npmnpm-authors-contributorsnpm-dependency-analyzernull-session-npmqqcibuildpzmtestsindre-module-pathsserver-liuxinrutinker@asserted/shrinkwrap@beisen/npm@buganto/client@0xcda7a/npm@0x-lerna-fork/bootstrap421752593proyarn-upgrade-on-ciyss-perseuswebpack-external-pluginvinpmuniversal-module-treetsdm@farris/jit-engine@finclip/blender-compile@finclip/blender-compile-m@houdiniproject/noticeme@hyext/cli@hyext/ext-sdk-cli@functionless/nodejs-closure-serializer@kuinox/testpackagethatnooneshoulduse@kuinox/testpackagethatnooneshoulduseever@lewisl9029/pulumi-native-es-modules@mrauhu/npm@erquhart/lerna-bootstrap@microsoft/rush-lib@merna/bootstrap@jasonssun/npm@kne/compile-system@jump-mp/blender-compile@react-18-pdf/root@pulumi/vsphere@pulumi/digitalocean@pulumi/gitlab@safely-project/safely-ts@salomvary/npm
5.3.1

5 years ago

5.3.0

5 years ago

5.2.2

6 years ago

5.2.1

7 years ago

5.2.0

7 years ago

5.1.6

8 years ago

5.1.5

9 years ago

5.1.4

9 years ago

5.1.3

9 years ago

5.1.2

9 years ago

5.1.1

9 years ago

5.1.0

9 years ago

5.0.0

9 years ago

4.1.0

10 years ago

4.0.2

10 years ago

4.0.1

10 years ago

4.0.0

10 years ago

3.0.0

10 years ago

2.2.0

10 years ago

2.0.0

10 years ago

1.0.0

10 years ago