npm-packlist 1.4.3 → 1.4.7

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 +42 -18
  2. package/package.json +12 -5
package/index.js CHANGED
@@ -17,6 +17,8 @@ const rootBuiltinRules = Symbol('root-builtin-rules')
17
17
  const packageNecessaryRules = Symbol('package-necessary-rules')
18
18
  const path = require('path')
19
19
 
20
+ const normalizePackageBin = require('npm-normalize-package-bin')
21
+
20
22
  const defaultRules = [
21
23
  '.npmignore',
22
24
  '.gitignore',
@@ -51,6 +53,9 @@ const defaultRules = [
51
53
  'core.+([0-9])',
52
54
  ]
53
55
 
56
+ // There may be others, but :?|<> are handled by node-tar
57
+ const nameIsBadForWindows = file => /\*/.test(file)
58
+
54
59
  // a decorator that applies our custom rules to an ignore walker
55
60
  const npmWalker = Class => class Walker extends Class {
56
61
  constructor (opt) {
@@ -92,8 +97,12 @@ const npmWalker = Class => class Walker extends Class {
92
97
  }
93
98
 
94
99
  onReaddir (entries) {
95
- if (!this.parent)
96
- entries = entries.filter(e => e !== '.git')
100
+ if (!this.parent) {
101
+ entries = entries.filter(e =>
102
+ e !== '.git' &&
103
+ !(e === 'node_modules' && this.bundled.length === 0)
104
+ )
105
+ }
97
106
  return super.onReaddir(entries)
98
107
  }
99
108
 
@@ -166,14 +175,14 @@ const npmWalker = Class => class Walker extends Class {
166
175
  pkg.browser ? '!' + pkg.browser : '',
167
176
  pkg.main ? '!' + pkg.main : '',
168
177
  '!package.json',
178
+ '!npm-shrinkwrap.json',
169
179
  '!@(readme|copying|license|licence|notice|changes|changelog|history){,.*[^~$]}'
170
180
  ]
171
- if (pkg.bin)
172
- if (typeof pkg.bin === "object")
173
- for (const key in pkg.bin)
174
- rules.push('!' + pkg.bin[key])
175
- else
176
- rules.push('!' + pkg.bin)
181
+ if (pkg.bin) {
182
+ // always an object, because normalized already
183
+ for (const key in pkg.bin)
184
+ rules.push('!' + pkg.bin[key])
185
+ }
177
186
 
178
187
  const data = rules.filter(f => f).join('\n') + '\n'
179
188
  super.onReadIgnoreFile(packageNecessaryRules, data, _=>_)
@@ -186,6 +195,16 @@ const npmWalker = Class => class Walker extends Class {
186
195
  then()
187
196
  }
188
197
 
198
+ // override parent stat function to completely skip any filenames
199
+ // that will break windows entirely.
200
+ // XXX(isaacs) Next major version should make this an error instead.
201
+ stat (entry, file, dir, then) {
202
+ if (nameIsBadForWindows(entry))
203
+ then()
204
+ else
205
+ super.stat(entry, file, dir, then)
206
+ }
207
+
189
208
  // override parent onstat function to nix all symlinks
190
209
  onstat (st, entry, file, dir, then) {
191
210
  if (st.isSymbolicLink())
@@ -198,7 +217,7 @@ const npmWalker = Class => class Walker extends Class {
198
217
  if (file === 'package.json')
199
218
  try {
200
219
  const ig = path.resolve(this.path, file)
201
- this.onPackageJson(ig, JSON.parse(data), then)
220
+ this.onPackageJson(ig, normalizePackageBin(JSON.parse(data)), then)
202
221
  } catch (er) {
203
222
  // ignore package.json files that are not json
204
223
  then()
@@ -249,15 +268,20 @@ const walkSync = options => {
249
268
  return walker.result
250
269
  }
251
270
 
252
- // package.json first, node_modules last, files before folders, alphasort
253
- const sort = (a, b) =>
254
- a === 'package.json' ? -1
255
- : b === 'package.json' ? 1
256
- : /^node_modules/.test(a) && !/^node_modules/.test(b) ? 1
257
- : /^node_modules/.test(b) && !/^node_modules/.test(a) ? -1
258
- : path.dirname(a) === '.' && path.dirname(b) !== '.' ? -1
259
- : path.dirname(b) === '.' && path.dirname(a) !== '.' ? 1
260
- : a.localeCompare(b)
271
+ // optimize for compressibility
272
+ // extname, then basename, then locale alphabetically
273
+ // https://twitter.com/isntitvacant/status/1131094910923231232
274
+ const sort = (a, b) => {
275
+ const exta = path.extname(a).toLowerCase()
276
+ const extb = path.extname(b).toLowerCase()
277
+ const basea = path.basename(a).toLowerCase()
278
+ const baseb = path.basename(b).toLowerCase()
279
+
280
+ return exta.localeCompare(extb) ||
281
+ basea.localeCompare(baseb) ||
282
+ a.localeCompare(b)
283
+ }
284
+
261
285
 
262
286
  module.exports = walk
263
287
  walk.sync = walkSync
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "npm-packlist",
3
- "version": "1.4.3",
3
+ "version": "1.4.7",
4
+ "publishConfig": {
5
+ "tag": "legacy-v1"
6
+ },
4
7
  "description": "Get a list of the files to add from a folder into an npm package",
5
8
  "directories": {
6
9
  "test": "test"
@@ -18,13 +21,14 @@
18
21
  "devDependencies": {
19
22
  "mkdirp": "^0.5.1",
20
23
  "rimraf": "^2.6.1",
21
- "tap": "^11.1.5"
24
+ "tap": "^14.6.9"
22
25
  },
23
26
  "scripts": {
24
- "test": "tap test/*.js --100 -J",
27
+ "test": "tap",
28
+ "snap": "tap",
25
29
  "preversion": "npm test",
26
30
  "postversion": "npm publish",
27
- "postpublish": "git push origin --all --follow-tags"
31
+ "postpublish": "git push origin --follow-tags"
28
32
  },
29
33
  "repository": {
30
34
  "type": "git",
@@ -33,5 +37,8 @@
33
37
  "bugs": {
34
38
  "url": "https://github.com/npm/npm-packlist/issues"
35
39
  },
36
- "homepage": "https://www.npmjs.com/package/npm-packlist"
40
+ "homepage": "https://www.npmjs.com/package/npm-packlist",
41
+ "tap": {
42
+ "jobs": 1
43
+ }
37
44
  }