npm-packlist 3.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +24 -10
- package/{index.js → lib/index.js} +40 -62
- package/package.json +22 -20
package/bin/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
const packlist = require('../')
|
|
2
5
|
|
|
3
6
|
const dirs = []
|
|
4
7
|
let doSort = false
|
|
@@ -6,20 +9,31 @@ process.argv.slice(2).forEach(arg => {
|
|
|
6
9
|
if (arg === '-h' || arg === '--help') {
|
|
7
10
|
console.log('usage: npm-packlist [-s --sort] [directory, directory, ...]')
|
|
8
11
|
process.exit(0)
|
|
9
|
-
} else if (arg === '-s' || arg === '--sort')
|
|
12
|
+
} else if (arg === '-s' || arg === '--sort') {
|
|
10
13
|
doSort = true
|
|
11
|
-
else
|
|
14
|
+
} else {
|
|
12
15
|
dirs.push(arg)
|
|
16
|
+
}
|
|
13
17
|
})
|
|
14
18
|
|
|
15
19
|
const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list
|
|
16
20
|
|
|
17
|
-
const
|
|
18
|
-
if (!dirs.length)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const main = async () => {
|
|
22
|
+
if (!dirs.length) {
|
|
23
|
+
const results = await packlist({ path: process.cwd() })
|
|
24
|
+
console.log(sort(results).join('\n'))
|
|
25
|
+
} else {
|
|
26
|
+
for (const dir of dirs) {
|
|
27
|
+
console.group(`> ${dir}`)
|
|
28
|
+
const results = await packlist({ path: dir })
|
|
29
|
+
console.log(sort(results).join('\n'))
|
|
30
|
+
console.groupEnd()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
25
33
|
}
|
|
34
|
+
|
|
35
|
+
// coverage disabled for catch handler because we don't need to test that
|
|
36
|
+
main().catch(/* istanbul ignore next */(err) => {
|
|
37
|
+
process.exitCode = 1
|
|
38
|
+
console.error(err.stack)
|
|
39
|
+
})
|
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
const bundleWalk = require('npm-bundled')
|
|
9
9
|
const BundleWalker = bundleWalk.BundleWalker
|
|
10
|
-
const BundleWalkerSync = bundleWalk.BundleWalkerSync
|
|
11
10
|
|
|
12
11
|
const ignoreWalk = require('ignore-walk')
|
|
13
12
|
const IgnoreWalker = ignoreWalk.Walker
|
|
14
|
-
const IgnoreWalkerSync = ignoreWalk.WalkerSync
|
|
15
13
|
|
|
16
14
|
const rootBuiltinRules = Symbol('root-builtin-rules')
|
|
17
15
|
const packageNecessaryRules = Symbol('package-necessary-rules')
|
|
@@ -34,6 +32,24 @@ const packageMustHavesRE = new RegExp(`^(${packageMustHaveFileNames})(\\..*[^~$]
|
|
|
34
32
|
const fs = require('fs')
|
|
35
33
|
const glob = require('glob')
|
|
36
34
|
|
|
35
|
+
const pathHasPkg = (input) => {
|
|
36
|
+
if (!input.startsWith('node_modules/')) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const segments = input.slice('node_modules/'.length).split('/', 2)
|
|
41
|
+
return segments[0].startsWith('@')
|
|
42
|
+
? segments.length === 2
|
|
43
|
+
: true
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const pkgFromPath = (input) => {
|
|
47
|
+
const segments = input.slice('node_modules/'.length).split('/', 2)
|
|
48
|
+
return segments[0].startsWith('@')
|
|
49
|
+
? segments.join('/')
|
|
50
|
+
: segments[0]
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
const defaultRules = [
|
|
38
54
|
'.npmignore',
|
|
39
55
|
'.gitignore',
|
|
@@ -58,14 +74,14 @@ const defaultRules = [
|
|
|
58
74
|
'*.orig',
|
|
59
75
|
'/package-lock.json',
|
|
60
76
|
'/yarn.lock',
|
|
77
|
+
'/pnpm-lock.yaml',
|
|
61
78
|
'/archived-packages/**',
|
|
62
79
|
]
|
|
63
80
|
|
|
64
81
|
// There may be others, but :?|<> are handled by node-tar
|
|
65
82
|
const nameIsBadForWindows = file => /\*/.test(file)
|
|
66
83
|
|
|
67
|
-
|
|
68
|
-
const npmWalker = Class => class Walker extends Class {
|
|
84
|
+
class Walker extends IgnoreWalker {
|
|
69
85
|
constructor (opt) {
|
|
70
86
|
opt = opt || {}
|
|
71
87
|
|
|
@@ -89,7 +105,7 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
89
105
|
// hierarchy (ie, not in test/foo/node_modules/ or something).
|
|
90
106
|
const followRe = /^(?:\/node_modules\/(?:@[^/]+\/[^/]+|[^/]+)\/)*\/node_modules(?:\/@[^/]+)?$/
|
|
91
107
|
const rootPath = opt.parent ? opt.parent.root : opt.path
|
|
92
|
-
const followTestPath = opt.path.replace(/\\/g, '/').
|
|
108
|
+
const followTestPath = opt.path.replace(/\\/g, '/').slice(rootPath.length)
|
|
93
109
|
opt.follow = followRe.test(followTestPath)
|
|
94
110
|
|
|
95
111
|
super(opt)
|
|
@@ -223,7 +239,7 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
223
239
|
const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
|
|
224
240
|
const excl = pattern.match(/^!+/)
|
|
225
241
|
if (excl) {
|
|
226
|
-
pattern = pattern.
|
|
242
|
+
pattern = pattern.slice(excl[0].length)
|
|
227
243
|
}
|
|
228
244
|
// strip off any / from the start of the pattern. /foo => foo
|
|
229
245
|
pattern = pattern.replace(/^\/+/, '')
|
|
@@ -247,8 +263,8 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
247
263
|
processResults(results)
|
|
248
264
|
}
|
|
249
265
|
}
|
|
250
|
-
const processResults =
|
|
251
|
-
for (const {negate, fileList} of
|
|
266
|
+
const processResults = processed => {
|
|
267
|
+
for (const { negate, fileList } of processed) {
|
|
252
268
|
if (negate) {
|
|
253
269
|
fileList.forEach(f => {
|
|
254
270
|
f = f.replace(/\/+$/, '')
|
|
@@ -276,17 +292,17 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
276
292
|
// maintain the index so that we process them in-order only once all
|
|
277
293
|
// are completed, otherwise the parallelism messes things up, since a
|
|
278
294
|
// glob like **/*.js will always be slower than a subsequent !foo.js
|
|
279
|
-
patterns.forEach(({pattern, negate}, i) =>
|
|
295
|
+
patterns.forEach(({ pattern, negate }, i) =>
|
|
280
296
|
this.globFiles(pattern, (er, res) => then(pattern, negate, er, res, i)))
|
|
281
297
|
}
|
|
282
298
|
|
|
283
299
|
filterEntry (entry, partial) {
|
|
284
300
|
// get the partial path from the root of the walk
|
|
285
|
-
const p = this.path.
|
|
286
|
-
const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/
|
|
301
|
+
const p = this.path.slice(this.root.length + 1)
|
|
287
302
|
const { isProject } = this
|
|
288
|
-
const pkg = isProject &&
|
|
289
|
-
entry
|
|
303
|
+
const pkg = isProject && pathHasPkg(entry)
|
|
304
|
+
? pkgFromPath(entry)
|
|
305
|
+
: null
|
|
290
306
|
const rootNM = isProject && entry === 'node_modules'
|
|
291
307
|
const rootPJ = isProject && entry === 'package.json'
|
|
292
308
|
|
|
@@ -398,11 +414,19 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
398
414
|
}
|
|
399
415
|
|
|
400
416
|
sort (a, b) {
|
|
401
|
-
|
|
417
|
+
// optimize for compressibility
|
|
418
|
+
// extname, then basename, then locale alphabetically
|
|
419
|
+
// https://twitter.com/isntitvacant/status/1131094910923231232
|
|
420
|
+
const exta = path.extname(a).toLowerCase()
|
|
421
|
+
const extb = path.extname(b).toLowerCase()
|
|
422
|
+
const basea = path.basename(a).toLowerCase()
|
|
423
|
+
const baseb = path.basename(b).toLowerCase()
|
|
424
|
+
|
|
425
|
+
return exta.localeCompare(extb, 'en') ||
|
|
426
|
+
basea.localeCompare(baseb, 'en') ||
|
|
427
|
+
a.localeCompare(b, 'en')
|
|
402
428
|
}
|
|
403
|
-
}
|
|
404
429
|
|
|
405
|
-
class Walker extends npmWalker(IgnoreWalker) {
|
|
406
430
|
globFiles (pattern, cb) {
|
|
407
431
|
glob(pattern, { dot: true, cwd: this.path, nocase: true }, cb)
|
|
408
432
|
}
|
|
@@ -417,26 +441,6 @@ class Walker extends npmWalker(IgnoreWalker) {
|
|
|
417
441
|
}
|
|
418
442
|
}
|
|
419
443
|
|
|
420
|
-
class WalkerSync extends npmWalker(IgnoreWalkerSync) {
|
|
421
|
-
globFiles (pattern, cb) {
|
|
422
|
-
cb(null, glob.sync(pattern, { dot: true, cwd: this.path, nocase: true }))
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
readPackageJson (entries) {
|
|
426
|
-
const p = this.path + '/package.json'
|
|
427
|
-
try {
|
|
428
|
-
this.onReadPackageJson(entries, null, fs.readFileSync(p))
|
|
429
|
-
} catch (er) {
|
|
430
|
-
this.onReadPackageJson(entries, er)
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
walker (entry, opt, then) {
|
|
435
|
-
new WalkerSync(this.walkerOpt(entry, opt)).start()
|
|
436
|
-
then()
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
444
|
const walk = (options, callback) => {
|
|
441
445
|
options = options || {}
|
|
442
446
|
const p = new Promise((resolve, reject) => {
|
|
@@ -451,31 +455,5 @@ const walk = (options, callback) => {
|
|
|
451
455
|
return callback ? p.then(res => callback(null, res), callback) : p
|
|
452
456
|
}
|
|
453
457
|
|
|
454
|
-
const walkSync = options => {
|
|
455
|
-
options = options || {}
|
|
456
|
-
const bw = new BundleWalkerSync(options).start()
|
|
457
|
-
options.bundled = bw.result
|
|
458
|
-
options.packageJsonCache = bw.packageJsonCache
|
|
459
|
-
const walker = new WalkerSync(options)
|
|
460
|
-
walker.start()
|
|
461
|
-
return walker.result
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// optimize for compressibility
|
|
465
|
-
// extname, then basename, then locale alphabetically
|
|
466
|
-
// https://twitter.com/isntitvacant/status/1131094910923231232
|
|
467
|
-
const sort = (a, b) => {
|
|
468
|
-
const exta = path.extname(a).toLowerCase()
|
|
469
|
-
const extb = path.extname(b).toLowerCase()
|
|
470
|
-
const basea = path.basename(a).toLowerCase()
|
|
471
|
-
const baseb = path.basename(b).toLowerCase()
|
|
472
|
-
|
|
473
|
-
return exta.localeCompare(extb, 'en') ||
|
|
474
|
-
basea.localeCompare(baseb, 'en') ||
|
|
475
|
-
a.localeCompare(b, 'en')
|
|
476
|
-
}
|
|
477
|
-
|
|
478
458
|
module.exports = walk
|
|
479
|
-
walk.sync = walkSync
|
|
480
459
|
walk.Walker = Walker
|
|
481
|
-
walk.WalkerSync = WalkerSync
|
package/package.json
CHANGED
|
@@ -1,59 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-packlist",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Get a list of the files to add from a folder into an npm package",
|
|
5
5
|
"directories": {
|
|
6
6
|
"test": "test"
|
|
7
7
|
},
|
|
8
|
-
"main": "
|
|
8
|
+
"main": "lib",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"glob": "^
|
|
11
|
-
"ignore-walk": "^
|
|
12
|
-
"npm-bundled": "^1.1.
|
|
10
|
+
"glob": "^8.0.1",
|
|
11
|
+
"ignore-walk": "^5.0.1",
|
|
12
|
+
"npm-bundled": "^1.1.2",
|
|
13
13
|
"npm-normalize-package-bin": "^1.0.1"
|
|
14
14
|
},
|
|
15
|
-
"author": "
|
|
15
|
+
"author": "GitHub Inc.",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"files": [
|
|
18
|
-
"bin/
|
|
19
|
-
"
|
|
18
|
+
"bin/",
|
|
19
|
+
"lib/"
|
|
20
20
|
],
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@npmcli/
|
|
22
|
+
"@npmcli/eslint-config": "^3.0.1",
|
|
23
|
+
"@npmcli/template-oss": "3.4.1",
|
|
23
24
|
"mutate-fs": "^2.1.1",
|
|
24
|
-
"tap": "^
|
|
25
|
+
"tap": "^16.0.1"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"test": "tap",
|
|
28
|
-
"posttest": "npm run lint
|
|
29
|
+
"posttest": "npm run lint",
|
|
29
30
|
"snap": "tap",
|
|
30
31
|
"postsnap": "npm run lintfix --",
|
|
31
32
|
"preversion": "npm test",
|
|
32
33
|
"postversion": "npm publish",
|
|
33
34
|
"prepublishOnly": "git push origin --follow-tags",
|
|
34
35
|
"eslint": "eslint",
|
|
35
|
-
"lint": "
|
|
36
|
+
"lint": "eslint \"**/*.js\"",
|
|
36
37
|
"lintfix": "npm run lint -- --fix",
|
|
37
|
-
"npmclilint": "npmcli-lint"
|
|
38
|
+
"npmclilint": "npmcli-lint",
|
|
39
|
+
"postlint": "template-oss-check",
|
|
40
|
+
"template-oss-apply": "template-oss-apply --force"
|
|
38
41
|
},
|
|
39
42
|
"repository": {
|
|
40
43
|
"type": "git",
|
|
41
|
-
"url": "
|
|
44
|
+
"url": "https://github.com/npm/npm-packlist.git"
|
|
42
45
|
},
|
|
43
46
|
"tap": {
|
|
44
47
|
"test-env": [
|
|
45
48
|
"LC_ALL=sk"
|
|
46
|
-
],
|
|
47
|
-
"check-coverage": true,
|
|
48
|
-
"nyc-arg": [
|
|
49
|
-
"--include=index.js",
|
|
50
|
-
"--include=bin/index.js"
|
|
51
49
|
]
|
|
52
50
|
},
|
|
53
51
|
"bin": {
|
|
54
52
|
"npm-packlist": "bin/index.js"
|
|
55
53
|
},
|
|
56
54
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
55
|
+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
|
|
56
|
+
},
|
|
57
|
+
"templateOSS": {
|
|
58
|
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
59
|
+
"version": "3.4.1"
|
|
58
60
|
}
|
|
59
61
|
}
|