fix(libnpmexec): skip redundant reify for cached directory specs#9255
Merged
wraithgar merged 1 commit intonpm:latestfrom Apr 17, 2026
Merged
Conversation
Member
|
Did some spot checking on this, and the only "bug" is one that already exists, namely if you use Everything else seems to work as expected. |
wraithgar
approved these changes
Apr 17, 2026
github-actions bot
pushed a commit
that referenced
this pull request
Apr 17, 2026
`npx` unconditionally re-reifies `file:`/directory specs on every invocation, even when the package is already installed in the npx cache. This happens because `missingFromTree()` has an early return for directory specs that bypasses the cache lookup entirely. Registry packages correctly skip reify on cache hit by checking `node.package.resolved === manifest._resolved`, but directory specs never reach that check. The fix makes two changes to `missingFromTree()` in `libnpmexec/lib/index.js`: 1. The early return for directory specs is now scoped to non-npx trees (`!isNpxTree`), so the npx cache tree is actually consulted on subsequent runs. 2. Added `node.realpath === manifest._resolved` as an alternative match condition, since `file:` spec nodes in the npx cache have `undefined` for `package.resolved` but their `realpath` contains the matching absolute path. A regression test verifies that running `exec` twice with the same `file:` spec only triggers `reify` once (on the cold cache run). ## References Fixes #9251 (cherry picked from commit e9b0157)
Contributor
|
🎉 Backport to |
This was referenced Apr 17, 2026
wraithgar
pushed a commit
that referenced
this pull request
Apr 17, 2026
Backport of #9255 to `release/v11`. Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
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.
npxunconditionally re-reifiesfile:/directory specs on every invocation, even when the package is already installed in the npx cache.This happens because
missingFromTree()has an early return for directory specs that bypasses the cache lookup entirely.Registry packages correctly skip reify on cache hit by checking
node.package.resolved === manifest._resolved, but directory specs never reach that check.The fix makes two changes to
missingFromTree()inlibnpmexec/lib/index.js:!isNpxTree), so the npx cache tree is actually consulted on subsequent runs.node.realpath === manifest._resolvedas an alternative match condition, sincefile:spec nodes in the npx cache haveundefinedforpackage.resolvedbut theirrealpathcontains the matching absolute path.A regression test verifies that running
exectwice with the samefile:spec only triggersreifyonce (on the cold cache run).References
Fixes #9251