Skip to content

fix: make why --exclude-peers skip peer dependency edges#12763

Draft
DrBearZay wants to merge 1 commit into
pnpm:mainfrom
DrBearZay:codex/why-exclude-peers
Draft

fix: make why --exclude-peers skip peer dependency edges#12763
DrBearZay wants to merge 1 commit into
pnpm:mainfrom
DrBearZay:codex/why-exclude-peers

Conversation

@DrBearZay

Copy link
Copy Markdown

Summary

Fix pnpm why --exclude-peers so reverse dependency trees exclude peer dependency
edges.

pnpm why now builds a reverse dependency tree. The reverse graph was not
carrying whether an edge came from a peer dependency, and the CLI handler was not
passing excludePeerDependencies through to the dependents tree builder. As a
result, pnpm why --prod --exclude-peers could still show a package that was
only present as a resolved peer.

Changes

  • Pass excludePeerDependencies from the why command to whyForPackages and
    buildDependentsTree.
  • Preserve peer-edge information when building the reverse graph.
  • Skip peer edges while walking reverse dependents when peers are excluded.
  • Add regression coverage for peer-only and mixed direct+peer dependency paths.

Repro

Public repro repository: https://github.com/DrBearZay/pnpm-why-exclude-peers-repro

Minimal repository contents:

.
├── package.json
├── pnpm-lock.yaml
└── pnpm-workspace.yaml
{
  "name": "pnpm-why-exclude-peers-repro",
  "version": "1.0.0",
  "private": true,
  "packageManager": "pnpm@11.9.0",
  "dependencies": {
    "@electron-toolkit/utils": "4.0.0"
  },
  "devDependencies": {
    "electron": "39.7.0"
  }
}

@electron-toolkit/utils@4.0.0 declares electron as a peer dependency. The
root project provides electron@39.7.0 only from devDependencies.

The lockfile records that peer-resolved package instance like this:

'@electron-toolkit/utils@4.0.0':
  peerDependencies:
    electron: '>=13.0.0'

'@electron-toolkit/utils@4.0.0(electron@39.7.0)':
  dependencies:
    electron: 39.7.0

Since electron is only reached as a resolved peer from a production dependency,
--exclude-peers should remove it from the result.

Actual output

$ corepack pnpm@10.9.0 why electron --prod --exclude-peers

$ corepack pnpm@10.9.0 list electron --prod --depth Infinity --exclude-peers

$ corepack pnpm@11.9.0 why electron --prod --exclude-peers
electron@39.7.0
└─┬ @electron-toolkit/utils@4.0.0
  └── pnpm-why-exclude-peers-repro@1.0.0 (dependencies)

Found 1 version of electron

$ corepack pnpm@11.9.0 list electron --prod --depth Infinity --exclude-peers

pnpm@11.9.0 list --exclude-peers agrees with pnpm@10.9.0 and prints
nothing. Only pnpm@11.9.0 why --exclude-peers reports electron, so the
regression appears to be in the reverse-tree why path.

Verification

corepack pnpm@11.9.0 --filter @pnpm/deps.inspection.tree-builder compile
corepack pnpm@11.9.0 --filter @pnpm/deps.inspection.list compile
corepack pnpm@11.9.0 --filter @pnpm/deps.inspection.commands compile
corepack pnpm@11.9.0 --filter @pnpm/deps.inspection.tree-builder test -- buildDependentsTree.test.ts
node /private/tmp/verify-pnpm-why-peer.mjs

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 328f7d88-d4bc-4b6f-bf30-5f45a4a688b3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant