npm-packlist
Advanced tools
Comparing version 4.0.0 to 5.0.0
#!/usr/bin/env node | ||
'use strict' | ||
const packlist = require('../') | ||
const dirs = [] | ||
@@ -18,10 +21,20 @@ let doSort = false | ||
const packlist = require('../') | ||
if (!dirs.length) { | ||
console.log(sort(packlist.sync({ path: process.cwd() })).join('\n')) | ||
} else { | ||
dirs.forEach(path => { | ||
console.log(`> ${path}`) | ||
console.log(sort(packlist.sync({ path })).join('\n')) | ||
}) | ||
const main = async () => { | ||
if (!dirs.length) { | ||
const results = await packlist({ path: process.cwd() }) | ||
console.log(sort(results).join('\n')) | ||
} else { | ||
for (const dir of dirs) { | ||
console.group(`> ${dir}`) | ||
const results = await packlist({ path: dir }) | ||
console.log(sort(results).join('\n')) | ||
console.groupEnd() | ||
} | ||
} | ||
} | ||
// coverage disabled for catch handler because we don't need to test that | ||
main().catch(/* istanbul ignore next */(err) => { | ||
process.exitCode = 1 | ||
console.error(err.stack) | ||
}) |
@@ -10,7 +10,5 @@ 'use strict' | ||
const BundleWalker = bundleWalk.BundleWalker | ||
const BundleWalkerSync = bundleWalk.BundleWalkerSync | ||
const ignoreWalk = require('ignore-walk') | ||
const IgnoreWalker = ignoreWalk.Walker | ||
const IgnoreWalkerSync = ignoreWalk.WalkerSync | ||
@@ -38,2 +36,20 @@ const rootBuiltinRules = Symbol('root-builtin-rules') | ||
const pathHasPkg = (input) => { | ||
if (!input.startsWith('node_modules/')) { | ||
return false | ||
} | ||
const segments = input.slice('node_modules/'.length).split('/', 2) | ||
return segments[0].startsWith('@') | ||
? segments.length === 2 | ||
: true | ||
} | ||
const pkgFromPath = (input) => { | ||
const segments = input.slice('node_modules/'.length).split('/', 2) | ||
return segments[0].startsWith('@') | ||
? segments.join('/') | ||
: segments[0] | ||
} | ||
const defaultRules = [ | ||
@@ -70,4 +86,3 @@ '.npmignore', | ||
// a decorator that applies our custom rules to an ignore walker | ||
const npmWalker = Class => class Walker extends Class { | ||
class Walker extends IgnoreWalker { | ||
constructor (opt) { | ||
@@ -96,3 +111,3 @@ opt = opt || {} | ||
const rootPath = opt.parent ? opt.parent.root : opt.path | ||
const followTestPath = opt.path.replace(/\\/g, '/').substr(rootPath.length) | ||
const followTestPath = opt.path.replace(/\\/g, '/').slice(rootPath.length) | ||
opt.follow = followRe.test(followTestPath) | ||
@@ -231,3 +246,3 @@ | ||
if (excl) { | ||
pattern = pattern.substr(excl[0].length) | ||
pattern = pattern.slice(excl[0].length) | ||
} | ||
@@ -256,4 +271,4 @@ // strip off any / from the start of the pattern. /foo => foo | ||
} | ||
const processResults = results => { | ||
for (const { negate, fileList } of results) { | ||
const processResults = processed => { | ||
for (const { negate, fileList } of processed) { | ||
if (negate) { | ||
@@ -292,7 +307,7 @@ fileList.forEach(f => { | ||
// get the partial path from the root of the walk | ||
const p = this.path.substr(this.root.length + 1) | ||
const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/ | ||
const p = this.path.slice(this.root.length + 1) | ||
const { isProject } = this | ||
const pkg = isProject && pkgre.test(entry) ? | ||
entry.replace(pkgre, '$1') : null | ||
const pkg = isProject && pathHasPkg(entry) | ||
? pkgFromPath(entry) | ||
: null | ||
const rootNM = isProject && entry === 'node_modules' | ||
@@ -409,7 +424,15 @@ const rootPJ = isProject && entry === 'package.json' | ||
sort (a, b) { | ||
return sort(a, b) | ||
// optimize for compressibility | ||
// extname, then basename, then locale alphabetically | ||
// https://twitter.com/isntitvacant/status/1131094910923231232 | ||
const exta = path.extname(a).toLowerCase() | ||
const extb = path.extname(b).toLowerCase() | ||
const basea = path.basename(a).toLowerCase() | ||
const baseb = path.basename(b).toLowerCase() | ||
return exta.localeCompare(extb, 'en') || | ||
basea.localeCompare(baseb, 'en') || | ||
a.localeCompare(b, 'en') | ||
} | ||
} | ||
class Walker extends npmWalker(IgnoreWalker) { | ||
globFiles (pattern, cb) { | ||
@@ -429,22 +452,2 @@ glob(pattern, { dot: true, cwd: this.path, nocase: true }, cb) | ||
class WalkerSync extends npmWalker(IgnoreWalkerSync) { | ||
globFiles (pattern, cb) { | ||
cb(null, glob.sync(pattern, { dot: true, cwd: this.path, nocase: true })) | ||
} | ||
readPackageJson (entries) { | ||
const p = this.path + '/package.json' | ||
try { | ||
this.onReadPackageJson(entries, null, fs.readFileSync(p)) | ||
} catch (er) { | ||
this.onReadPackageJson(entries, er) | ||
} | ||
} | ||
walker (entry, opt, then) { | ||
new WalkerSync(this.walkerOpt(entry, opt)).start() | ||
then() | ||
} | ||
} | ||
const walk = (options, callback) => { | ||
@@ -464,29 +467,3 @@ options = options || {} | ||
const walkSync = options => { | ||
options = options || {} | ||
const bw = new BundleWalkerSync(options).start() | ||
options.bundled = bw.result | ||
options.packageJsonCache = bw.packageJsonCache | ||
const walker = new WalkerSync(options) | ||
walker.start() | ||
return walker.result | ||
} | ||
// optimize for compressibility | ||
// extname, then basename, then locale alphabetically | ||
// https://twitter.com/isntitvacant/status/1131094910923231232 | ||
const sort = (a, b) => { | ||
const exta = path.extname(a).toLowerCase() | ||
const extb = path.extname(b).toLowerCase() | ||
const basea = path.basename(a).toLowerCase() | ||
const baseb = path.basename(b).toLowerCase() | ||
return exta.localeCompare(extb, 'en') || | ||
basea.localeCompare(baseb, 'en') || | ||
a.localeCompare(b, 'en') | ||
} | ||
module.exports = walk | ||
walk.sync = walkSync | ||
walk.Walker = Walker | ||
walk.WalkerSync = WalkerSync |
{ | ||
"name": "npm-packlist", | ||
"version": "4.0.0", | ||
"version": "5.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.2.0", | ||
"ignore-walk": "^4.0.1", | ||
"ignore-walk": "^5.0.1", | ||
"npm-bundled": "^1.1.2", | ||
@@ -19,9 +19,10 @@ "npm-normalize-package-bin": "^1.0.1" | ||
"files": [ | ||
"bin", | ||
"lib" | ||
"bin/", | ||
"lib/" | ||
], | ||
"devDependencies": { | ||
"@npmcli/template-oss": "^2.9.2", | ||
"@npmcli/eslint-config": "^3.0.1", | ||
"@npmcli/template-oss": "3.2.2", | ||
"mutate-fs": "^2.1.1", | ||
"tap": "^15.1.6" | ||
"tap": "^16.0.1" | ||
}, | ||
@@ -37,11 +38,11 @@ "scripts": { | ||
"eslint": "eslint", | ||
"lint": "eslint '**/*.js'", | ||
"lint": "eslint \"**/*.js\"", | ||
"lintfix": "npm run lint -- --fix", | ||
"npmclilint": "npmcli-lint", | ||
"postlint": "npm-template-check", | ||
"template-copy": "npm-template-copy --force" | ||
"postlint": "template-oss-check", | ||
"template-oss-apply": "template-oss-apply --force" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/npm/npm-packlist.git" | ||
"url": "https://github.com/npm/npm-packlist.git" | ||
}, | ||
@@ -51,7 +52,2 @@ "tap": { | ||
"LC_ALL=sk" | ||
], | ||
"check-coverage": true, | ||
"nyc-arg": [ | ||
"--include=index.js", | ||
"--include=bin/index.js" | ||
] | ||
@@ -63,7 +59,8 @@ }, | ||
"engines": { | ||
"node": "^12.13.0 || ^14.15.0 || >=16" | ||
"node": "^12.13.0 || ^14.15.0 || >=16.0.0" | ||
}, | ||
"templateOSS": { | ||
"version": "2.9.2" | ||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", | ||
"version": "3.2.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
24056
4
431
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedignore-walk@5.0.1(transitive)
+ Addedminimatch@5.1.6(transitive)
- Removedignore-walk@4.0.1(transitive)
Updatedignore-walk@^5.0.1