npm-packlist 2.1.1 → 2.1.5
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/index.js +56 -27
- package/package.json +6 -4
package/index.js
CHANGED
|
@@ -83,13 +83,23 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
83
83
|
opt.path = opt.path || process.cwd()
|
|
84
84
|
const dirName = path.basename(opt.path)
|
|
85
85
|
const parentName = path.basename(path.dirname(opt.path))
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
|
|
87
|
+
// only follow links in the root node_modules folder, because if those
|
|
88
|
+
// folders are included, it's because they're bundled, and bundles
|
|
89
|
+
// should include the contents, not the symlinks themselves.
|
|
90
|
+
// This regexp tests to see that we're either a node_modules folder,
|
|
91
|
+
// or a @scope within a node_modules folder, in the root's node_modules
|
|
92
|
+
// hierarchy (ie, not in test/foo/node_modules/ or something).
|
|
93
|
+
const followRe = /^(?:\/node_modules\/(?:@[^\/]+\/[^\/]+|[^\/]+)\/)*\/node_modules(?:\/@[^\/]+)?$/
|
|
94
|
+
const rootPath = opt.parent ? opt.parent.root : opt.path
|
|
95
|
+
const followTestPath = opt.path.replace(/\\/g, '/').substr(rootPath.length)
|
|
96
|
+
opt.follow = followRe.test(followTestPath)
|
|
97
|
+
|
|
89
98
|
super(opt)
|
|
90
99
|
|
|
91
100
|
// ignore a bunch of things by default at the root level.
|
|
92
|
-
// also ignore anything in
|
|
101
|
+
// also ignore anything in the main project node_modules hierarchy,
|
|
102
|
+
// except bundled dependencies
|
|
93
103
|
if (!this.parent) {
|
|
94
104
|
this.bundled = opt.bundled || []
|
|
95
105
|
this.bundledScopes = Array.from(new Set(
|
|
@@ -172,6 +182,13 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
172
182
|
|
|
173
183
|
getPackageFiles (entries, pkg) {
|
|
174
184
|
try {
|
|
185
|
+
// XXX this could be changed to use read-package-json-fast
|
|
186
|
+
// which handles the normalizing of bins for us, and simplifies
|
|
187
|
+
// the test for bundleDependencies and bundledDependencies later.
|
|
188
|
+
// HOWEVER if we do this, we need to be sure that we're careful
|
|
189
|
+
// about what we write back out since rpj-fast removes some fields
|
|
190
|
+
// that the user likely wants to keep. it also would add a second
|
|
191
|
+
// file read that we would want to optimize away.
|
|
175
192
|
pkg = normalizePackageBin(JSON.parse(pkg.toString()))
|
|
176
193
|
} catch (er) {
|
|
177
194
|
// not actually a valid package.json
|
|
@@ -192,7 +209,7 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
192
209
|
// the files list as the effective readdir result, that means it
|
|
193
210
|
// looks like we don't have a node_modules folder at all unless we
|
|
194
211
|
// include it here.
|
|
195
|
-
if (pkg.bundleDependencies && entries.includes('node_modules'))
|
|
212
|
+
if ((pkg.bundleDependencies || pkg.bundledDependencies) && entries.includes('node_modules'))
|
|
196
213
|
pkg.files.push('node_modules')
|
|
197
214
|
|
|
198
215
|
const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
|
|
@@ -210,35 +227,47 @@ const npmWalker = Class => class Walker extends Class {
|
|
|
210
227
|
let n = patterns.length
|
|
211
228
|
const set = new Set()
|
|
212
229
|
const negates = new Set()
|
|
213
|
-
const
|
|
230
|
+
const results = []
|
|
231
|
+
const then = (pattern, negate, er, fileList, i) => {
|
|
214
232
|
if (er)
|
|
215
233
|
return this.emit('error', er)
|
|
216
234
|
|
|
217
|
-
|
|
218
|
-
fileList.forEach(f => {
|
|
219
|
-
set.delete(f)
|
|
220
|
-
negates.add(f)
|
|
221
|
-
})
|
|
222
|
-
} else {
|
|
223
|
-
fileList.forEach(f => {
|
|
224
|
-
set.add(f)
|
|
225
|
-
negates.delete(f)
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
|
|
235
|
+
results[i] = { negate, fileList }
|
|
229
236
|
if (--n === 0) {
|
|
230
|
-
|
|
231
|
-
// replace the files array with our computed explicit set
|
|
232
|
-
pkg.files = list.concat(Array.from(negates).map(f => '!' + f))
|
|
233
|
-
const rdResult = Array.from(new Set(
|
|
234
|
-
list.map(f => f.replace(/^\/+/, ''))
|
|
235
|
-
))
|
|
236
|
-
super.onReaddir(rdResult)
|
|
237
|
+
processResults(results)
|
|
237
238
|
}
|
|
238
239
|
}
|
|
240
|
+
const processResults = results => {
|
|
241
|
+
for (const {negate, fileList} of results) {
|
|
242
|
+
if (negate) {
|
|
243
|
+
fileList.forEach(f => {
|
|
244
|
+
f = f.replace(/\/+$/, '')
|
|
245
|
+
set.delete(f)
|
|
246
|
+
negates.add(f)
|
|
247
|
+
})
|
|
248
|
+
} else {
|
|
249
|
+
fileList.forEach(f => {
|
|
250
|
+
f = f.replace(/\/+$/, '')
|
|
251
|
+
set.add(f)
|
|
252
|
+
negates.delete(f)
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const list = Array.from(set)
|
|
258
|
+
// replace the files array with our computed explicit set
|
|
259
|
+
pkg.files = list.concat(Array.from(negates).map(f => '!' + f))
|
|
260
|
+
const rdResult = Array.from(new Set(
|
|
261
|
+
list.map(f => f.replace(/^\/+/, ''))
|
|
262
|
+
))
|
|
263
|
+
super.onReaddir(rdResult)
|
|
264
|
+
}
|
|
239
265
|
|
|
240
|
-
|
|
241
|
-
|
|
266
|
+
// maintain the index so that we process them in-order only once all
|
|
267
|
+
// are completed, otherwise the parallelism messes things up, since a
|
|
268
|
+
// glob like **/*.js will always be slower than a subsequent !foo.js
|
|
269
|
+
patterns.forEach(({pattern, negate}, i) =>
|
|
270
|
+
this.globFiles(pattern, (er, res) => then(pattern, negate, er, res, i)))
|
|
242
271
|
}
|
|
243
272
|
|
|
244
273
|
filterEntry (entry, partial) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-packlist",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
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"
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"mutate-fs": "^2.1.1",
|
|
22
22
|
"require-inject": "^1.4.4",
|
|
23
|
-
"tap": "^14.10.
|
|
23
|
+
"tap": "^14.10.8"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"test": "tap",
|
|
27
27
|
"snap": "tap",
|
|
28
28
|
"preversion": "npm test",
|
|
29
29
|
"postversion": "npm publish",
|
|
30
|
-
"
|
|
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":
|
|
43
|
+
"bin": {
|
|
44
|
+
"npm-packlist": "bin/index.js"
|
|
45
|
+
},
|
|
44
46
|
"engines": {
|
|
45
47
|
"node": ">=10"
|
|
46
48
|
}
|