npm-packlist 2.2.1 → 4.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.
package/bin/index.js CHANGED
@@ -6,18 +6,19 @@ process.argv.slice(2).forEach(arg => {
6
6
  if (arg === '-h' || arg === '--help') {
7
7
  console.log('usage: npm-packlist [-s --sort] [directory, directory, ...]')
8
8
  process.exit(0)
9
- } else if (arg === '-s' || arg === '--sort')
9
+ } else if (arg === '-s' || arg === '--sort') {
10
10
  doSort = true
11
- else
11
+ } else {
12
12
  dirs.push(arg)
13
+ }
13
14
  })
14
15
 
15
- const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b)) : list
16
+ const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list
16
17
 
17
18
  const packlist = require('../')
18
- if (!dirs.length)
19
+ if (!dirs.length) {
19
20
  console.log(sort(packlist.sync({ path: process.cwd() })).join('\n'))
20
- else {
21
+ } else {
21
22
  dirs.forEach(path => {
22
23
  console.log(`> ${path}`)
23
24
  console.log(sort(packlist.sync({ path })).join('\n'))
@@ -58,6 +58,7 @@ const defaultRules = [
58
58
  '*.orig',
59
59
  '/package-lock.json',
60
60
  '/yarn.lock',
61
+ '/pnpm-lock.yaml',
61
62
  '/archived-packages/**',
62
63
  ]
63
64
 
@@ -97,13 +98,14 @@ const npmWalker = Class => class Walker extends Class {
97
98
  // ignore a bunch of things by default at the root level.
98
99
  // also ignore anything in the main project node_modules hierarchy,
99
100
  // except bundled dependencies
100
- if (!this.parent) {
101
+ if (this.isProject) {
101
102
  this.bundled = opt.bundled || []
102
103
  this.bundledScopes = Array.from(new Set(
103
104
  this.bundled.filter(f => /^@/.test(f))
104
105
  .map(f => f.split('/')[0])))
105
106
  const rules = defaultRules.join('\n') + '\n'
106
- this.packageJsonCache = opt.packageJsonCache || new Map()
107
+ this.packageJsonCache = this.parent ? this.parent.packageJsonCache
108
+ : (opt.packageJsonCache || new Map())
107
109
  super.onReadIgnoreFile(rootBuiltinRules, rules, _ => _)
108
110
  } else {
109
111
  this.bundled = []
@@ -112,8 +114,12 @@ const npmWalker = Class => class Walker extends Class {
112
114
  }
113
115
  }
114
116
 
117
+ get isProject () {
118
+ return !this.parent || this.parent.follow && this.isSymbolicLink
119
+ }
120
+
115
121
  onReaddir (entries) {
116
- if (!this.parent) {
122
+ if (this.isProject) {
117
123
  entries = entries.filter(e =>
118
124
  e !== '.git' &&
119
125
  !(e === 'node_modules' && this.bundled.length === 0)
@@ -126,8 +132,9 @@ const npmWalker = Class => class Walker extends Class {
126
132
  // to be in the state the user wants to include them, and
127
133
  // a package.json somewhere else might be a template or
128
134
  // test or something else entirely.
129
- if (this.parent || !entries.includes('package.json'))
135
+ if (!this.isProject || !entries.includes('package.json')) {
130
136
  return super.onReaddir(entries)
137
+ }
131
138
 
132
139
  // when the cache has been seeded with the root manifest,
133
140
  // we must respect that (it may differ from the filesystem)
@@ -137,8 +144,9 @@ const npmWalker = Class => class Walker extends Class {
137
144
  const pkg = this.packageJsonCache.get(ig)
138
145
 
139
146
  // fall back to filesystem when seeded manifest is invalid
140
- if (!pkg || typeof pkg !== 'object')
147
+ if (!pkg || typeof pkg !== 'object') {
141
148
  return this.readPackageJson(entries)
149
+ }
142
150
 
143
151
  // feels wonky, but this ensures package bin is _always_
144
152
  // normalized, as well as guarding against invalid JSON
@@ -149,22 +157,26 @@ const npmWalker = Class => class Walker extends Class {
149
157
  }
150
158
 
151
159
  onReadPackageJson (entries, er, pkg) {
152
- if (er)
160
+ if (er) {
153
161
  this.emit('error', er)
154
- else
162
+ } else {
155
163
  this.getPackageFiles(entries, pkg)
164
+ }
156
165
  }
157
166
 
158
167
  mustHaveFilesFromPackage (pkg) {
159
168
  const files = []
160
- if (pkg.browser)
169
+ if (pkg.browser) {
161
170
  files.push('/' + pkg.browser)
162
- if (pkg.main)
171
+ }
172
+ if (pkg.main) {
163
173
  files.push('/' + pkg.main)
174
+ }
164
175
  if (pkg.bin) {
165
176
  // always an object because normalized already
166
- for (const key in pkg.bin)
177
+ for (const key in pkg.bin) {
167
178
  files.push('/' + pkg.bin[key])
179
+ }
168
180
  }
169
181
  files.push(
170
182
  '/package.json',
@@ -194,8 +206,9 @@ const npmWalker = Class => class Walker extends Class {
194
206
  this.packageJsonCache.set(ig, pkg)
195
207
 
196
208
  // no files list, just return the normal readdir() result
197
- if (!Array.isArray(pkg.files))
209
+ if (!Array.isArray(pkg.files)) {
198
210
  return super.onReaddir(entries)
211
+ }
199
212
 
200
213
  pkg.files.push(...this.mustHaveFilesFromPackage(pkg))
201
214
 
@@ -204,13 +217,15 @@ const npmWalker = Class => class Walker extends Class {
204
217
  // the files list as the effective readdir result, that means it
205
218
  // looks like we don't have a node_modules folder at all unless we
206
219
  // include it here.
207
- if ((pkg.bundleDependencies || pkg.bundledDependencies) && entries.includes('node_modules'))
220
+ if ((pkg.bundleDependencies || pkg.bundledDependencies) && entries.includes('node_modules')) {
208
221
  pkg.files.push('node_modules')
222
+ }
209
223
 
210
224
  const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
211
225
  const excl = pattern.match(/^!+/)
212
- if (excl)
226
+ if (excl) {
213
227
  pattern = pattern.substr(excl[0].length)
228
+ }
214
229
  // strip off any / from the start of the pattern. /foo => foo
215
230
  pattern = pattern.replace(/^\/+/, '')
216
231
  // an odd number of ! means a negated pattern. !!foo ==> foo
@@ -224,15 +239,17 @@ const npmWalker = Class => class Walker extends Class {
224
239
  const negates = new Set()
225
240
  const results = []
226
241
  const then = (pattern, negate, er, fileList, i) => {
227
- if (er)
242
+ if (er) {
228
243
  return this.emit('error', er)
244
+ }
229
245
 
230
246
  results[i] = { negate, fileList }
231
- if (--n === 0)
247
+ if (--n === 0) {
232
248
  processResults(results)
249
+ }
233
250
  }
234
251
  const processResults = results => {
235
- for (const {negate, fileList} of results) {
252
+ for (const { negate, fileList } of results) {
236
253
  if (negate) {
237
254
  fileList.forEach(f => {
238
255
  f = f.replace(/\/+$/, '')
@@ -260,7 +277,7 @@ const npmWalker = Class => class Walker extends Class {
260
277
  // maintain the index so that we process them in-order only once all
261
278
  // are completed, otherwise the parallelism messes things up, since a
262
279
  // glob like **/*.js will always be slower than a subsequent !foo.js
263
- patterns.forEach(({pattern, negate}, i) =>
280
+ patterns.forEach(({ pattern, negate }, i) =>
264
281
  this.globFiles(pattern, (er, res) => then(pattern, negate, er, res, i)))
265
282
  }
266
283
 
@@ -268,15 +285,15 @@ const npmWalker = Class => class Walker extends Class {
268
285
  // get the partial path from the root of the walk
269
286
  const p = this.path.substr(this.root.length + 1)
270
287
  const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/
271
- const isRoot = !this.parent
272
- const pkg = isRoot && pkgre.test(entry) ?
288
+ const { isProject } = this
289
+ const pkg = isProject && pkgre.test(entry) ?
273
290
  entry.replace(pkgre, '$1') : null
274
- const rootNM = isRoot && entry === 'node_modules'
275
- const rootPJ = isRoot && entry === 'package.json'
291
+ const rootNM = isProject && entry === 'node_modules'
292
+ const rootPJ = isProject && entry === 'package.json'
276
293
 
277
294
  return (
278
295
  // if we're in a bundled package, check with the parent.
279
- /^node_modules($|\/)/i.test(p) ? this.parent.filterEntry(
296
+ /^node_modules($|\/)/i.test(p) && !this.isProject ? this.parent.filterEntry(
280
297
  this.basename + '/' + entry, partial)
281
298
 
282
299
  // if package is bundled, all files included
@@ -298,11 +315,11 @@ const npmWalker = Class => class Walker extends Class {
298
315
  : packageMustHavesRE.test(entry) ? true
299
316
 
300
317
  // npm-shrinkwrap and package.json always included in the root pkg
301
- : isRoot && (entry === 'npm-shrinkwrap.json' || entry === 'package.json')
318
+ : isProject && (entry === 'npm-shrinkwrap.json' || entry === 'package.json')
302
319
  ? true
303
320
 
304
321
  // package-lock never included
305
- : isRoot && entry === 'package-lock.json' ? false
322
+ : isProject && entry === 'package-lock.json' ? false
306
323
 
307
324
  // otherwise, follow ignore-walk's logic
308
325
  : super.filterEntry(entry, partial)
@@ -310,20 +327,22 @@ const npmWalker = Class => class Walker extends Class {
310
327
  }
311
328
 
312
329
  filterEntries () {
313
- if (this.ignoreRules['.npmignore'])
330
+ if (this.ignoreRules['.npmignore']) {
314
331
  this.ignoreRules['.gitignore'] = null
332
+ }
315
333
  this.filterEntries = super.filterEntries
316
334
  super.filterEntries()
317
335
  }
318
336
 
319
337
  addIgnoreFile (file, then) {
320
338
  const ig = path.resolve(this.path, file)
321
- if (file === 'package.json' && this.parent)
339
+ if (file === 'package.json' && !this.isProject) {
322
340
  then()
323
- else if (this.packageJsonCache.has(ig))
341
+ } else if (this.packageJsonCache.has(ig)) {
324
342
  this.onPackageJson(ig, this.packageJsonCache.get(ig), then)
325
- else
343
+ } else {
326
344
  super.addIgnoreFile(file, then)
345
+ }
327
346
  }
328
347
 
329
348
  onPackageJson (ig, pkg, then) {
@@ -347,19 +366,22 @@ const npmWalker = Class => class Walker extends Class {
347
366
  // override parent stat function to completely skip any filenames
348
367
  // that will break windows entirely.
349
368
  // XXX(isaacs) Next major version should make this an error instead.
350
- stat (entry, file, dir, then) {
351
- if (nameIsBadForWindows(entry))
369
+ stat ({ entry, file, dir }, then) {
370
+ if (nameIsBadForWindows(entry)) {
352
371
  then()
353
- else
354
- super.stat(entry, file, dir, then)
372
+ } else {
373
+ super.stat({ entry, file, dir }, then)
374
+ }
355
375
  }
356
376
 
357
- // override parent onstat function to nix all symlinks
358
- onstat (st, entry, file, dir, then) {
359
- if (st.isSymbolicLink())
377
+ // override parent onstat function to nix all symlinks, other than
378
+ // those coming out of the followed bundled symlink deps
379
+ onstat ({ st, entry, file, dir, isSymbolicLink }, then) {
380
+ if (st.isSymbolicLink()) {
360
381
  then()
361
- else
362
- super.onstat(st, entry, file, dir, then)
382
+ } else {
383
+ super.onstat({ st, entry, file, dir, isSymbolicLink }, then)
384
+ }
363
385
  }
364
386
 
365
387
  onReadIgnoreFile (file, data, then) {
@@ -371,8 +393,9 @@ const npmWalker = Class => class Walker extends Class {
371
393
  // ignore package.json files that are not json
372
394
  then()
373
395
  }
374
- } else
396
+ } else {
375
397
  super.onReadIgnoreFile(file, data, then)
398
+ }
376
399
  }
377
400
 
378
401
  sort (a, b) {
@@ -390,8 +413,8 @@ class Walker extends npmWalker(IgnoreWalker) {
390
413
  this.onReadPackageJson(entries, er, pkg))
391
414
  }
392
415
 
393
- walker (entry, then) {
394
- new Walker(this.walkerOpt(entry)).on('done', then).start()
416
+ walker (entry, opt, then) {
417
+ new Walker(this.walkerOpt(entry, opt)).on('done', then).start()
395
418
  }
396
419
  }
397
420
 
@@ -409,8 +432,8 @@ class WalkerSync extends npmWalker(IgnoreWalkerSync) {
409
432
  }
410
433
  }
411
434
 
412
- walker (entry, then) {
413
- new WalkerSync(this.walkerOpt(entry)).start()
435
+ walker (entry, opt, then) {
436
+ new WalkerSync(this.walkerOpt(entry, opt)).start()
414
437
  then()
415
438
  }
416
439
  }
package/package.json CHANGED
@@ -1,43 +1,42 @@
1
1
  {
2
2
  "name": "npm-packlist",
3
- "version": "2.2.1",
3
+ "version": "4.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"
7
7
  },
8
- "main": "index.js",
8
+ "main": "lib",
9
9
  "dependencies": {
10
- "glob": "^7.1.6",
11
- "ignore-walk": "^3.0.3",
12
- "npm-bundled": "^1.1.1",
10
+ "glob": "^7.2.0",
11
+ "ignore-walk": "^4.0.1",
12
+ "npm-bundled": "^1.1.2",
13
13
  "npm-normalize-package-bin": "^1.0.1"
14
14
  },
15
- "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
15
+ "author": "GitHub Inc.",
16
16
  "license": "ISC",
17
17
  "files": [
18
- "bin/index.js",
19
- "index.js"
18
+ "bin",
19
+ "lib"
20
20
  ],
21
21
  "devDependencies": {
22
- "eslint": "^7.25.0",
23
- "eslint-plugin-import": "^2.22.1",
24
- "eslint-plugin-node": "^11.1.0",
25
- "eslint-plugin-promise": "^5.1.0",
26
- "eslint-plugin-standard": "^5.0.0",
22
+ "@npmcli/template-oss": "^2.9.2",
27
23
  "mutate-fs": "^2.1.1",
28
- "tap": "^15.0.6"
24
+ "tap": "^15.1.6"
29
25
  },
30
26
  "scripts": {
31
27
  "test": "tap",
32
28
  "posttest": "npm run lint",
33
29
  "snap": "tap",
34
- "postsnap": "npm run lintfix",
30
+ "postsnap": "npm run lintfix --",
35
31
  "preversion": "npm test",
36
32
  "postversion": "npm publish",
37
33
  "prepublishOnly": "git push origin --follow-tags",
38
34
  "eslint": "eslint",
39
- "lint": "npm run eslint -- index.js bin/index.js \"test/**/*.js\"",
40
- "lintfix": "npm run lint -- --fix"
35
+ "lint": "eslint '**/*.js'",
36
+ "lintfix": "npm run lint -- --fix",
37
+ "npmclilint": "npmcli-lint",
38
+ "postlint": "npm-template-check",
39
+ "template-copy": "npm-template-copy --force"
41
40
  },
42
41
  "repository": {
43
42
  "type": "git",
@@ -57,6 +56,9 @@
57
56
  "npm-packlist": "bin/index.js"
58
57
  },
59
58
  "engines": {
60
- "node": ">=10"
59
+ "node": "^12.13.0 || ^14.15.0 || >=16"
60
+ },
61
+ "templateOSS": {
62
+ "version": "2.9.2"
61
63
  }
62
64
  }