Skip to content

Commit 486d46c

Browse files
lukekarryswraithgar
authored andcommitted
deps: @npmcli/installed-package-contents@2.1.0
1 parent 157d0ae commit 486d46c

6 files changed

Lines changed: 88 additions & 105 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#! /usr/bin/env node
2+
3+
const { relative } = require('path')
4+
const pkgContents = require('../')
5+
6+
const usage = `Usage:
7+
installed-package-contents <path> [-d<n> --depth=<n>]
8+
9+
Lists the files installed for a package specified by <path>.
10+
11+
Options:
12+
-d<n> --depth=<n> Provide a numeric value ("Infinity" is allowed)
13+
to specify how deep in the file tree to traverse.
14+
Default=1
15+
-h --help Show this usage information`
16+
17+
const options = {}
18+
19+
process.argv.slice(2).forEach(arg => {
20+
let match
21+
if ((match = arg.match(/^(?:--depth=|-d)([0-9]+|Infinity)/))) {
22+
options.depth = +match[1]
23+
} else if (arg === '-h' || arg === '--help') {
24+
console.log(usage)
25+
process.exit(0)
26+
} else {
27+
options.path = arg
28+
}
29+
})
30+
31+
if (!options.path) {
32+
console.error('ERROR: no path provided')
33+
console.error(usage)
34+
process.exit(1)
35+
}
36+
37+
const cwd = process.cwd()
38+
39+
pkgContents(options)
40+
.then(list => list.sort().forEach(p => console.log(relative(cwd, p))))
41+
.catch(/* istanbul ignore next - pretty unusual */ er => {
42+
console.error(er)
43+
process.exit(1)
44+
})

node_modules/@npmcli/installed-package-contents/lib/index.js

100755100644
Lines changed: 30 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#! /usr/bin/env node
2-
31
// to GET CONTENTS for folder at PATH (which may be a PACKAGE):
42
// - if PACKAGE, read path/package.json
53
// - if bins in ../node_modules/.bin, add those to result
@@ -19,53 +17,46 @@
1917
// - add GET CONTENTS of bundled deps, PACKAGE=true, depth + 1
2018

2119
const bundled = require('npm-bundled')
22-
const { promisify } = require('util')
23-
const fs = require('fs')
24-
const readFile = promisify(fs.readFile)
25-
const readdir = promisify(fs.readdir)
26-
const stat = promisify(fs.stat)
27-
const lstat = promisify(fs.lstat)
28-
const { relative, resolve, basename, dirname } = require('path')
20+
const { readFile, readdir, stat } = require('fs/promises')
21+
const { resolve, basename, dirname } = require('path')
2922
const normalizePackageBin = require('npm-normalize-package-bin')
3023

31-
const readPackage = ({ path, packageJsonCache }) =>
32-
packageJsonCache.has(path) ? Promise.resolve(packageJsonCache.get(path))
24+
const readPackage = ({ path, packageJsonCache }) => packageJsonCache.has(path)
25+
? Promise.resolve(packageJsonCache.get(path))
3326
: readFile(path).then(json => {
3427
const pkg = normalizePackageBin(JSON.parse(json))
3528
packageJsonCache.set(path, pkg)
3629
return pkg
37-
})
38-
.catch(er => null)
30+
}).catch(() => null)
3931

4032
// just normalize bundle deps and bin, that's all we care about here.
4133
const normalized = Symbol('package data has been normalized')
42-
const rpj = ({ path, packageJsonCache }) =>
43-
readPackage({ path, packageJsonCache })
44-
.then(pkg => {
45-
if (!pkg || pkg[normalized]) {
46-
return pkg
47-
}
48-
if (pkg.bundledDependencies && !pkg.bundleDependencies) {
49-
pkg.bundleDependencies = pkg.bundledDependencies
50-
delete pkg.bundledDependencies
51-
}
52-
const bd = pkg.bundleDependencies
53-
if (bd === true) {
54-
pkg.bundleDependencies = [
55-
...Object.keys(pkg.dependencies || {}),
56-
...Object.keys(pkg.optionalDependencies || {}),
57-
]
58-
}
59-
if (typeof bd === 'object' && !Array.isArray(bd)) {
60-
pkg.bundleDependencies = Object.keys(bd)
61-
}
62-
pkg[normalized] = true
34+
const rpj = ({ path, packageJsonCache }) => readPackage({ path, packageJsonCache })
35+
.then(pkg => {
36+
if (!pkg || pkg[normalized]) {
6337
return pkg
64-
})
38+
}
39+
if (pkg.bundledDependencies && !pkg.bundleDependencies) {
40+
pkg.bundleDependencies = pkg.bundledDependencies
41+
delete pkg.bundledDependencies
42+
}
43+
const bd = pkg.bundleDependencies
44+
if (bd === true) {
45+
pkg.bundleDependencies = [
46+
...Object.keys(pkg.dependencies || {}),
47+
...Object.keys(pkg.optionalDependencies || {}),
48+
]
49+
}
50+
if (typeof bd === 'object' && !Array.isArray(bd)) {
51+
pkg.bundleDependencies = Object.keys(bd)
52+
}
53+
pkg[normalized] = true
54+
return pkg
55+
})
6556

