feat: .npm-extension transformManifest for imperative manifest repairs#9586
Open
manzoorwanijk wants to merge 8 commits into
Open
feat: .npm-extension transformManifest for imperative manifest repairs#9586manzoorwanijk wants to merge 8 commits into
.npm-extension transformManifest for imperative manifest repairs#9586manzoorwanijk wants to merge 8 commits into
Conversation
27a0b0b to
ae8e7ac
Compare
ae8e7ac to
f29b151
Compare
868067c to
64e45c5
Compare
64e45c5 to
7a92e3a
Compare
Contributor
Author
|
CC: @owlstronaut |
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.
Implements the accepted RFC npm/rfcs#903: a root-owned
.npm-extension.mjs/.npm-extension.cjsfile exportingtransformManifest(pkg, context)that imperatively repairs third-party dependency manifests before Arborist finalizes the ideal tree. It is the imperative counterpart topackageExtensions(#9496) and operates in the same pre-resolution phase, running beforepackageExtensions.Why
packageExtensionsis declarative JSON: it cannot carry comments or issue links, repeats itself across many packages, is add-only, and lives inpackage.json(so public packages cannot publish while it is present)..npm-extensioncovers the gap for advanced projects that need conditional repairs, deletion, range rewrites, repeated rules expressed as code, stale-repair guards, and a policy location outside the published manifest.What it does
.npm-extension.mjsor.npm-extension.cjs(both present is an error). Theextension-fileconfig overrides discovery with a project-local path that must resolve inside the project root and use.mjs/.cjs.transformManifest(pkg, context)— receives a deeply isolated copy of the normalized manifest;contextexposeslog,root, andextensionPoint. Must return a manifest synchronously;null/primitive/array/promise returns and throws fail the install with a.npm-extension-named error.dependencies,optionalDependencies,peerDependencies, andpeerDependenciesMetamay change (add, replace, or delete). Any other changed field (scripts,bin, …) is rejected. pacote's cached manifest is never mutated.npmExtensionHash(a format-tagged digest of the file bytes); affected entries record minimalnpmExtensionAppliedprovenance. Extension state reuses the existinglockfileVersion: 4threshold.npm install, reverting transforms that no longer apply.npm ci— never imports or executes the file; it validates the recorded hash and reifies the locked graph (which already carries the extension-influenced edges).ignore-extensiondisables import/execution;ignore-scriptsimplies it;extension-fileis honored only from project config or the command line, never from user/global/builtin sources..npm-extensionfile in a non-root workspace is ignored with a warning; only the workspace root's file is honored.npm explainannotates extension-changed edges andnpm ls(human +--json) surfaces the provenance.npm-packlistforce-excludes root.npm-extension.{mjs,cjs}from package tarballs.Companion change
Requires npm/npm-packlist#294 to exclude root
.npm-extension.{mjs,cjs}from tarballs.pacote/CLI will pick this up via a version bump once that publishes.Notes / out of scope for this PR
One item is deferred for a genuine structural reason the RFC itself flags:
file:/link:/directory sources.transformManifestapplies to fetched manifests (registry, git, remote tarball,file:tarballs) and is re-derived on the installed tree across all install strategies includinginstall-strategy=linked. It is not yet applied to local sources that createLinknodes directly and bypass the fetch phase — the RFC flags this as net-new wiring ("npm must add an analogous pre-edge-read transform path for theLinktarget"). Follow-up.References
Implements npm/rfcs#903
Builds on #9496
Companion: npm/npm-packlist#294