npm-packlist 7.0.4 → 8.0.1

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,9 +294,11 @@ 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',
301
+ '.npmrc',
290
302
  '/package-lock.json',
291
303
  '/yarn.lock',
292
304
  '/pnpm-lock.yaml',
@@ -296,14 +308,15 @@ class PackWalker extends IgnoreWalker {
296
308
  if (files) {
297
309
  for (let file of files) {
298
310
  // invert the rule because these are things we want to include
299
- if (file.startsWith('/')) {
311
+ if (file.startsWith('./')) {
300
312
  file = file.slice(1)
301
- } else if (file.startsWith('./')) {
302
- file = file.slice(2)
303
313
  } else if (file.endsWith('/*')) {
304
- file = file.slice(0, -2)
314
+ file = file.slice(0, -1)
305
315
  }
306
316
  const inverse = `!${file}`
317
+
318
+ this.excludeNonRoot(file)
319
+
307
320
  try {
308
321
  // if an entry in the files array is a specific file, then we need to include it as a
309
322
  // strict requirement for this package. if it's a directory or a pattern, it's a default
@@ -312,7 +325,7 @@ class PackWalker extends IgnoreWalker {
312
325
  // if we have a file and we know that, it's strictly required
313
326
  if (stat.isFile()) {
314
327
  strict.unshift(inverse)
315
- this.requiredFiles.push(file)
328
+ this.requiredFiles.push(file.startsWith('/') ? file.slice(1) : file)
316
329
  } else if (stat.isDirectory()) {
317
330
  // otherwise, it's a default ignore, and since we got here we know it's not a pattern
318
331
  // so we include the directory contents
@@ -352,6 +365,20 @@ class PackWalker extends IgnoreWalker {
352
365
  this.injectRules(strictRules, strict, callback)
353
366
  }
354
367
 
368
+ // excludes non root files by checking if elements from the files array in
369
+ // package.json contain an ! and readme/license/licence/copying, and then
370
+ // removing readme/license/licence/copying accordingly from strict defaults
371
+ excludeNonRoot (file) {
372
+ // Find the pattern
373
+ const matchingPattern = rootOnly.find(regex => regex.test(file))
374
+
375
+ if (matchingPattern) {
376
+ // Find which index matches the pattern and remove it from allLevels
377
+ const indexToRemove = allLevels.findIndex(element => matchingPattern.test(element))
378
+ allLevels.splice(indexToRemove, 1)
379
+ }
380
+ }
381
+
355
382
  // custom method: after we've finished gathering the files for the root package, we call this
356
383
  // before emitting the 'done' event in order to gather all of the files for bundled deps
357
384
  async gatherBundles () {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "npm-packlist",
3
- "version": "7.0.4",
3
+ "version": "8.0.1",
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"
7
7
  },
8
8
  "main": "lib/index.js",
9
9
  "dependencies": {
10
- "ignore-walk": "^6.0.0"
10
+ "ignore-walk": "^6.0.4"
11
11
  },
12
12
  "author": "GitHub Inc.",
13
13
  "license": "ISC",
@@ -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.21.2",
22
22
  "mutate-fs": "^2.1.1",
23
23
  "tap": "^16.0.1"
24
24
  },
@@ -28,7 +28,7 @@
28
28
  "snap": "tap",
29
29
  "postsnap": "npm run lintfix --",
30
30
  "eslint": "eslint",
31
- "lint": "eslint \"**/*.js\"",
31
+ "lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
32
32
  "lintfix": "npm run lint -- --fix",
33
33
  "npmclilint": "npmcli-lint",
34
34
  "postlint": "template-oss-check",
@@ -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.21.2",
59
+ "publish": true
59
60
  }
60
61
  }