{"id":15290266,"url":"https://github.com/npm/read-package-tree","last_synced_at":"2026-01-10T05:44:25.752Z","repository":{"id":19642984,"uuid":"22895305","full_name":"npm/read-package-tree","owner":"npm","description":"Read the contents of node_modules ","archived":true,"fork":false,"pushed_at":"2021-05-09T11:14:29.000Z","size":349,"stargazers_count":42,"open_issues_count":6,"forks_count":15,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-10-01T16:06:48.714Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-12T23:02:21.000Z","updated_at":"2023-08-25T22:33:03.000Z","dependencies_parsed_at":"2022-08-24T18:01:21.832Z","dependency_job_id":null,"html_url":"https://github.com/npm/read-package-tree","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/read-package-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235586073,"owners_count":19014028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-30T16:06:40.448Z","updated_at":"2025-10-07T03:32:33.650Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# read-package-tree\n\n[![Build Status](https://travis-ci.org/npm/read-package-tree.svg?branch=master)](https://travis-ci.org/npm/read-package-tree)\n\nRead the contents of node_modules.\n\n## USAGE\n\n```javascript\nvar rpt = require ('read-package-tree')\nrpt('/path/to/pkg/root', function (node, kidName) {\n  // optional filter function– if included, each package folder found is passed to\n  // it to see if it should be included in the final tree\n  // node is what we're adding children to\n  // kidName is the directory name of the module we're considering adding\n  // return true -\u003e include, false -\u003e skip\n}, function (er, data) {\n  // er means that something didn't work.\n  // data is a structure like:\n  // {\n  //   package: \u003cpackage.json data, or an empty object\u003e\n  //   package.name: defaults to `basename(path)`\n  //   children: [ \u003cmore things like this\u003e ]\n  //   parent: \u003cthing that has this in its children property, or null\u003e\n  //   path: \u003cpath loaded\u003e\n  //   realpath: \u003cthe real path on disk\u003e\n  //   isLink: \u003cset if this is a Link\u003e\n  //   target: \u003cif a Link, then this is the actual Node\u003e\n  //   error: \u003cif set, the error we got loading/parsing the package.json\u003e\n  // }\n})\n\n// or promise-style\nrpt('/path/to/pkg/root').then(data =\u003e { ... })\n```\n\nThat's it.  It doesn't figure out if dependencies are met, it doesn't\nmutate package.json data objects (beyond what\n[read-package-json](http://npm.im/read-package-json) already does), it\ndoesn't limit its search to include/exclude `devDependencies`, or\nanything else.\n\nJust follows the links in the `node_modules` hierarchy and reads the\npackage.json files it finds therein.\n\n## Symbolic Links\n\nWhen there are symlinks to packages in the `node_modules` hierarchy, a\n`Link` object will be created, with a `target` that is a `Node`\nobject.\n\nFor the most part, you can treat `Link` objects just the same as\n`Node` objects.  But if your tree-walking program needs to treat\nsymlinks differently from normal folders, then make sure to check the\nobject.\n\nIn a given `read-package-tree` run, a specific `path` will always\ncorrespond to a single object, and a specific `realpath` will always\ncorrespond to a single `Node` object.  This means that you may not be\nable to pass the resulting data object to `JSON.stringify`, because it\nmay contain cycles.\n\n## Errors\n\nErrors parsing or finding a package.json in node_modules will result in a\nnode with the error property set.  We will still find deeper node_modules\nif any exist. *Prior to `5.0.0` these aborted tree reading with an error\ncallback.*\n\nOnly a few classes of errors are fatal (result in an error callback):\n\n* If the top level location is entirely missing, that will error.\n* if `fs.realpath` returns an error for any path its trying to resolve.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fread-package-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Fread-package-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fread-package-tree/lists"}