npm-packlist 4.0.0 → 5.0.0

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.
Files changed (3) hide show
  1. package/bin/index.js +21 -8
  2. package/lib/index.js +38 -61
  3. package/package.json +14 -17
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 packlist = require('../')
19
- if (!dirs.length) {
20
- console.log(sort(packlist.sync({ path: process.cwd() })).join('\n'))
21
- } else {
22
- dirs.forEach(path => {
23
- console.log(`> ${path}`)
24
- console.log(sort(packlist.sync({ path })).join('\n'))
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')
@@ -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',
@@ -65,8 +81,7 @@ const defaultRules = [
65
81
  // There may be others, but :?|<> are handled by node-tar
66
82
  const nameIsBadForWindows = file => /\*/.test(file)
67
83
 
68
- // a decorator that applies our custom rules to an ignore walker
69
- const npmWalker = Class => class Walker extends Class {
84
+ class Walker extends IgnoreWalker {
70
85
  constructor (opt) {
71
86
  opt = opt || {}
72
87
 
@@ -90,7 +105,7 @@ const npmWalker = Class => class Walker extends Class {
90
105
  // hierarchy (ie, not in test/foo/node_modules/ or something).
91
106
  const followRe = /^(?:\/node_modules\/(?:@[^/]+\/[^/]+|[^/]+)\/)*\/node_modules(?:\/@[^/]+)?$/
92
107
  const rootPath = opt.parent ? opt.parent.root : opt.path
93
- const followTestPath = opt.path.replace(/\\/g, '/').substr(rootPath.length)
108
+ const followTestPath = opt.path.replace(/\\/g, '/').slice(rootPath.length)
94
109
  opt.follow = followRe.test(followTestPath)
95
110
 
96
111
  super(opt)
@@ -224,7 +239,7 @@ const npmWalker = Class => class Walker extends Class {
224
239
  const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
225
240
  const excl = pattern.match(/^!+/)
226
241
  if (excl) {
227
- pattern = pattern.substr(excl[0].length)
242
+ pattern = pattern.slice(excl[0].length)
228
243
  }
229
244
  // strip off any / from the start of the pattern. /foo => foo
230
245
  pattern = pattern.replace(/^\/+/, '')
@@ -248,8 +263,8 @@ const npmWalker = Class => class Walker extends Class {
248
263
  processResults(results)
249
264
  }
250
265
  }
251
- const processResults = results => {
252
- for (const { negate, fileList } of results) {
266
+ const processResults = processed => {
267
+ for (const { negate, fileList } of processed) {
253
268
  if (negate) {
254
269
  fileList.forEach(f => {
255
270
  f = f.replace(/\/+$/, '')
@@ -283,11 +298,11 @@ const npmWalker = Class => class Walker extends Class {
283
298
 
284
299
  filterEntry (entry, partial) {
285
300
  // get the partial path from the root of the walk
286
- const p = this.path.substr(this.root.length + 1)
287
- const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/
301
+ const p = this.path.slice(this.root.length + 1)
288
302
  const { isProject } = this
289
- const pkg = isProject && pkgre.test(entry) ?
290
- entry.replace(pkgre, '$1') : null
303
+ const pkg = isProject && pathHasPkg(entry)
304
+ ? pkgFromPath(entry)
305
+ : null
291
306
  const rootNM = isProject && entry === 'node_modules'
292
307
  const rootPJ = isProject && entry === 'package.json'
293
308
 
@@ -399,11 +414,19 @@ const npmWalker = Class => class Walker extends Class {
399
414
  }
400
415
 
401
416
  sort (a, b) {
402
- return sort(a, b)
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')
403
428
  }
404
- }
405
429
 
406
- class Walker extends npmWalker(IgnoreWalker) {
407
430
  globFiles (pattern, cb) {
408
431
  glob(pattern, { dot: true, cwd: this.path, nocase: true }, cb)
409
432
  }
@@ -418,26 +441,6 @@ class Walker extends npmWalker(IgnoreWalker) {
418
441
  }
419
442
  }
420
443
 
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
444
  const walk = (options, callback) => {
442
445
  options = options || {}
443
446
  const p = new Promise((resolve, reject) => {
@@ -452,31 +455,5 @@ const walk = (options, callback) => {
452
455
  return callback ? p.then(res => callback(null, res), callback) : p
453
456
  }
454
457
 
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
458
  module.exports = walk
480
- walk.sync = walkSync
481
459
  walk.Walker = Walker
482
- walk.WalkerSync = WalkerSync
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-packlist",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
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"
@@ -8,20 +8,21 @@
8
8
  "main": "lib",
9
9
  "dependencies": {
10
10
  "glob": "^7.2.0",
11
- "ignore-walk": "^4.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/template-oss": "^2.9.2",
22
+ "@npmcli/eslint-config": "^3.0.1",
23
+ "@npmcli/template-oss": "3.2.2",
23
24
  "mutate-fs": "^2.1.1",
24
- "tap": "^15.1.6"
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 '**/*.js'",
36
+ "lint": "eslint \"**/*.js\"",
36
37
  "lintfix": "npm run lint -- --fix",
37
38
  "npmclilint": "npmcli-lint",
38
- "postlint": "npm-template-check",
39
- "template-copy": "npm-template-copy --force"
39
+ "postlint": "template-oss-check",
40
+ "template-oss-apply": "template-oss-apply --force"
40
41
  },
41
42
  "repository": {
42
43
  "type": "git",
43
- "url": "git+https://github.com/npm/npm-packlist.git"
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
- "version": "2.9.2"
58
+ "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
59
+ "version": "3.2.2"
63
60
  }
64
61
  }