Skip to content

Commit

Permalink
deps: @npmcli/installed-package-contents@2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Apr 23, 2024
1 parent af4ef2e commit 1436756
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 105 deletions.
44 changes: 44 additions & 0 deletions node_modules/@npmcli/installed-package-contents/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#! /usr/bin/env node

const { relative } = require('path')
const pkgContents = require('../')

const usage = `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`

const options = {}

process.argv.slice(2).forEach(arg => {
let match
if ((match = arg.match(/^(?:--depth=|-d)([0-9]+|Infinity)/))) {
options.depth = +match[1]
} else if (arg === '-h' || arg === '--help') {
console.log(usage)
process.exit(0)
} else {
options.path = arg
}
})

if (!options.path) {
console.error('ERROR: no path provided')
console.error(usage)
process.exit(1)
}

const cwd = process.cwd()

pkgContents(options)
.then(list => list.sort().forEach(p => console.log(relative(cwd, p))))
.catch(/* istanbul ignore next - pretty unusual */ er => {
console.error(er)
process.exit(1)
})
121 changes: 30 additions & 91 deletions node_modules/@npmcli/installed-package-contents/lib/index.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env node

// to GET CONTENTS for folder at PATH (which may be a PACKAGE):
// - if PACKAGE, read path/package.json
// - if bins in ../node_modules/.bin, add those to result
Expand All @@ -19,53 +17,46 @@
// - add GET CONTENTS of bundled deps, PACKAGE=true, depth + 1

const bundled = require('npm-bundled')
const { promisify } = require('util')
const fs = require('fs')
const readFile = promisify(fs.readFile)
const readdir = promisify(fs.readdir)
const stat = promisify(fs.stat)
const lstat = promisify(fs.lstat)
const { relative, resolve, basename, dirname } = require('path')
const { readFile, readdir, stat } = require('fs/promises')
const { resolve, basename, dirname } = require('path')
const normalizePackageBin = require('npm-normalize-package-bin')

const readPackage = ({ path, packageJsonCache }) =>
packageJsonCache.has(path) ? Promise.resolve(packageJsonCache.get(path))
const readPackage = ({ path, packageJsonCache }) => packageJsonCache.has(path)
? Promise.resolve(packageJsonCache.get(path))
: readFile(path).then(json => {
const pkg = normalizePackageBin(JSON.parse(json))
packageJsonCache.set(path, pkg)
return pkg
})
.catch(er => null)
}).catch(() => null)

// just normalize bundle deps and bin, that's all we care about here.
const normalized = Symbol('package data has been normalized')
const rpj = ({ path, packageJsonCache }) =>
readPackage({ path, packageJsonCache })
.then(pkg => {
if (!pkg || pkg[normalized]) {
return pkg
}
if (pkg.bundledDependencies && !pkg.bundleDependencies) {
pkg.bundleDependencies = pkg.bundledDependencies
delete pkg.bundledDependencies
}
const bd = pkg.bundleDependencies
if (bd === true) {
pkg.bundleDependencies = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.optionalDependencies || {}),
]
}
if (typeof bd === 'object' && !Array.isArray(bd)) {
pkg.bundleDependencies = Object.keys(bd)
}
pkg[normalized] = true
const rpj = ({ path, packageJsonCache }) => readPackage({ path, packageJsonCache })
.then(pkg => {
if (!pkg || pkg[normalized]) {
return pkg
})
}
if (pkg.bundledDependencies && !pkg.bundleDependencies) {
pkg.bundleDependencies = pkg.bundledDependencies
delete pkg.bundledDependencies
}
const bd = pkg.bundleDependencies
if (bd === true) {
pkg.bundleDependencies = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.optionalDependencies || {}),
]
}
if (typeof bd === 'object' && !Array.isArray(bd)) {
pkg.bundleDependencies = Object.keys(bd)
}
pkg[normalized] = true
return pkg
})

