Socket
Socket
Sign inDemoInstall

npm-packlist

Package Overview
Dependencies
4
Maintainers
7
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.2 to 3.0.0

102

index.js

@@ -100,3 +100,3 @@ 'use strict'

// except bundled dependencies
if (!this.parent) {
if (this.isProject) {
this.bundled = opt.bundled || []

@@ -107,3 +107,4 @@ this.bundledScopes = Array.from(new Set(

const rules = defaultRules.join('\n') + '\n'
this.packageJsonCache = opt.packageJsonCache || new Map()
this.packageJsonCache = this.parent ? this.parent.packageJsonCache
: (opt.packageJsonCache || new Map())
super.onReadIgnoreFile(rootBuiltinRules, rules, _ => _)

@@ -117,4 +118,8 @@ } else {

get isProject () {
return !this.parent || this.parent.follow && this.isSymbolicLink
}
onReaddir (entries) {
if (!this.parent) {
if (this.isProject) {
entries = entries.filter(e =>

@@ -132,4 +137,5 @@ e !== '.git' &&

// test or something else entirely.
if (this.parent || !entries.includes('package.json'))
if (!this.isProject || !entries.includes('package.json')) {
return super.onReaddir(entries)
}

@@ -144,4 +150,5 @@ // when the cache has been seeded with the root manifest,

// fall back to filesystem when seeded manifest is invalid
if (!pkg || typeof pkg !== 'object')
if (!pkg || typeof pkg !== 'object') {
return this.readPackageJson(entries)
}

@@ -157,6 +164,7 @@ // feels wonky, but this ensures package bin is _always_

onReadPackageJson (entries, er, pkg) {
if (er)
if (er) {
this.emit('error', er)
else
} else {
this.getPackageFiles(entries, pkg)
}
}

@@ -166,10 +174,13 @@

const files = []
if (pkg.browser)
if (pkg.browser) {
files.push('/' + pkg.browser)
if (pkg.main)
}
if (pkg.main) {
files.push('/' + pkg.main)
}
if (pkg.bin) {
// always an object because normalized already
for (const key in pkg.bin)
for (const key in pkg.bin) {
files.push('/' + pkg.bin[key])
}
}

@@ -204,4 +215,5 @@ files.push(

// no files list, just return the normal readdir() result
if (!Array.isArray(pkg.files))
if (!Array.isArray(pkg.files)) {
return super.onReaddir(entries)
}

@@ -215,9 +227,11 @@ pkg.files.push(...this.mustHaveFilesFromPackage(pkg))

// include it here.
if ((pkg.bundleDependencies || pkg.bundledDependencies) && entries.includes('node_modules'))
if ((pkg.bundleDependencies || pkg.bundledDependencies) && entries.includes('node_modules')) {
pkg.files.push('node_modules')
}
const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
const excl = pattern.match(/^!+/)
if (excl)
if (excl) {
pattern = pattern.substr(excl[0].length)
}
// strip off any / from the start of the pattern. /foo => foo

@@ -236,8 +250,10 @@ pattern = pattern.replace(/^\/+/, '')

const then = (pattern, negate, er, fileList, i) => {
if (er)
if (er) {
return this.emit('error', er)
}
results[i] = { negate, fileList }
if (--n === 0)
if (--n === 0) {
processResults(results)
}
}

@@ -281,11 +297,11 @@ const processResults = results => {

const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/
const isRoot = !this.parent
const pkg = isRoot && pkgre.test(entry) ?
const { isProject } = this
const pkg = isProject && pkgre.test(entry) ?
entry.replace(pkgre, '$1') : null
const rootNM = isRoot && entry === 'node_modules'
const rootPJ = isRoot && entry === 'package.json'
const rootNM = isProject && entry === 'node_modules'
const rootPJ = isProject && entry === 'package.json'
return (
// if we're in a bundled package, check with the parent.
/^node_modules($|\/)/i.test(p) ? this.parent.filterEntry(
/^node_modules($|\/)/i.test(p) && !this.isProject ? this.parent.filterEntry(
this.basename + '/' + entry, partial)

@@ -312,7 +328,7 @@

// npm-shrinkwrap and package.json always included in the root pkg
: isRoot && (entry === 'npm-shrinkwrap.json' || entry === 'package.json')
: isProject && (entry === 'npm-shrinkwrap.json' || entry === 'package.json')
? true
// package-lock never included
: isRoot && entry === 'package-lock.json' ? false
: isProject && entry === 'package-lock.json' ? false

@@ -325,4 +341,5 @@ // otherwise, follow ignore-walk's logic

filterEntries () {
if (this.ignoreRules['.npmignore'])
if (this.ignoreRules['.npmignore']) {
this.ignoreRules['.gitignore'] = null
}
this.filterEntries = super.filterEntries

@@ -334,8 +351,9 @@ super.filterEntries()

const ig = path.resolve(this.path, file)
if (file === 'package.json' && this.parent)
if (file === 'package.json' && !this.isProject) {
then()
else if (this.packageJsonCache.has(ig))
} else if (this.packageJsonCache.has(ig)) {
this.onPackageJson(ig, this.packageJsonCache.get(ig), then)
else
} else {
super.addIgnoreFile(file, then)
}
}

@@ -364,15 +382,18 @@

// XXX(isaacs) Next major version should make this an error instead.
stat (entry, file, dir, then) {
if (nameIsBadForWindows(entry))
stat ({ entry, file, dir }, then) {
if (nameIsBadForWindows(entry)) {
then()
else
super.stat(entry, file, dir, then)
} else {
super.stat({ entry, file, dir }, then)
}
}
// override parent onstat function to nix all symlinks
onstat (st, entry, file, dir, then) {
if (st.isSymbolicLink())
// override parent onstat function to nix all symlinks, other than
// those coming out of the followed bundled symlink deps
onstat ({ st, entry, file, dir, isSymbolicLink }, then) {
if (st.isSymbolicLink()) {
then()
else
super.onstat(st, entry, file, dir, then)
} else {
super.onstat({ st, entry, file, dir, isSymbolicLink }, then)
}
}

@@ -389,4 +410,5 @@

}
} else
} else {
super.onReadIgnoreFile(file, data, then)
}
}

@@ -409,4 +431,4 @@

walker (entry, then) {
new Walker(this.walkerOpt(entry)).on('done', then).start()
walker (entry, opt, then) {
new Walker(this.walkerOpt(entry, opt)).on('done', then).start()
}

@@ -429,4 +451,4 @@ }

walker (entry, then) {
new WalkerSync(this.walkerOpt(entry)).start()
walker (entry, opt, then) {
new WalkerSync(this.walkerOpt(entry, opt)).start()
then()

@@ -433,0 +455,0 @@ }

{
"name": "npm-packlist",
"version": "2.2.2",
"version": "3.0.0",
"description": "Get a list of the files to add from a folder into an npm package",

@@ -11,3 +11,3 @@ "directories": {

"glob": "^7.1.6",
"ignore-walk": "^3.0.3",
"ignore-walk": "^4.0.1",
"npm-bundled": "^1.1.1",

@@ -23,7 +23,3 @@ "npm-normalize-package-bin": "^1.0.1"

"devDependencies": {
"eslint": "^7.25.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"@npmcli/lint": "^1.0.2",
"mutate-fs": "^2.1.1",

@@ -34,5 +30,5 @@ "tap": "^15.0.6"

"test": "tap",
"posttest": "npm run lint",
"posttest": "npm run lint --",
"snap": "tap",
"postsnap": "npm run lintfix",
"postsnap": "npm run lintfix --",
"preversion": "npm test",

@@ -42,4 +38,5 @@ "postversion": "npm publish",

"eslint": "eslint",
"lint": "npm run eslint -- index.js bin/index.js \"test/**/*.js\"",
"lintfix": "npm run lint -- --fix"
"lint": "npm run npmclilint -- \"*.*js\" \"test/**/*.*js\"",
"lintfix": "npm run lint -- --fix",
"npmclilint": "npmcli-lint"
},

@@ -46,0 +43,0 @@ "repository": {

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