You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ae6dbeb
Browse filesBrowse the repository at this point in the historyBrowse files
fix(arborist): surface undeclared workspaces under the linked strategy (npm#9657)
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`, 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
Fixesnpm#9618
// In linked strategy, two types of edges produce false UNMET DEPENDENCYs:
446
-
// 1. Workspace edges for undeclared workspaces: the lockfile records edges from root to ALL workspaces, but only declared workspaces are hoisted to root/node_modules in linked mode. Undeclared ones are intentionally absent.
447
-
// 2. Dev edges on non-root packages: store package link targets have no parent in the node tree, so they are treated as "top" nodes and their devDependencies are loaded as edges. Those devDeps are never installed.
// Skip dev edges for non-root packages (store packages)
465
-
if(currentDepth>0&&edge.dev){
466
-
returnfalse
467
-
}
468
-
469
-
returntrue
445
+
// In linked strategy, dev edges on non-root packages produce false UNMET DEPENDENCYs: store package link targets have no parent in the node tree, so they are treated as "top" nodes and their devDependencies are loaded as edges. Those devDeps are never installed.
446
+
// Undeclared workspaces no longer need filtering here: loadActual synthesizes their root links so their edges resolve instead of reporting missing.
// Under the linked (isolated) strategy, workspaces the root does not depend on are not symlinked into the root node_modules, so neither the on-disk scan nor the hidden lockfile gives the root's workspace edges a node_modules/<ws> link to resolve to.
226
+
// Synthesize those links from the authoritative workspaces map so npm ls and npm query surface the workspaces, matching hoisted and the logical package-lock.
// Under linked, undeclared workspaces are not symlinked into root node_modules, so loadActual must synthesize their root links for their edges to resolve (npm/cli#9618).
351
+
constfixture={
352
+
'package.json': JSON.stringify({
353
+
name: 'root',
354
+
version: '1.0.0',
355
+
workspaces: ['packages/*'],
356
+
// declared workspace is symlinked at root; undeclared one is not
0 commit comments