{"id":15290155,"url":"https://github.com/npm/installed-package-contents","last_synced_at":"2025-04-07T13:09:09.916Z","repository":{"id":36469891,"uuid":"226702572","full_name":"npm/installed-package-contents","owner":"npm","description":"Get the list of files installed in a package in node_modules, including bundled dependencies","archived":false,"fork":false,"pushed_at":"2024-10-03T09:58:19.000Z","size":232,"stargazers_count":11,"open_issues_count":1,"forks_count":11,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T04:11:57.172Z","etag":null,"topics":["npm-cli"],"latest_commit_sha":null,"homepage":"","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":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-08T17:09:49.000Z","updated_at":"2024-09-26T15:16:33.000Z","dependencies_parsed_at":"2024-05-03T19:58:33.306Z","dependency_job_id":"92701418-d1d0-4be7-a67c-2ea586eae369","html_url":"https://github.com/npm/installed-package-contents","commit_stats":{"total_commits":112,"total_committers":11,"mean_commits":"10.181818181818182","dds":0.7232142857142857,"last_synced_commit":"59f2893c45ffe264117fa873abceea24246ef369"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Finstalled-package-contents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Finstalled-package-contents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Finstalled-package-contents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Finstalled-package-contents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/installed-package-contents/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"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":["npm-cli"],"created_at":"2024-09-30T16:05:47.183Z","updated_at":"2025-04-07T13:09:09.896Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @npmcli/installed-package-contents\n\nGet the list of files installed in a package in node_modules, including\nbundled dependencies.\n\nThis is useful if you want to remove a package node from the tree _without_\nremoving its child nodes, for example to extract a new version of the\ndependency into place safely.\n\nIt's sort of the reflection of [npm-packlist](http://npm.im/npm-packlist),\nbut for listing out the _installed_ files rather than the files that _will_\nbe installed.  This is of course a much simpler operation, because we don't\nhave to handle ignore files or package.json `files` lists.\n\n## USAGE\n\n```js\n// programmatic usage\nconst pkgContents = require('@npmcli/installed-package-contents')\n\npkgContents({ path: 'node_modules/foo', depth: 1 }).then(files =\u003e {\n  // files is an array of items that need to be passed to\n  // rimraf or moved out of the way to make the folder empty\n  // if foo bundled dependencies, those will be included.\n  // It will not traverse into child directories, because we set\n  // depth:1 in the options.\n  // If the folder doesn't exist, this returns an empty array.\n})\n\npkgContents({ path: 'node_modules/foo', depth: Infinity }).then(files =\u003e {\n  // setting depth:Infinity tells it to keep walking forever\n  // until it hits something that isn't a directory, so we'll\n  // just get the list of all files, but not their containing\n  // directories.\n})\n```\n\nAs a CLI:\n\n```bash\n$ installed-package-contents node_modules/bundle-some -d1\nnode_modules/.bin/some\nnode_modules/bundle-some/package.json\nnode_modules/bundle-some/node_modules/@scope/baz\nnode_modules/bundle-some/node_modules/.bin/foo\nnode_modules/bundle-some/node_modules/foo\n```\n\nCLI options:\n\n```\nUsage:\n  installed-package-contents \u003cpath\u003e [-d\u003cn\u003e --depth=\u003cn\u003e]\n\nLists the files installed for a package specified by \u003cpath\u003e.\n\nOptions:\n  -d\u003cn\u003e --depth=\u003cn\u003e   Provide a numeric value (\"Infinity\" is allowed)\n                      to specify how deep in the file tree to traverse.\n                      Default=1\n  -h --help           Show this usage information\n```\n\n## OPTIONS\n\n* `depth` Number, default `1`.  How deep to traverse through folders to get\n    contents.  Typically you'd want to set this to either `1` (to get the\n    surface files and folders) or `Infinity` (to get all files), but any\n    other positive number is supported as well.  If set to `0` or a\n    negative number, returns the path provided and (if it is a package) its\n    set of linked bins.\n* `path` Required.  Path to the package in `node_modules` where traversal\n    should begin.\n\n## RETURN VALUE\n\nA Promise that resolves to an array of fully-resolved files and folders\nmatching the criteria.  This includes all bundled dependencies in\n`node_modules`, and any linked executables in `node_modules/.bin` that the\npackage caused to be installed.\n\nAn empty or missing package folder will return an empty array.  Empty\ndirectories _within_ package contents are listed, even if the `depth`\nargument would cause them to be traversed into.\n\n## CAVEAT\n\nIf using this module to generate a list of files that should be recursively\nremoved to clear away the package, note that this will leave empty\ndirectories behind in certain cases:\n\n- If all child packages are bundled dependencies, then the\n    `node_modules` folder will remain.\n- If all child packages within a given scope were bundled dependencies,\n    then the `node_modules/@scope` folder will remain.\n- If all linked bin scripts were removed, then an empty `node_modules/.bin`\n    folder will remain.\n\nIn the interest of speed and algorithmic complexity, this module does _not_\ndo a subsequent readdir to see if it would remove all directory entries,\nthough it would be easier to look at if it returned `node_modules` or\n`.bin` in that case rather than the contents.  However, if the intent is to\npass these arguments to `rimraf`, it hardly makes sense to do _two_\n`readdir` calls just so that we can have the luxury of having to make a\nthird.\n\nSince the primary use case is to delete a package's contents so that they\ncan be re-filled with a new version of that package, this caveat does not\npose a problem.  Empty directories are already ignored by both npm and git.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Finstalled-package-contents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Finstalled-package-contents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Finstalled-package-contents/lists"}