Socket
Socket
Sign inDemoInstall

@npmcli/installed-package-contents

Package Overview
Dependencies
2
Maintainers
5
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.1.0

bin/index.js

121

lib/index.js

@@ -1,3 +0,1 @@

#! /usr/bin/env node
// to GET CONTENTS for folder at PATH (which may be a PACKAGE):

@@ -22,13 +20,8 @@ // - if PACKAGE, read path/package.json

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 => {

@@ -38,34 +31,32 @@ const pkg = normalizePackageBin(JSON.parse(json))

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,

@@ -110,3 +101,3 @@ pkg = null,

const bins = await Promise.all(
binFiles.map(b => stat(b).then(() => b).catch((er) => null))
binFiles.map(b => stat(b).then(() => b).catch(() => null))
)

@@ -142,14 +133,2 @@ bins.filter(b => b).forEach(b => result.add(b))

// 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) {

@@ -202,46 +181,6 @@ const p = resolve(path, entry.name)

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)
})
}
{
"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",

@@ -8,3 +8,3 @@ "author": "GitHub Inc.",

"bin": {
"installed-package-contents": "lib/index.js"
"installed-package-contents": "bin/index.js"
},

@@ -15,3 +15,3 @@ "license": "ISC",

"snap": "tap",
"lint": "eslint \"**/*.js\"",
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"postlint": "template-oss-check",

@@ -24,4 +24,3 @@ "template-oss-apply": "template-oss-apply --force",

"@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"

@@ -46,3 +45,4 @@ },

"//@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
},

@@ -49,0 +49,0 @@ "tap": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc