npm-packlist 2.1.4 → 2.2.2

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 (3) hide show
  1. package/bin/index.js +3 -2
  2. package/index.js +28 -28
  3. package/package.json +17 -4
package/bin/index.js CHANGED
@@ -12,13 +12,14 @@ process.argv.slice(2).forEach(arg => {
12
12
  dirs.push(arg)
13
13
  })
14
14
 
15
- const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b)) : list
15
+ const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list
16
16
 
17
17
  const packlist = require('../')
18
18
  if (!dirs.length)
19
19
  console.log(sort(packlist.sync({ path: process.cwd() })).join('\n'))
20
- else
20
+ else {
21
21
  dirs.forEach(path => {
22
22
  console.log(`> ${path}`)
23
23
  console.log(sort(packlist.sync({ path })).join('\n'))
24
24
  })
25
+ }
package/index.js CHANGED
@@ -26,11 +26,10 @@ 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
- const packageMustHavesRE = new RegExp(`^(${packageMustHaveFileNames})(\\..*[^~\$])?$`, 'i')
32
+ const packageMustHavesRE = new RegExp(`^(${packageMustHaveFileNames})(\\..*[^~$])?$`, 'i')
34
33
 
35
34
  const fs = require('fs')
36
35
  const glob = require('glob')
@@ -76,13 +75,11 @@ const npmWalker = Class => class Walker extends Class {
76
75
  'package.json',
77
76
  '.npmignore',
78
77
  '.gitignore',
79
- packageNecessaryRules
78
+ packageNecessaryRules,
80
79
  ]
81
80
 
82
81
  opt.includeEmpty = false
83
82
  opt.path = opt.path || process.cwd()
84
- const dirName = path.basename(opt.path)
85
- const parentName = path.basename(path.dirname(opt.path))
86
83
 
87
84
  // only follow links in the root node_modules folder, because if those
88
85
  // folders are included, it's because they're bundled, and bundles
@@ -90,7 +87,7 @@ const npmWalker = Class => class Walker extends Class {
90
87
  // This regexp tests to see that we're either a node_modules folder,
91
88
  // or a @scope within a node_modules folder, in the root's node_modules
92
89
  // hierarchy (ie, not in test/foo/node_modules/ or something).
93
- const followRe = /^(?:\/node_modules\/(?:@[^\/]+\/[^\/]+|[^\/]+)\/)*\/node_modules(?:\/@[^\/]+)?$/
90
+ const followRe = /^(?:\/node_modules\/(?:@[^/]+\/[^/]+|[^/]+)\/)*\/node_modules(?:\/@[^/]+)?$/
94
91
  const rootPath = opt.parent ? opt.parent.root : opt.path
95
92
  const followTestPath = opt.path.replace(/\\/g, '/').substr(rootPath.length)
96
93
  opt.follow = followRe.test(followTestPath)
@@ -104,10 +101,10 @@ const npmWalker = Class => class Walker extends Class {
104
101
  this.bundled = opt.bundled || []
105
102
  this.bundledScopes = Array.from(new Set(
106
103
  this.bundled.filter(f => /^@/.test(f))
107
- .map(f => f.split('/')[0])))
104
+ .map(f => f.split('/')[0])))
108
105
  const rules = defaultRules.join('\n') + '\n'
109
106
  this.packageJsonCache = opt.packageJsonCache || new Map()
