Skip to content

fix(ls): suppress false UNMET DEPENDENCYs in linked strategy#9095

Merged
wraithgar merged 2 commits intonpm:latestfrom
manzoorwanijk:fix/linked-strategy/ls-false-unmet-deps
Mar 10, 2026
Merged

fix(ls): suppress false UNMET DEPENDENCYs in linked strategy#9095
wraithgar merged 2 commits intonpm:latestfrom
manzoorwanijk:fix/linked-strategy/ls-false-unmet-deps

Conversation

@manzoorwanijk
Copy link
Contributor

@manzoorwanijk manzoorwanijk commented Mar 10, 2026

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

In linked install strategy, npm ls reports two types of false UNMET DEPENDENCYs:

  1. Undeclared workspaces: The root node always creates workspace edges for all workspaces (from the workspaces field in package.json), but in linked mode only workspaces explicitly declared in dependencies are hoisted to root/node_modules/. Undeclared workspaces are intentionally absent, yet npm ls reports them as missing.

  2. devDependencies of store packages: Store package link targets (at .store/<key>/node_modules/<name>) 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, but npm ls --all reports them as UNMET DEPENDENCY.

This PR adds a filterLinkedStrategyEdges filter in ls.js that is only active when installStrategy === 'linked'. It skips workspace edges for undeclared workspaces at the root level and skips dev edges for non-root packages (store packages).

References

Fixes #9090
Fixes #9092

@manzoorwanijk manzoorwanijk requested a review from a team as a code owner March 10, 2026 15:42
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-strategy/ls-false-unmet-deps branch from a633541 to dc003fb Compare March 10, 2026 15:59
// 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.
const filterLinkedStrategyEdges = ({ node, currentDepth }) => {
const declaredDeps = currentDepth === 0
? new Set(Object.keys(Object.assign({},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach is cleaner than what we're doing with things like this.#rootDeclaredDeps in makeIdealGraph.

    this.#rootDeclaredDeps = new Set([
      ...Object.keys(rootPkg.dependencies || {}),
      ...(!omit.has('dev') ? Object.keys(rootPkg.devDependencies || {}) : []),
      ...(!omit.has('optional') ? Object.keys(rootPkg.optionalDependencies || {}) : []),
      ...(!omit.has('peer') ? Object.keys(rootPkg.peerDependencies || {}) : []),
    ])

could become

    this.#rootDeclaredDeps = new Set(Object.keys(Object.assign({},
      rootPkg.dependencies,
      (!omit.has('dev') && rootPkg.devDependencies),
      (!omit.has('optional') && rootPkg.optionalDependencies),
      (!omit.has('peer') && rootPkg.peerDependencies),
    )))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! That refactor in isolated-reifier.js would be a nice follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should I make that change here? It doesn't seem to affect the coverage, so the changes should be minimal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in #9097

@manzoorwanijk manzoorwanijk requested a review from wraithgar March 10, 2026 16:28
@wraithgar wraithgar merged commit b56986a into npm:latest Mar 10, 2026
20 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/linked-strategy/ls-false-unmet-deps branch March 10, 2026 16:40
@github-actions github-actions bot mentioned this pull request Mar 10, 2026
manzoorwanijk added a commit to manzoorwanijk/npm-cli that referenced this pull request Mar 10, 2026
wraithgar pushed a commit that referenced this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants