Skip to content

fix(libnpmexec): skip redundant reify for cached directory specs#9256

Merged
wraithgar merged 1 commit intorelease/v11from
backport/v11/9255
Apr 17, 2026
Merged

fix(libnpmexec): skip redundant reify for cached directory specs#9256
wraithgar merged 1 commit intorelease/v11from
backport/v11/9255

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Backport of #9255 to release/v11.

`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)
@wraithgar wraithgar merged commit e200696 into release/v11 Apr 17, 2026
17 checks passed
@wraithgar wraithgar deleted the backport/v11/9255 branch April 17, 2026 17:50
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.

2 participants