Skip to content

fix(arborist): surface undeclared workspaces under the linked strategy#9657

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-undeclared-workspaces-invisible
Jun 25, 2026
Merged

fix(arborist): surface undeclared workspaces under the linked strategy#9657
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-undeclared-workspaces-invisible

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, a declared workspace that the root does not depend on is installed on disk but was invisible to npm ls --all, npm ls --workspaces, and npm query ':root > *', all of which reported an empty tree. The hoisted strategy lists every workspace.

Undeclared workspaces are intentionally not symlinked into the root node_modules under the linked strategy, so when loadActual rebuilds the actual tree (from the filesystem scan or the hidden lockfile, neither of which records a node_modules/<ws> entry) the root's workspace edges resolve to nothing and the workspaces drop out of the tree that ls and query traverse. npm ls then hid those missing edges entirely to avoid a false UNMET DEPENDENCY.

The fix adds loadActual post-processing that, for the linked strategy, synthesizes an in-memory Link at node_modules/<ws> for each undeclared workspace so its root edge resolves, matching the logical layout the regular package-lock.json already records. This is introspection-only and writes nothing to disk. A declared workspace whose root link is genuinely missing is left alone so it still reports UNMET, an existing root child of the same name is never replaced, and a workspace that was not loaded is skipped. With the edges now resolving, the workspace-skip branch that npm ls used to suppress them is removed.

References

Fixes #9618

@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 25, 2026 10:09
@manzoorwanijk manzoorwanijk requested review from a team as code owners June 25, 2026 10:09
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-undeclared-workspaces-invisible branch from 1d08ee8 to 5ab259a Compare June 25, 2026 18:36
@manzoorwanijk

manzoorwanijk commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@owlstronaut let us wrap this up. It may also need a manual backport.

EDIT: I am done for the day, please feel free to create a manual backport if needed, otherwise I will do it tomorrow.

@owlstronaut owlstronaut merged commit ae6dbeb into npm:latest Jun 25, 2026
45 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Backport to release/v11 failed.

This usually means the cherry-pick had conflicts. Please create a manual backport:

git fetch origin release/v11
git checkout -b backport/v11/9657 origin/release/v11
git cherry-pick -x ae6dbeb12a6f4b313a28c99068e34ba834ae91d1
# resolve any conflicts, then:
git push origin backport/v11/9657
Error details
Command failed: git cherry-pick -x ae6dbeb12a6f4b313a28c99068e34ba834ae91d1
error: could not apply ae6dbeb12... fix(arborist): surface undeclared workspaces under the linked strategy (#9657)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"

@owlstronaut

Copy link
Copy Markdown
Contributor

@manzoorwanijk I'll let you do it so my approval lets me merge it as well 😆

@manzoorwanijk

Copy link
Copy Markdown
Contributor Author

Here is it is #9669

owlstronaut pushed a commit that referenced this pull request Jun 26, 2026
…y (backport release/v11) (#9669)

Backport of #9657 to `release/v11`.

Under `install-strategy=linked`, a workspace the root does not depend on
is installed on disk but was invisible to `npm ls --all`, `npm ls
--workspaces`, and `npm query ':root > *'`, all of which reported an
empty tree. The hoisted strategy lists every workspace.

`loadActual` now synthesizes the missing root-to-workspace links for
undeclared workspaces in both the filesystem-scan and hidden-lockfile
paths (via a shared `#linkActualWorkspaces()` helper), so the root's
workspace edges resolve. A declared workspace whose root link is
genuinely missing is left unsynthesized so it still reports `UNMET`, and
a name already present as a root child is never replaced. With the edges
resolving, the workspace-skip branch `npm ls` used to suppress them is
removed.

Backport notes: the `.npm-extension` calls from the original commit are
omitted (that feature is not on `release/v11`), and the
`filterLinkedStrategyEdges` dev-edge guard keeps the v11 `istanbul
ignore` since v11 has no test exercising it.

## References

Fixes #9618
Backport of #9657
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: workspace-only / undeclared workspaces are invisible to npm ls and npm query

2 participants