fix(arborist): drop stale top-level lockfile version - #9964
Open
SomSamantray wants to merge 1 commit into
Open
Conversation
Shrinkwrap.load() copies the on-disk lockfile into this.data, so a top-level version recorded by a previous lockfile survives in memory. commit() rebuilds packages[""] from the tree, but nothing cleared that top-level version: the legacy builder assigns one only when the root has a version, and lockfileVersion 4 skips that builder entirely. Clear the stale top-level version in commit() for every non-hidden lockfile, so a root package.json without a version no longer leaves the previous version behind while packages[""] is correctly rebuilt. Fixes npm#8831
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.
Removing
versionfrom the rootpackage.jsonno longer leaves the previous number at the top level ofpackage-lock.json.Before, the lockfile contradicted itself:
packages[""]was rebuilt without a version while the top-levelversionkept the old one.Shrinkwrap.load()copies the on-disk lockfile intothis.data, and nothing cleared that top-level value - the legacy builder assigns a version only when the root has one, and lockfileVersion 4 skips that builder entirely.commit()now clears it for every non-hidden lockfile.Verified: a new regression test covers removal, retention, and unchanged sibling fields across lockfileVersion 3 and 4;
npm install --package-lock-onlyreproductions pass for both lockfile versions; the full@npmcli/arboristsuite is green withshrinkwrap.jsat 100% coverage; eslint clean.Known limitation: this clears a version the manifest no longer has, but lockfileVersion 4 still does not resync a changed version. Doing that safely needs a link-root-aware contract - a blanket reassignment overwrites the
file:...value link roots legitimately record and fails the existingloadActualfixtures.Fixes #8831