npm-packlist 2.1.2 → 2.2.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 +43 -25
  2. package/package.json +7 -5
package/index.js CHANGED
@@ -26,8 +26,7 @@ const normalizePackageBin = require('npm-normalize-package-bin')
26
26
  // localized documentation and other use cases. Adding a `/` to
27
27
  // these rules, while tempting and arguably more "correct", is a
28
28
  // significant change that will break existing use cases.
29
- const packageMustHaveFileNames =
30
- 'readme|copying|license|licence|notice|changes|changelog|history'
29
+ const packageMustHaveFileNames = 'readme|copying|license|licence'
31
30
 
32
31
  const packageMustHaves = `@(${packageMustHaveFileNames}){,.*[^~$]}`
33
32
  const packageMustHavesRE = new RegExp(`^(${packageMustHaveFileNames})(\\..*[^~\$])?$`, 'i')
@@ -182,6 +181,13 @@ const npmWalker = Class => class Walker extends Class {
182
181
 
183
182
  getPackageFiles (entries, pkg) {
184
183
  try {
184
+ // XXX this could be changed to use read-package-json-fast
185
+ // which handles the normalizing of bins for us, and simplifies
186
+ // the test for bundleDependencies and bundledDependencies later.
187
+ // HOWEVER if we do this, we need to be sure that we're careful
188
+ // about what we write back out since rpj-fast removes some fields
189
+ // that the user likely wants to keep. it also would add a second
190
+ // file read that we would want to optimize away.
185
191
  pkg = normalizePackageBin(JSON.parse(pkg.toString()))
186
192
  } catch (er) {
187
193
  // not actually a valid package.json
@@ -202,7 +208,7 @@ const npmWalker = Class => class Walker extends Class {
202
208
  // the files list as the effective readdir result, that means it
203
209
  // looks like we don't have a node_modules folder at all unless we
204
210
  // include it here.
205
- if (pkg.bundleDependencies && entries.includes('node_modules'))
211
+ if ((pkg.bundleDependencies || pkg.bundledDependencies) && entries.includes('node_modules'))
206
212
  pkg.files.push('node_modules')
207
213
 
208
214
  const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
@@ -220,35 +226,47 @@ const npmWalker = Class => class Walker extends Class {
220
226
  let n = patterns.length
221
227
  const set = new Set()
222
228
  const negates = new Set()
223
- const then = (pattern, negate, er, fileList) => {
229
+ const results = []
230
+ const then = (pattern, negate, er, fileList, i) => {
224
231
  if (er)
225
232
  return this.emit('error', er)
226
233
 
227
- if (negate) {
228
- fileList.forEach(f => {
229
- set.delete(f)
230
- negates.add(f)
231
- })
232
- } else {
233
- fileList.forEach(f => {
234
- set.add(f)
235
- negates.delete(f)
236
- })
237
- }
238
-
234
+ results[i] = { negate, fileList }
239
235
  if (--n === 0) {
240
- const list = Array.from(set)
241
- // replace the files array with our computed explicit set
242
- pkg.files = list.concat(Array.from(negates).map(f => '!' + f))
243
- const rdResult = Array.from(new Set(
244
- list.map(f => f.replace(/^\/+/, ''))
245
- ))
246
- super.onReaddir(rdResult)
236
+ processResults(results)
247
237
  }
248
238
  }
239
+ const processResults = results => {
240
+ for (const {negate, fileList} of results) {
241
+ if (negate) {
242
+ fileList.forEach(f => {
243
+ f = f.replace(/\/+$/, '')
244
+ set.delete(f)
245
+ negates.add(f)
246
+ })
247
+ } else {
248
+ fileList.forEach(f => {
249
+ f = f.replace(/\/+$/, '')
250
+ set.add(f)
251
+ negates.delete(f)
252
+ })
253
+ }
254
+ }
255
+
256
+ const list = Array.from(set)
257
+ // replace the files array with our computed explicit set
258
+ pkg.files = list.concat(Array.from(negates).map(f => '!' + f))
259
+ const rdResult = Array.from(new Set(
260
+ list.map(f => f.replace(/^\/+/, ''))
261
+ ))
262
+ super.onReaddir(rdResult)
263
+ }
249
264
 
250
- patterns.forEach(({pattern, negate}) =>
251
- this.globFiles(pattern, (er, res) => then(pattern, negate, er, res)))
265
+ // maintain the index so that we process them in-order only once all
266
+ // are completed, otherwise the parallelism messes things up, since a
267
+ // glob like **/*.js will always be slower than a subsequent !foo.js
268
+ patterns.forEach(({pattern, negate}, i) =>
269
+ this.globFiles(pattern, (er, res) => then(pattern, negate, er, res, i)))
252
270
  }
253
271
 
254
272
  filterEntry (entry, partial) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-packlist",
3
- "version": "2.1.2",
3
+ "version": "2.2.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"
@@ -15,19 +15,19 @@
15
15
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
16
16
  "license": "ISC",
17
17
  "files": [
18
+ "bin/index.js",
18
19
  "index.js"
19
20
  ],
20
21
  "devDependencies": {
21
22
  "mutate-fs": "^2.1.1",
22
- "require-inject": "^1.4.4",
23
- "tap": "^14.10.7"
23
+ "tap": "^15.0.6"
24
24
  },
25
25
  "scripts": {
26
26
  "test": "tap",
27
27
  "snap": "tap",
28
28
  "preversion": "npm test",
29
29
  "postversion": "npm publish",
30
- "postpublish": "git push origin --follow-tags"
30
+ "prepublishOnly": "git push origin --follow-tags"
31
31
  },
32
32
  "repository": {
33
33
  "type": "git",
@@ -40,7 +40,9 @@
40
40
  "--include=bin/index.js"
41
41
  ]
42
42
  },
43
- "bin": "bin/index.js",
43
+ "bin": {
44
+ "npm-packlist": "bin/index.js"
45
+ },
44
46
  "engines": {
45
47
  "node": ">=10"
46
48
  }