npm-packlist 11.1.0 → 11.2.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/lib/index.js +27 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -305,6 +305,7 @@ class PackWalker extends IgnoreWalker {
|
|
|
305
305
|
browser,
|
|
306
306
|
files,
|
|
307
307
|
main,
|
|
308
|
+
patchedDependencies,
|
|
308
309
|
} = this.tree.package
|
|
309
310
|
|
|
310
311
|
// rules in these arrays are inverted since they are patterns we want to _not_ ignore
|
|
@@ -394,6 +395,32 @@ class PackWalker extends IgnoreWalker {
|
|
|
394
395
|
}
|
|
395
396
|
}
|
|
396
397
|
|
|
398
|
+
// patch files declared in patchedDependencies are project-local fixes and must never ship.
|
|
399
|
+
// patchedDependencies is root-only state, so this applies only to the package being packed.
|
|
400
|
+
// each declared patch file is force-excluded even when it was added via "files".
|
|
401
|
+
// only the exact files are excluded, never their directory, so a shared dir keeps its other contents.
|
|
402
|
+
if (this.tree.isProjectRoot && patchedDependencies && typeof patchedDependencies === 'object') {
|
|
403
|
+
for (const patchPath of Object.values(patchedDependencies)) {
|
|
404
|
+
if (typeof patchPath !== 'string') {
|
|
405
|
+
continue
|
|
406
|
+
}
|
|
407
|
+
const rel = normalizePath(patchPath).replace(/^\.?\//, '').replace(/\/+$/, '')
|
|
408
|
+
// skip absolute paths or paths that escape the package root, which are never packed anyway
|
|
409
|
+
if (!rel || rel.startsWith('/') || rel === '..' || rel.startsWith('../') || rel.includes('/../')) {
|
|
410
|
+
continue
|
|
411
|
+
}
|
|
412
|
+
// warn when a "files" entry pulled the patch file in, either directly or via its directory
|
|
413
|
+
const parentGlob = `!/${normalizePath(dirname(rel))}/**`
|
|
414
|
+
if (files && (ignores.includes(`!/${rel}`) || ignores.includes(parentGlob))) {
|
|
415
|
+
log.warn(
|
|
416
|
+
'patched-dependencies',
|
|
417
|
+
`excluding "${rel}" from the package tarball: patch files in patchedDependencies must not be published`
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
strict.push(`/${rel}`)
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
397
424
|
// and now we add all of the strict rules to our synthetic file
|
|
398
425
|
this.injectRules(strictRules, strict, callback)
|
|
399
426
|
}
|