6657
const pkgContents = async ({
6758
path,
68-
depth,
59+
depth = 1,
6960
currentDepth = 0,
7061
pkg = null,
7162
result = null,
@@ -105,7 +96,7 @@ const pkgContents = async ({
10596
})
10697

10798
const bins = await Promise.all(
108-
binFiles.map(b => stat(b).then(() => b).catch((er) => null))
99+
binFiles.map(b => stat(b).then(() => b).catch(() => null))
109100
)
110101
bins.filter(b => b).forEach(b => result.add(b))
111102
}
@@ -136,18 +127,6 @@ const pkgContents = async ({
136127

137128
const recursePromises = []
138129

139-
// if we didn't get withFileTypes support, tack that on
140-
if (typeof dirEntries[0] === 'string') {
141-
// use a map so we can return a promise, but we mutate dirEntries in place
142-
// this is much slower than getting the entries from the readdir call,
143-
// but polyfills support for node versions before 10.10
144-
await Promise.all(dirEntries.map(async (name, index) => {
145-
const p = resolve(path, name)
146-
const st = await lstat(p)
147-
dirEntries[index] = Object.assign(st, { name })
148-
}))
149-
}
150-
151130
for (const entry of dirEntries) {
152131
const p = resolve(path, entry.name)
153132
if (entry.isDirectory() === false) {
@@ -195,48 +174,8 @@ const pkgContents = async ({
195174
return result
196175
}
197176

198-
module.exports = ({ path, depth = 1, packageJsonCache }) => pkgContents({
177+
module.exports = ({ path, ...opts }) => pkgContents({
199178
path: resolve(path),
200-
depth,
179+
...opts,
201180
pkg: true,
202-
packageJsonCache,
203181
}).then(results => [...results])
204-
205-
if (require.main === module) {
206-
const options = { path: null, depth: 1 }
207-
const usage = `Usage:
208-
installed-package-contents <path> [-d<n> --depth=<n>]
209-
210-
Lists the files installed for a package specified by <path>.
211-
212-
Options:
213-
-d<n> --depth=<n> Provide a numeric value ("Infinity" is allowed)
214-
to specify how deep in the file tree to traverse.
215-
Default=1
216-
-h --help Show this usage information`
217-
218-
process.argv.slice(2).forEach(arg => {
219-
let match
220-
if ((match = arg.match(/^--depth=([0-9]+|Infinity)/)) ||
221-
(match = arg.match(/^-d([0-9]+|Infinity)/))) {
222-
options.depth = +match[1]
223-
} else if (arg === '-h' || arg === '--help') {
224-
console.log(usage)
225-
process.exit(0)
226-
} else {
227-
options.path = arg
228-
}
229-
})
230-
if (!options.path) {
231-
console.error('ERROR: no path provided')
232-
console.error(usage)
233-
process.exit(1)
234-
}
235-
const cwd = process.cwd()
236-
module.exports(options)
237-
.then(list => list.sort().forEach(p => console.log(relative(cwd, p))))
238-
.catch(/* istanbul ignore next - pretty unusual */ er => {
239-
console.error(er)
240-
process.exit(1)
241-
})
242-
}

node_modules/@npmcli/installed-package-contents/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
{
22
"name": "@npmcli/installed-package-contents",
3-
"version": "2.0.2",
3+
"version": "2.1.0",
44
"description": "Get the list of files installed in a package in node_modules, including bundled dependencies",
55
"author": "GitHub Inc.",
66
"main": "lib/index.js",
77
"bin": {
8-
"installed-package-contents": "lib/index.js"
8+
"installed-package-contents": "bin/index.js"
99
},
1010
"license": "ISC",
1111
"scripts": {
1212
"test": "tap",
1313
"snap": "tap",
14-
"lint": "eslint \"**/*.js\"",
14+
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
1515
"postlint": "template-oss-check",
1616
"template-oss-apply": "template-oss-apply --force",
1717
"lintfix": "npm run lint -- --fix",
1818
"posttest": "npm run lint"
1919
},
2020
"devDependencies": {
2121
"@npmcli/eslint-config": "^4.0.0",
22-
"@npmcli/template-oss": "4.11.4",
23-
"require-inject": "^1.4.4",
22+
"@npmcli/template-oss": "4.21.4",
2423
"tap": "^16.3.0"
2524
},
2625
"dependencies": {
@@ -40,7 +39,8 @@
4039
},
4140
"templateOSS": {
4241
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
43-
"version": "4.11.4"
42+
"version": "4.21.4",
43+
"publish": true
4444
},
4545
"tap": {
4646
"nyc-arg": [

package-lock.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,16 +1693,16 @@
16931693
}
16941694
},
16951695
"node_modules/@npmcli/installed-package-contents": {
1696-
"version": "2.0.2",
1697-
"resolved": "https://registry.npmjs.org/@npmcli/installed-package-contents/-/installed-package-contents-2.0.2.tgz",
1698-
"integrity": "sha512-xACzLPhnfD51GKvTOOuNX2/V4G4mz9/1I2MfDoye9kBM3RYe5g2YbscsaGoTlaWqkxeiapBWyseULVKpSVHtKQ==",
1696+
"version": "2.1.0",
1697+
"resolved": "https://registry.npmjs.org/@npmcli/installed-package-contents/-/installed-package-contents-2.1.0.tgz",
1698+
"integrity": "sha512-c8UuGLeZpm69BryRykLuKRyKFZYJsZSCT4aVY5ds4omyZqJ172ApzgfKJ5eV/r3HgLdUYgFVe54KSFVjKoe27w==",
16991699
"inBundle": true,
17001700
"dependencies": {
17011701
"npm-bundled": "^3.0.0",
17021702
"npm-normalize-package-bin": "^3.0.0"
17031703
},
17041704
"bin": {
1705-
"installed-package-contents": "lib/index.js"
1705+
"installed-package-contents": "bin/index.js"
17061706
},
17071707
"engines": {
17081708
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
@@ -16355,7 +16355,7 @@
1635516355
"dependencies": {
1635616356
"@isaacs/string-locale-compare": "^1.1.0",
1635716357
"@npmcli/fs": "^3.1.0",
16358-
"@npmcli/installed-package-contents": "^2.0.2",
16358+
"@npmcli/installed-package-contents": "^2.1.0",
1635916359
"@npmcli/map-workspaces": "^3.0.2",
1636016360
"@npmcli/metavuln-calculator": "^7.1.0",
1636116361
"@npmcli/name-from-folder": "^2.0.0",
@@ -16452,7 +16452,7 @@
1645216452
"license": "ISC",
1645316453
"dependencies": {
1645416454
"@npmcli/arborist": "^7.2.1",
16455-
"@npmcli/installed-package-contents": "^2.0.2",
16455+
"@npmcli/installed-package-contents": "^2.1.0",
1645616456
"binary-extensions": "^2.3.0",
1645716457
"diff": "^5.1.0",
1645816458
"minimatch": "^9.0.4",

workspaces/arborist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"@isaacs/string-locale-compare": "^1.1.0",
77
"@npmcli/fs": "^3.1.0",
8-
"@npmcli/installed-package-contents": "^2.0.2",
8+
"@npmcli/installed-package-contents": "^2.1.0",
99
"@npmcli/map-workspaces": "^3.0.2",
1010
"@npmcli/metavuln-calculator": "^7.1.0",
1111
"@npmcli/name-from-folder": "^2.0.0",

workspaces/libnpmdiff/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"dependencies": {
4949
"@npmcli/arborist": "^7.2.1",
50-
"@npmcli/installed-package-contents": "^2.0.2",
50+
"@npmcli/installed-package-contents": "^2.1.0",
5151
"binary-extensions": "^2.3.0",
5252
"diff": "^5.1.0",
5353
"minimatch": "^9.0.4",

0 commit comments

Comments
 (0)