fix(query): report logical dep location under linked strategy by manzoorwanijk · Pull Request #9656 · npm/cli · GitHub
Skip to content

fix(query): report logical dep location under linked strategy#9656

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-query-logical-location
Jun 25, 2026
Merged

fix(query): report logical dep location under linked strategy#9656
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-query-logical-location

Conversation

@manzoorwanijk

Copy link
Copy Markdown
Contributor

In continuation of our exploration of using install-strategy=linked in the Gutenberg monorepo, which powers the WordPress Block Editor.

Under install-strategy=linked, npm query ':root > *' reported a direct dependency at its node_modules/.store/<key>/node_modules/<pkg> backing path instead of the logical node_modules/<pkg> location, diverging from the hoisted strategy.

There are two root causes.
In hasParent (query-selector-all.js), a store-backing node is isTop, has resolveParent === root, and has a top-level symlink whose parent is root, so it matched as a direct child of root through the linksIn logical-parent block that exists for workspaces.
This returned the store node alongside its logical Link.
In the query command, QuerySelectorItem read node.target.location, which for a linked dep resolves to the store node.

The fix skips store-backing nodes in the linksIn parent check, so a store node is reached only through its logical Link (matched via the edgesIn branch) rather than as a direct child of root.
The query command now reports the node's own logical location/path when the target is in the store, while workspaces and regular nodes keep the target location (for example packages/<ws>).
Deduplication now keys on the target's physical location and ranks competing representations of the same package, so a top-level placement wins over the canonical store node, which wins over an internal store symlink.
This keeps direct deps logical and transitive deps at their canonical store key for selectors such as :root *, and leaves the hoisted strategy unchanged.

References

Fixes #9617

Under install-strategy=linked, npm query reported a direct dependency at its node_modules/.store/<key>/node_modules/<pkg> backing path instead of the logical node_modules/<pkg> location. A store-backing node matched as a direct child of root in hasParent (its top-level symlink is parented at root), and the query command read node.target.location. Skip store-backing nodes in the linksIn parent check so only the logical Link matches, and report the logical link location for store-backed deps while keeping transitive deps at their canonical store key.
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-query-logical-location branch from 7aad686 to 6abcb1f Compare June 25, 2026 09:04
@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 25, 2026 09:06
@manzoorwanijk manzoorwanijk requested review from a team as code owners June 25, 2026 09:06
@owlstronaut owlstronaut merged commit 803ba70 into npm:latest Jun 25, 2026
47 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/linked-query-logical-location branch June 25, 2026 17:38
@github-actions

Copy link
Copy Markdown
Contributor

owlstronaut pushed a commit that referenced this pull request Jun 25, 2026
Backport of #9656 to `release/v11`.

Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] install-strategy=linked: npm query ':root > *' reports .store backing paths instead of logical locations

2 participants