Skip to content

fix(arborist): omit root dev deps in linked strategy when shared with workspaces#9081

Merged
wraithgar merged 2 commits intonpm:latestfrom
manzoorwanijk:fix/omit-dev-linked-shared-deps
Mar 9, 2026
Merged

fix(arborist): omit root dev deps in linked strategy when shared with workspaces#9081
wraithgar merged 2 commits intonpm:latestfrom
manzoorwanijk:fix/omit-dev-linked-shared-deps

Conversation

@manzoorwanijk
Copy link
Contributor

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

Summary

Fixes --omit=dev (and --omit=optional, --omit=peer) not being fully respected in the linked install strategy for monorepos.

PR #9066 added a shouldOmit() check during graph traversal in makeIdealGraph(), which works for dev deps that are only dev deps. However, it missed two cases:

  • Shared external packages: When a root devDependency is also a workspace prodDependency, the node has dev=false (reachable via prod paths), so shouldOmit() returns false. The package correctly goes into the store (the workspace needs it), but root incorrectly gets a symlink to it because #assignCommonProperties() doesn't filter by edge type.
  • Workspace dev deps: Workspaces listed in root's devDependencies are always hoisted to root's node_modules/ because #rootDeclaredDeps unconditionally includes devDependencies keys, and npm auto-creates workspace type edges (not dev edges) for all workspaces.

Changes

  1. Filter edges by type in #assignCommonProperties() for root and workspace nodes — dev, optional, and peer edges are excluded when their corresponding --omit flag is set.
  2. Exclude omitted dep types from #rootDeclaredDeps — so workspaces declared only as root devDependencies aren't hoisted when --omit=dev is set.

References

Fixes #9080

wraithgar
wraithgar previously approved these changes Mar 9, 2026
@wraithgar wraithgar merged commit 1a744b5 into npm:latest Mar 9, 2026
16 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/omit-dev-linked-shared-deps branch March 9, 2026 16:53
manzoorwanijk added a commit to manzoorwanijk/npm-cli that referenced this pull request Mar 9, 2026
wraithgar pushed a commit that referenced this pull request Mar 9, 2026
Cherry pick of:
- 5fd40b6 (#9076)
- e2c2443 (#9081)

Additional changes:

- Ported `shouldOmit` method to v10's `Node` class (exists on `latest`
but was missing on v10) with full test coverage
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.

[BUG] --omit=dev does not omit root devDependencies in linked install strategy when shared with workspace prod deps

2 participants