npm-packlist 4.0.0 → 5.0.2
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 +21 -8
- package/lib/index.js +40 -62
- package/package.json +15 -18
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
|
|
@@ -15,12 +18,22 @@ process.argv.slice(2).forEach(arg => {
|
|
|
15
18
|
|
|
16
19
|
const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list
|
|
17
20
|
|
|
18
|
-
const
|
|
19
|
-
if (!dirs.length) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
}
|
|
26
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
|
+
})
|
package/lib/index.js
CHANGED
|
@@ -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')
|
|
@@ -33,6 +31,25 @@ const packageMustHavesRE = new RegExp(`^(${packageMustHaveFileNames})(\\..*[^~$]
|
|
|
33
31
|
|
|
34
32
|
const fs = require('fs')
|
|
35
33
|
const glob = require('glob')
|
|
34
|
+
const globify = pattern => pattern.split('\\').join('/')
|
|
35
|
+
|
|
36
|
+
const pathHasPkg = (input) => {
|
|
37
|
+
if (!input.startsWith('node_modules/')) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const segments = input.slice('node_modules/'.length).split('/', 2)
|
|
42
|
+
return segments[0].startsWith('@')
|
|
43
|
+
? segments.length === 2
|
|
44
|
+
: true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const pkgFromPath = (input) => {
|
|
48
|
+
const segments = input.slice('node_modules/'.length).split('/', 2)
|
|
49
|
+
return segments[0].startsWith('@')
|
|
50
|
+
? segments.join('/')
|
|
51
|
+
: segments[0]
|
|
52
|
+
}
|
|
36
53
|
|
|
37
54
|
const defaultRules = [
|
|
38
55
|
'.npmignore',
|
|
@@ -65,8 +82,7 @@ const defaultRules = [
|
|
|
65
82
|
// There may be others, but :?|<> are handled by node-tar
|
|
66
83
|
const nameIsBadForWindows = file => /\*/.test(file)
|
|
67
84
|
|
|
68
|
-
|
|
69
|
-
const npmWalker = Class => class Walker extends Class {
|
|
85
|
+
class Walker extends IgnoreWalker {
|
|
70
86
|
constructor (opt) {
|
|
71
87
|
opt = opt || {}
|
|
72
88
|
|
|
@@ -90,7 +106,7 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
90
106
|
// hierarchy (ie, not in test/foo/node_modules/ or something).
|
|
91
107
|
const followRe = /^(?:\/node_modules\/(?:@[^/]+\/[^/]+|[^/]+)\/)*\/node_modules(?:\/@[^/]+)?$/
|
|
92
108
|
const rootPath = opt.parent ? opt.parent.root : opt.path
|
|
93
|
-
const followTestPath = opt.path.replace(/\\/g, '/').
|
|
109
|
+
const followTestPath = opt.path.replace(/\\/g, '/').slice(rootPath.length)
|
|
94
110
|
opt.follow = followRe.test(followTestPath)
|
|
95
111
|
|
|
96
112
|
super(opt)
|
|
@@ -224,7 +240,7 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
224
240
|
const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
|
|
225
241
|
const excl = pattern.match(/^!+/)
|
|
226
242
|
if (excl) {
|
|
227
|
-
pattern = pattern.
|
|
243
|
+
pattern = pattern.slice(excl[0].length)
|
|
228
244
|
}
|
|
229
245
|
// strip off any / from the start of the pattern. /foo => foo
|
|
230
246
|
pattern = pattern.replace(/^\/+/, '')
|
|
@@ -248,8 +264,8 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
248
264
|
processResults(results)
|
|
249
265
|
}
|
|
250
266
|
}
|
|
251
|
-
const processResults =
|
|
252
|
-
for (const { negate, fileList } of
|
|
267
|
+
const processResults = processed => {
|
|
268
|
+
for (const { negate, fileList } of processed) {
|
|
253
269
|
if (negate) {
|
|
254
270
|
fileList.forEach(f => {
|
|
255
271
|
f = f.replace(/\/+$/, '')
|
|
@@ -283,11 +299,11 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
283
299
|
|
|
284
300
|
filterEntry (entry, partial) {
|
|
285
301
|
// get the partial path from the root of the walk
|
|
286
|
-
const p = this.path.
|
|
287
|
-
const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/
|
|
302
|
+
const p = this.path.slice(this.root.length + 1)
|
|
288
303
|
const { isProject } = this
|
|
289
|
-
const pkg = isProject &&
|
|
290
|
-
entry
|
|
304
|
+
const pkg = isProject && pathHasPkg(entry)
|
|
305
|
+
? pkgFromPath(entry)
|
|
306
|
+
: null
|
|
291
307
|
const rootNM = isProject && entry === 'node_modules'
|
|
292
308
|
const rootPJ = isProject && entry === 'package.json'
|
|
293
309
|
|
|
@@ -399,13 +415,21 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
399
415
|
}
|
|
400
416
|
|
|
401
417
|
sort (a, b) {
|
|
402
|
-
|
|
418
|
+
// optimize for compressibility
|
|
419
|
+
// extname, then basename, then locale alphabetically
|
|
420
|
+
// https://twitter.com/isntitvacant/status/1131094910923231232
|
|
421
|
+
const exta = path.extname(a).toLowerCase()
|
|
422
|
+
const extb = path.extname(b).toLowerCase()
|
|
423
|
+
const basea = path.basename(a).toLowerCase()
|
|
424
|
+
const baseb = path.basename(b).toLowerCase()
|
|
425
|
+
|
|
426
|
+
return exta.localeCompare(extb, 'en') ||
|
|
427
|
+
basea.localeCompare(baseb, 'en') ||
|
|
428
|
+
a.localeCompare(b, 'en')
|
|
403
429
|
}
|
|
404
|
-
}
|
|
405
430
|
|
|
406
|
-
class Walker extends npmWalker(IgnoreWalker) {
|
|
407
431
|
globFiles (pattern, cb) {
|
|
408
|
-
glob(pattern, { dot: true, cwd: this.path, nocase: true }, cb)
|
|
432
|
+
glob(globify(pattern), { dot: true, cwd: this.path, nocase: true }, cb)
|
|
409
433
|
}
|
|
410
434
|
|
|
411
435
|
readPackageJson (entries) {
|
|
@@ -418,26 +442,6 @@ class Walker extends npmWalker(IgnoreWalker) {
|
|
|
418
442
|
}
|
|
419
443
|
}
|
|
420
444
|
|
|
421
|
-
class WalkerSync extends npmWalker(IgnoreWalkerSync) {
|
|
422
|
-
globFiles (pattern, cb) {
|
|
423
|
-
cb(null, glob.sync(pattern, { dot: true, cwd: this.path, nocase: true }))
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
readPackageJson (entries) {
|
|
427
|
-
const p = this.path + '/package.json'
|
|
428
|
-
try {
|
|
429
|
-
this.onReadPackageJson(entries, null, fs.readFileSync(p))
|
|
430
|
-
} catch (er) {
|
|
431
|
-
this.onReadPackageJson(entries, er)
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
walker (entry, opt, then) {
|
|
436
|
-
new WalkerSync(this.walkerOpt(entry, opt)).start()
|
|
437
|
-
then()
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
445
|
const walk = (options, callback) => {
|
|
442
446
|
options = options || {}
|
|
443
447
|
const p = new Promise((resolve, reject) => {
|
|
@@ -452,31 +456,5 @@ const walk = (options, callback) => {
|
|
|
452
456
|
return callback ? p.then(res => callback(null, res), callback) : p
|
|
453
457
|
}
|
|
454
458
|
|
|
455
|
-
const walkSync = options => {
|
|
456
|
-
options = options || {}
|
|
457
|
-
const bw = new BundleWalkerSync(options).start()
|
|
458
|
-
options.bundled = bw.result
|
|
459
|
-
options.packageJsonCache = bw.packageJsonCache
|
|
460
|
-
const walker = new WalkerSync(options)
|
|
461
|
-
walker.start()
|
|
462
|
-
return walker.result
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// optimize for compressibility
|
|
466
|
-
// extname, then basename, then locale alphabetically
|
|
467
|
-
// https://twitter.com/isntitvacant/status/1131094910923231232
|
|
468
|
-
const sort = (a, b) => {
|
|
469
|
-
const exta = path.extname(a).toLowerCase()
|
|
470
|
-
const extb = path.extname(b).toLowerCase()
|
|
471
|
-
const basea = path.basename(a).toLowerCase()
|
|
472
|
-
const baseb = path.basename(b).toLowerCase()
|
|
473
|
-
|
|
474
|
-
return exta.localeCompare(extb, 'en') ||
|
|
475
|
-
basea.localeCompare(baseb, 'en') ||
|
|
476
|
-
a.localeCompare(b, 'en')
|
|
477
|
-
}
|
|
478
|
-
|
|
479
459
|
module.exports = walk
|
|
480
|
-
walk.sync = walkSync
|
|
481
460
|
walk.Walker = Walker
|
|
482
|
-
walk.WalkerSync = WalkerSync
|
package/package.json
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-packlist",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.2",
|
|
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
8
|
"main": "lib",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"glob": "^
|
|
11
|
-
"ignore-walk": "^
|
|
10
|
+
"glob": "^8.0.1",
|
|
11
|
+
"ignore-walk": "^5.0.1",
|
|
12
12
|
"npm-bundled": "^1.1.2",
|
|
13
13
|
"npm-normalize-package-bin": "^1.0.1"
|
|
14
14
|
},
|
|
15
15
|
"author": "GitHub Inc.",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"files": [
|
|
18
|
-
"bin",
|
|
19
|
-
"lib"
|
|
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",
|
|
@@ -32,33 +33,29 @@
|
|
|
32
33
|
"postversion": "npm publish",
|
|
33
34
|
"prepublishOnly": "git push origin --follow-tags",
|
|
34
35
|
"eslint": "eslint",
|
|
35
|
-
"lint": "eslint
|
|
36
|
+
"lint": "eslint \"**/*.js\"",
|
|
36
37
|
"lintfix": "npm run lint -- --fix",
|
|
37
38
|
"npmclilint": "npmcli-lint",
|
|
38
|
-
"postlint": "
|
|
39
|
-
"template-
|
|
39
|
+
"postlint": "template-oss-check",
|
|
40
|
+
"template-oss-apply": "template-oss-apply --force"
|
|
40
41
|
},
|
|
41
42
|
"repository": {
|
|
42
43
|
"type": "git",
|
|
43
|
-
"url": "
|
|
44
|
+
"url": "https://github.com/npm/npm-packlist.git"
|
|
44
45
|
},
|
|
45
46
|
"tap": {
|
|
46
47
|
"test-env": [
|
|
47
48
|
"LC_ALL=sk"
|
|
48
|
-
],
|
|
49
|
-
"check-coverage": true,
|
|
50
|
-
"nyc-arg": [
|
|
51
|
-
"--include=index.js",
|
|
52
|
-
"--include=bin/index.js"
|
|
53
49
|
]
|
|
54
50
|
},
|
|
55
51
|
"bin": {
|
|
56
52
|
"npm-packlist": "bin/index.js"
|
|
57
53
|
},
|
|
58
54
|
"engines": {
|
|
59
|
-
"node": "^12.13.0 || ^14.15.0 || >=16"
|
|
55
|
+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
|
|
60
56
|
},
|
|
61
57
|
"templateOSS": {
|
|
62
|
-
"
|
|
58
|
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
59
|
+
"version": "3.4.1"
|
|
63
60
|
}
|
|
64
61
|
}
|