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