feat: strip patchedDependencies from the packed package.json#497
Merged
owlstronaut merged 1 commit intoJun 5, 2026
Merged
Conversation
This was referenced Jun 5, 2026
owlstronaut
pushed a commit
to npm/npm-packlist
that referenced
this pull request
Jun 5, 2026
#291) Part of native dependency patching ([npm/rfcs#862](npm/rfcs#862)). This force-excludes the patch files declared in the root package's `patchedDependencies` from the packed file list, even when they are listed in `files`. ## Why `patchedDependencies` maps a dependency selector to a project-local patch file (e.g. `"abbrev@2.0.0": "patches/abbrev@2.0.0.patch"`). Those patches are a property of the project, not something a consumer of the published package applies. Without this, publishing a patched project would ship the patch files — and, once pacote strips the `patchedDependencies` field from the tarball's `package.json`, they would be dangling, unreferenced files. Excluding them keeps the published tarball clean. ## How In `PackWalker.processPackage`, when the walker is the project root and the manifest declares `patchedDependencies`, each declared patch file path is pushed onto the strict (un-overridable) rule set, so it is excluded even if `files` lists it. Design choices: - **Exact files, not directories.** Only the declared patch files are excluded — never their directory. A dedicated `patches/` dir becomes empty and drops out naturally, but a patch that lives in a shared directory (e.g. `src/foo.patch`) does not take the rest of `src/` down with it. - **`--patches-dir` honored for free.** The location is read straight off the `patchedDependencies` values, which already encode wherever the patches were written. - **Root-only.** `patchedDependencies` is root-only state, so the block is gated to the project root and never prunes a bundled dependency's files. - **Path safety.** Absolute paths and paths that escape the package root are skipped (they are never packed anyway). - **Warns** when a `files` entry pulled a patch file in (directly or via its directory), so the override is not silent. ## References Part of - npm/rfcs#862 Related to - npm/cli#9439 - npm/pacote#497
owlstronaut
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of native dependency patching (npm/rfcs#862). When packing a
directoryspec (thenpm publish/npm packpath), this strips a top-levelpatchedDependenciesfield from thepackage.jsonwritten into the tarball.Why
patchedDependenciesdeclares project-local patches against installed dependencies. It is honored only in a root manifest, so it is meaningless to consumers of a published package and should never travel through the registry. The published packument manifest is already stripped inlibnpmpublish; this closes the other half — thepackage.jsoninside the tarball itself — sonpm pack --dry-runand the published tarball no longer carry the field. It pairs with the npm-packlist change that excludes the patch files themselves; together they guarantee a patched project publishes clean.How
DirFetcherpacks the raw on-disk files viatar.c, so the tarball'spackage.jsonis the literal file on disk — there is no manifest seam to edit. The new#tarOptions():package.json(afterprepare) via@npmcli/package-json. If it has nopatchedDependencies, returns the existing options unchanged — non-patched packs are byte-for-byte identical to before.@npmcli/package-jsonattaches;JSON.stringifyignores them), writes the stripped copy to a temp dir, and removes the temp dir if the write fails.onWriteEntryto redirect only the top-levelpackage.jsonentry'sabsoluteat the stripped copy and fix itsstat.size/nlink.onWriteEntryruns before the header and the file's hardlink check, so the override is honored; every other file is untouched.end/error, so it outlives content consumption.No behavior change for any package without
patchedDependencies.References
Part of
Related to