const pkgContents = async ({
path,
depth,
depth = 1,
currentDepth = 0,
pkg = null,
result = null,
Expand Down Expand Up @@ -105,7 +96,7 @@ const pkgContents = async ({
})

const bins = await Promise.all(
binFiles.map(b => stat(b).then(() => b).catch((er) => null))
binFiles.map(b => stat(b).then(() => b).catch(() => null))
)
bins.filter(b => b).forEach(b => result.add(b))
}
Expand Down Expand Up @@ -136,18 +127,6 @@ const pkgContents = async ({

const recursePromises = []

// if we didn't get withFileTypes support, tack that on
if (typeof dirEntries[0] === 'string') {
// use a map so we can return a promise, but we mutate dirEntries in place
// this is much slower than getting the entries from the readdir call,
// but polyfills support for node versions before 10.10
await Promise.all(dirEntries.map(async (name, index) => {
const p = resolve(path, name)
const st = await lstat(p)
dirEntries[index] = Object.assign(st, { name })
}))
}

for (const entry of dirEntries) {
const p = resolve(path, entry.name)
if (entry.isDirectory() === false) {
Expand Down Expand Up @@ -195,48 +174,8 @@ const pkgContents = async ({
return result
}

module.exports = ({ path, depth = 1, packageJsonCache }) => pkgContents({
module.exports = ({ path, ...opts }) => pkgContents({
path: resolve(path),
depth,
...opts,
pkg: true,
packageJsonCache,
}).then(results => [...results])

if (require.main === module) {
const options = { path: null, depth: 1 }
const usage = `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`

process.argv.slice(2).forEach(arg => {
let match
if ((match = arg.match(/^--depth=([0-9]+|Infinity)/)) ||
(match = arg.match(/^-d([0-9]+|Infinity)/))) {
options.depth = +match[1]
} else if (arg === '-h' || arg === '--help') {
console.log(usage)
process.exit(0)
} else {
options.path = arg
}
})
if (!options.path) {
console.error('ERROR: no path provided')
console.error(usage)
process.exit(1)
}
const cwd = process.cwd()
module.exports(options)
.then(list => list.sort().forEach(p => console.log(relative(cwd, p))))
.catch(/* istanbul ignore next - pretty unusual */ er => {
console.error(er)
process.exit(1)
})
}
12 changes: 6 additions & 6 deletions node_modules/@npmcli/installed-package-contents/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{
"name": "@npmcli/installed-package-contents",
"version": "2.0.2",
"version": "2.1.0",
"description": "Get the list of files installed in a package in node_modules, including bundled dependencies",
"author": "GitHub Inc.",
"main": "lib/index.js",
"bin": {
"installed-package-contents": "lib/index.js"
"installed-package-contents": "bin/index.js"
},
"license": "ISC",
"scripts": {
"test": "tap",
"snap": "tap",
"lint": "eslint \"**/*.js\"",
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"posttest": "npm run lint"
},
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.11.4",
"require-inject": "^1.4.4",
"@npmcli/template-oss": "4.21.4",
"tap": "^16.3.0"
},
"dependencies": {
Expand All @@ -40,7 +39,8 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.11.4"
"version": "4.21.4",
"publish": true
},
"tap": {
"nyc-arg": [
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1718,16 +1718,16 @@
}
},
"node_modules/@npmcli/installed-package-contents": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@npmcli/installed-package-contents/-/installed-package-contents-2.0.2.tgz",
"integrity": "sha512-xACzLPhnfD51GKvTOOuNX2/V4G4mz9/1I2MfDoye9kBM3RYe5g2YbscsaGoTlaWqkxeiapBWyseULVKpSVHtKQ==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@npmcli/installed-package-contents/-/installed-package-contents-2.1.0.tgz",
"integrity": "sha512-c8UuGLeZpm69BryRykLuKRyKFZYJsZSCT4aVY5ds4omyZqJ172ApzgfKJ5eV/r3HgLdUYgFVe54KSFVjKoe27w==",
"inBundle": true,
"dependencies": {
"npm-bundled": "^3.0.0",
"npm-normalize-package-bin": "^3.0.0"
},
"bin": {
"installed-package-contents": "lib/index.js"
"installed-package-contents": "bin/index.js"
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
Expand Down Expand Up @@ -16364,7 +16364,7 @@
"dependencies": {
"@isaacs/string-locale-compare": "^1.1.0",
"@npmcli/fs": "^3.1.0",
"@npmcli/installed-package-contents": "^2.0.2",
"@npmcli/installed-package-contents": "^2.1.0",
"@npmcli/map-workspaces": "^3.0.2",
"@npmcli/metavuln-calculator": "^7.1.0",
"@npmcli/name-from-folder": "^2.0.0",
Expand Down Expand Up @@ -16462,7 +16462,7 @@
"dependencies": {
"@npmcli/arborist": "^7.2.1",
"@npmcli/disparity-colors": "^3.0.0",
"@npmcli/installed-package-contents": "^2.0.2",
"@npmcli/installed-package-contents": "^2.1.0",
"binary-extensions": "^2.3.0",
"diff": "^5.1.0",
"minimatch": "^9.0.4",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/arborist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@isaacs/string-locale-compare": "^1.1.0",
"@npmcli/fs": "^3.1.0",
"@npmcli/installed-package-contents": "^2.0.2",
"@npmcli/installed-package-contents": "^2.1.0",
"@npmcli/map-workspaces": "^3.0.2",
"@npmcli/metavuln-calculator": "^7.1.0",
"@npmcli/name-from-folder": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/libnpmdiff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@npmcli/arborist": "^7.2.1",
"@npmcli/disparity-colors": "^3.0.0",
"@npmcli/installed-package-contents": "^2.0.2",
"@npmcli/installed-package-contents": "^2.1.0",
"binary-extensions": "^2.3.0",
"diff": "^5.1.0",
"minimatch": "^9.0.4",
Expand Down

0 comments on commit 1436756

Please sign in to comment.