110
- super.onReadIgnoreFile(rootBuiltinRules, rules, _=>_)
107
+ super.onReadIgnoreFile(rootBuiltinRules, rules, _ => _)
111
108
  } else {
112
109
  this.bundled = []
113
110
  this.bundledScopes = []
@@ -129,9 +126,8 @@ const npmWalker = Class => class Walker extends Class {
129
126
  // to be in the state the user wants to include them, and
130
127
  // a package.json somewhere else might be a template or
131
128
  // test or something else entirely.
132
- if (this.parent || !entries.includes('package.json')) {
129
+ if (this.parent || !entries.includes('package.json'))
133
130
  return super.onReaddir(entries)
134
- }
135
131
 
136
132
  // when the cache has been seeded with the root manifest,
137
133
  // we must respect that (it may differ from the filesystem)
@@ -141,9 +137,8 @@ const npmWalker = Class => class Walker extends Class {
141
137
  const pkg = this.packageJsonCache.get(ig)
142
138
 
143
139
  // fall back to filesystem when seeded manifest is invalid
144
- if (!pkg || typeof pkg !== 'object') {
140
+ if (!pkg || typeof pkg !== 'object')
145
141
  return this.readPackageJson(entries)
146
- }
147
142
 
148
143
  // feels wonky, but this ensures package bin is _always_
149
144
  // normalized, as well as guarding against invalid JSON
@@ -175,13 +170,20 @@ const npmWalker = Class => class Walker extends Class {
175
170
  '/package.json',
176
171
  '/npm-shrinkwrap.json',
177
172
  '!/package-lock.json',
178
- packageMustHaves,
173
+ packageMustHaves
179
174
  )
180
175
  return files
181
176
  }
182
177
 
183
178
  getPackageFiles (entries, pkg) {
184
179
  try {
180
+ // XXX this could be changed to use read-package-json-fast
181
+ // which handles the normalizing of bins for us, and simplifies
182
+ // the test for bundleDependencies and bundledDependencies later.
183
+ // HOWEVER if we do this, we need to be sure that we're careful
184
+ // about what we write back out since rpj-fast removes some fields
185
+ // that the user likely wants to keep. it also would add a second
186
+ // file read that we would want to optimize away.
185
187
  pkg = normalizePackageBin(JSON.parse(pkg.toString()))
186
188
  } catch (er) {
187
189
  // not actually a valid package.json
@@ -202,7 +204,7 @@ const npmWalker = Class => class Walker extends Class {
202
204
  // the files list as the effective readdir result, that means it
203
205
  // looks like we don't have a node_modules folder at all unless we
204
206
  // include it here.
205
- if (pkg.bundleDependencies && entries.includes('node_modules'))
207
+ if ((pkg.bundleDependencies || pkg.bundledDependencies) && entries.includes('node_modules'))
206
208
  pkg.files.push('node_modules')
207
209
 
208
210
  const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => {
@@ -226,9 +228,8 @@ const npmWalker = Class => class Walker extends Class {
226
228
  return this.emit('error', er)
227
229
 
228
230
  results[i] = { negate, fileList }
229
- if (--n === 0) {
231
+ if (--n === 0)
230
232
  processResults(results)
231
- }
232
233
  }
233
234
  const processResults = results => {
234
235
  for (const {negate, fileList} of results) {
@@ -266,7 +267,7 @@ const npmWalker = Class => class Walker extends Class {
266
267
  filterEntry (entry, partial) {
267
268
  // get the partial path from the root of the walk
268
269
  const p = this.path.substr(this.root.length + 1)
269
- const pkgre = /^node_modules\/(@[^\/]+\/?[^\/]+|[^\/]+)(\/.*)?$/
270
+ const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/
270
271
  const isRoot = !this.parent
271
272
  const pkg = isRoot && pkgre.test(entry) ?
272
273
  entry.replace(pkgre, '$1') : null
@@ -276,7 +277,7 @@ const npmWalker = Class => class Walker extends Class {
276
277
  return (
277
278
  // if we're in a bundled package, check with the parent.
278
279
  /^node_modules($|\/)/i.test(p) ? this.parent.filterEntry(
279
- this.basename + '/' + entry, partial)
280
+ this.basename + '/' + entry, partial)
280
281
 
281
282
  // if package is bundled, all files included
282
283
  // also include @scope dirs for bundled scoped deps
@@ -284,8 +285,8 @@ const npmWalker = Class => class Walker extends Class {
284
285
  // However, this only matters if we're in the root.
285
286
  // node_modules folders elsewhere, like lib/node_modules,
286
287
  // should be included normally unless ignored.
287
- : pkg ? -1 !== this.bundled.indexOf(pkg) ||
288
- -1 !== this.bundledScopes.indexOf(pkg)
288
+ : pkg ? this.bundled.indexOf(pkg) !== -1 ||
289
+ this.bundledScopes.indexOf(pkg) !== -1
289
290
 
290
291
  // only walk top node_modules if we want to bundle something
291
292
  : rootNM ? !!this.bundled.length
@@ -301,10 +302,10 @@ const npmWalker = Class => class Walker extends Class {
301
302
  ? true
302
303
 
303
304
  // package-lock never included
304
- : isRoot && entry === 'package-lock.json' ? false
305
+ : isRoot && entry === 'package-lock.json' ? false
305
306
 
306
- // otherwise, follow ignore-walk's logic
307
- : super.filterEntry(entry, partial)
307
+ // otherwise, follow ignore-walk's logic
308
+ : super.filterEntry(entry, partial)
308
309
  )
309
310
  }
310
311
 
@@ -447,12 +448,11 @@ const sort = (a, b) => {
447
448
  const basea = path.basename(a).toLowerCase()
448
449
  const baseb = path.basename(b).toLowerCase()
449
450
 
450
- return exta.localeCompare(extb) ||
451
- basea.localeCompare(baseb) ||
452
- a.localeCompare(b)
451
+ return exta.localeCompare(extb, 'en') ||
452
+ basea.localeCompare(baseb, 'en') ||
453
+ a.localeCompare(b, 'en')
453
454
  }
454
455
 
455
-
456
456
  module.exports = walk
457
457
  walk.sync = walkSync
458
458
  walk.Walker = Walker
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-packlist",
3
- "version": "2.1.4",
3
+ "version": "2.2.2",
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,25 +15,38 @@
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": {
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",
21
27
  "mutate-fs": "^2.1.1",
22
- "require-inject": "^1.4.4",
23
- "tap": "^14.10.7"
28
+ "tap": "^15.0.6"
24
29
  },
25
30
  "scripts": {
26
31
  "test": "tap",
32
+ "posttest": "npm run lint",
27
33
  "snap": "tap",
34
+ "postsnap": "npm run lintfix",
28
35
  "preversion": "npm test",
29
36
  "postversion": "npm publish",
30
- "prepublishOnly": "git push origin --follow-tags"
37
+ "prepublishOnly": "git push origin --follow-tags",
38
+ "eslint": "eslint",
39
+ "lint": "npm run eslint -- index.js bin/index.js \"test/**/*.js\"",
40
+ "lintfix": "npm run lint -- --fix"
31
41
  },
32
42
  "repository": {
33
43
  "type": "git",
34
44
  "url": "git+https://github.com/npm/npm-packlist.git"
35
45
  },
36
46
  "tap": {
47
+ "test-env": [
48
+ "LC_ALL=sk"
49
+ ],
37
50
  "check-coverage": true,
38
51
  "nyc-arg": [
39
52
  "--include=index.js",