Gathering detailed insights and metrics for @npmcli/installed-package-contents
Gathering detailed insights and metrics for @npmcli/installed-package-contents
Gathering detailed insights and metrics for @npmcli/installed-package-contents
Gathering detailed insights and metrics for @npmcli/installed-package-contents
Get the list of files installed in a package in node_modules, including bundled dependencies
npm install @npmcli/installed-package-contents
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
11 Stars
112 Commits
11 Forks
6 Watching
4 Branches
72 Contributors
Updated on 26 Sept 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
2.3%
1,369,649
Compared to previous day
Last week
7.3%
7,360,314
Compared to previous week
Last month
11.6%
29,528,066
Compared to previous month
Last year
31.8%
315,504,673
Compared to previous year
2
3
Get the list of files installed in a package in node_modules, including bundled dependencies.
This is useful if you want to remove a package node from the tree without removing its child nodes, for example to extract a new version of the dependency into place safely.
It's sort of the reflection of npm-packlist,
but for listing out the installed files rather than the files that will
be installed. This is of course a much simpler operation, because we don't
have to handle ignore files or package.json files
lists.
1// programmatic usage 2const pkgContents = require('@npmcli/installed-package-contents') 3 4pkgContents({ path: 'node_modules/foo', depth: 1 }).then(files => { 5 // files is an array of items that need to be passed to 6 // rimraf or moved out of the way to make the folder empty 7 // if foo bundled dependencies, those will be included. 8 // It will not traverse into child directories, because we set 9 // depth:1 in the options. 10 // If the folder doesn't exist, this returns an empty array. 11}) 12 13pkgContents({ path: 'node_modules/foo', depth: Infinity }).then(files => { 14 // setting depth:Infinity tells it to keep walking forever 15 // until it hits something that isn't a directory, so we'll 16 // just get the list of all files, but not their containing 17 // directories. 18})
As a CLI:
1$ installed-package-contents node_modules/bundle-some -d1 2node_modules/.bin/some 3node_modules/bundle-some/package.json 4node_modules/bundle-some/node_modules/@scope/baz 5node_modules/bundle-some/node_modules/.bin/foo 6node_modules/bundle-some/node_modules/foo
CLI options:
Usage:
installed-package-contents <path> [-d<n> --depth=<n>]
Lists the files installed for a package specified by <path>.
Options:
-d<n> --depth=<n> Provide a numeric value ("Infinity" is allowed)
to specify how deep in the file tree to traverse.
Default=1
-h --help Show this usage information
depth
Number, default 1
. How deep to traverse through folders to get
contents. Typically you'd want to set this to either 1
(to get the
surface files and folders) or Infinity
(to get all files), but any
other positive number is supported as well. If set to 0
or a
negative number, returns the path provided and (if it is a package) its
set of linked bins.path
Required. Path to the package in node_modules
where traversal
should begin.A Promise that resolves to an array of fully-resolved files and folders
matching the criteria. This includes all bundled dependencies in
node_modules
, and any linked executables in node_modules/.bin
that the
package caused to be installed.
An empty or missing package folder will return an empty array. Empty
directories within package contents are listed, even if the depth
argument would cause them to be traversed into.
If using this module to generate a list of files that should be recursively removed to clear away the package, note that this will leave empty directories behind in certain cases:
node_modules
folder will remain.node_modules/@scope
folder will remain.node_modules/.bin
folder will remain.In the interest of speed and algorithmic complexity, this module does not
do a subsequent readdir to see if it would remove all directory entries,
though it would be easier to look at if it returned node_modules
or
.bin
in that case rather than the contents. However, if the intent is to
pass these arguments to rimraf
, it hardly makes sense to do two
readdir
calls just so that we can have the luxury of having to make a
third.
Since the primary use case is to delete a package's contents so that they can be re-filled with a new version of that package, this caveat does not pose a problem. Empty directories are already ignored by both npm and git.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
SAST tool detected but not run on all commits
Details
Reason
10 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 8
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More