Skip to content

fix(arborist): drop stale top-level lockfile version - #9964

Open
SomSamantray wants to merge 1 commit into
npm:latestfrom
SomSamantray:fix/arborist-stale-lockfile-version
Open

fix(arborist): drop stale top-level lockfile version#9964
SomSamantray wants to merge 1 commit into
npm:latestfrom
SomSamantray:fix/arborist-stale-lockfile-version

Conversation

@SomSamantray

Copy link
Copy Markdown

Removing version from the root package.json no longer leaves the previous number at the top level of package-lock.json.

Before, the lockfile contradicted itself: packages[""] was rebuilt without a version while the top-level version kept the old one. Shrinkwrap.load() copies the on-disk lockfile into this.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-only reproductions pass for both lockfile versions; the full @npmcli/arborist suite is green with shrinkwrap.js at 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 existing loadActual fixtures.

Fixes #8831

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
@SomSamantray
SomSamantray requested a review from a team as a code owner September 12, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Incorrect (previous) version number persists in package-lock.json after removal from package.json

1 participant