npm-packlist 7.0.4 → 8.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.
package/README.md CHANGED
@@ -30,9 +30,11 @@ arborist.loadActual().then((tree) => {
30
30
  This uses the following rules:
31
31
 
32
32
  1. If a `package.json` file is found, and it has a `files` list,
33
- then ignore everything that isn't in `files`. Always include the
33
+ then ignore everything that isn't in `files`. Always include the root
34
34
  readme, license, licence and copying files, if they exist, as well
35
- as the package.json file itself.
35
+ as the package.json file itself. Non-root readme, license, licence and
36
+ copying files are included by default, but can be excluded using the
37
+ `files` list e.g. `"!readme"`.
36
38
  2. If there's no `package.json` file (or it has no `files` list), and
37
39
  there is a `.npmignore` file, then ignore all the files in the
38
40
  `.npmignore` file.
package/lib/index.js CHANGED
@@ -38,13 +38,22 @@ const defaults = [
38
38
  ]
39
39
 
40
40
  const strictDefaults = [
41
- // these are forcibly included at all levels
41
+ // these are forcibly excluded
42
+ '/.git',
43
+ ]
44
+
45
+ const allLevels = [
46
+ // these are included by default but can be excluded by package.json files array
42
47
  '!/readme{,.*[^~$]}',
43
48
  '!/copying{,.*[^~$]}',
44
49
  '!/license{,.*[^~$]}',
45
50
  '!/licence{,.*[^~$]}',
46
- // these are forcibly excluded
47
- '/.git',
51
+ ]
52
+
53
+ const rootOnly = [
54
+ /^!.*readme/i,
55
+ /^!.*copying/i,
56
+ /^!.*licen[sc]e/i,
48
57
  ]
49
58
 
50
59
  const normalizePath = (path) => path.split('\\').join('/')
@@ -132,6 +141,7 @@ class PackWalker extends IgnoreWalker {
132
141
  // known required files for this directory
133
142
  this.injectRules(strictRules, [
134
143
  ...strictDefaults,
144
+ ...allLevels,
135
145
  ...this.requiredFiles.map((file) => `!${file}`),
136
146
  ])
137
147
  }
@@ -284,6 +294,7 @@ class PackWalker extends IgnoreWalker {
284
294
  const ignores = []
285
295
  const strict = [
286
296
  ...strictDefaults,
297
+ ...allLevels,
287
298
  '!/package.json',
288
299
  '/.git',
289
300
  '/node_modules',
@@ -304,6 +315,9 @@ class PackWalker extends IgnoreWalker {
304
315
  file = file.slice(0, -2)
305
316
  }
306
317
  const inverse = `!${file}`
318
+
319
+ this.excludeNonRoot(file)
320
+
307
321
  try {
308
322
  // if an entry in the files array is a specific file, then we need to include it as a
309
323
  // strict requirement for this package. if it's a directory or a pattern, it's a default
@@ -352,6 +366,20 @@ class PackWalker extends IgnoreWalker {
352
366
  this.injectRules(strictRules, strict, callback)
353
367
  }
354
368
 
369
+ // excludes non root files by checking if elements from the files array in
370
+ // package.json contain an ! and readme/license/licence/copying, and then
371
+ // removing readme/license/licence/copying accordingly from strict defaults
372
+ excludeNonRoot (file) {
373
+ // Find the pattern
374
+ const matchingPattern = rootOnly.find(regex => regex.test(file))
375
+
376
+ if (matchingPattern) {
377
+ // Find which index matches the pattern and remove it from allLevels
378
+ const indexToRemove = allLevels.findIndex(element => matchingPattern.test(element))
379
+ allLevels.splice(indexToRemove, 1)
380
+ }
381
+ }
382
+
355
383
  // custom method: after we've finished gathering the files for the root package, we call this
356
384
  // before emitting the 'done' event in order to gather all of the files for bundled deps
357
385
  async gatherBundles () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-packlist",
3
- "version": "7.0.4",
3
+ "version": "8.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"
@@ -18,7 +18,7 @@
18
18
  "devDependencies": {
19
19
  "@npmcli/arborist": "^6.0.0 || ^6.0.0-pre.0",
20
20
  "@npmcli/eslint-config": "^4.0.0",
21
- "@npmcli/template-oss": "4.10.0",
21
+ "@npmcli/template-oss": "4.18.0",
22
22
  "mutate-fs": "^2.1.1",
23
23
  "tap": "^16.0.1"
24
24
  },
@@ -55,6 +55,7 @@
55
55
  },
56
56
  "templateOSS": {
57
57
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
58
- "version": "4.10.0"
58
+ "version": "4.18.0",
59
+ "publish": true
59
60
  }
60
61
  }