fix(query): report logical dep location under linked strategy#9664
Merged
Conversation
In continuation of our exploration of using `install-strategy=linked` in the [Gutenberg monorepo](WordPress/gutenberg#75814), 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 (cherry picked from commit 803ba70)
owlstronaut
approved these changes
Jun 25, 2026
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.
Backport of #9656 to
release/v11.