# read-package-tree

> Read the contents of node_modules.

Latest version **5.3.1** (published 2019-06-29) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install read-package-tree
pnpm add read-package-tree
yarn add read-package-tree
bun add read-package-tree
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 5.3.1 |
| Published | 2019-06-29 |
| First published | 2014-08-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/read-package-tree) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Author | Isaac Z. Schlueter |
| Maintainers | isaacs, zkat |

## Links

- npm: https://www.npmjs.com/package/read-package-tree
- Repository: https://github.com/npm/read-package-tree
- Issues: https://github.com/npm/read-package-tree/issues
- npm.io page: https://npm.io/package/read-package-tree

## Dependencies (3)

- [util-promisify](https://npm.io/package/util-promisify.md) ^2.1.0
- [read-package-json](https://npm.io/package/read-package-json.md) ^2.0.0
- [readdir-scoped-modules](https://npm.io/package/readdir-scoped-modules.md) ^1.0.0

## Recent versions

- 5.3.1 (latest) — 2019-06-29
- 5.3.0 — 2019-06-26
- 5.2.2 — 2019-02-12
- 5.2.1 — 2018-04-11
- 5.2.0 — 2018-04-10
- 5.1.6 — 2017-06-02
- 5.1.5 — 2016-06-23
- 5.1.4 — 2016-05-19
- 5.1.3 — 2016-05-17
- 5.1.2 — 2015-09-24
- 5.1.1 — 2015-09-24
- 5.1.0 — 2015-07-17
- 5.0.0 — 2015-07-01
- 4.1.0 — 2015-04-25
- 4.0.2 — 2015-04-23
- … 6 more at https://npm.io/package/read-package-tree/versions

## README

# read-package-tree

[![Build Status](https://travis-ci.org/npm/read-package-tree.svg?branch=master)](https://travis-ci.org/npm/read-package-tree)

Read the contents of node_modules.

## USAGE

```javascript
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](http://npm.im/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.

---
_Source: https://npm.io/package/read-package-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
