Skip to content

feat(pacquet): align recursive why and peers - #13205

Merged
zkochan merged 2 commits into
mainfrom
recursive-why-peers
Jul 21, 2026
Merged

zkochan merged 2 commits into
mainfrom
recursive-why-peers

Conversation

@zkochan

@zkochan zkochan commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Related to #13201.

Aligns Rust pnpm's why and peers recursive behavior with the TypeScript CLI:

  • marks both commands recursive by default inside workspaces;
  • applies recursive project selection and filters to peers instead of checking every lockfile importer;
  • uses the active project lockfile for why and peers in workspaces configured with dedicated lockfiles;
  • adds focused tests for workspace defaults, filters, and dedicated-lockfile behavior;
  • updates the transitive fast-uri resolution to 3.1.4 after the PR audit detected GHSA-v2hh-gcrm-f6hx.

TypeScript already has these command semantics, so no TypeScript implementation change is needed.

Squash Commit Body

Make Rust pnpm promote why and peers to recursive mode when they run inside a workspace. Route peer checks through the selected-project set so filters exclude unselected importers.

For workspaces with dedicated lockfiles, inspect the active project's lockfile while discovering selection candidates from the workspace root. This matches the TypeScript commands' active-lockfile behavior rather than aggregating every project lockfile.

Related to pnpm/pnpm#13201.

Refresh the transitive fast-uri lockfile resolution to 3.1.4 after the dependency audit began rejecting 3.1.3 for GHSA-v2hh-gcrm-f6hx.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Codex, GPT-5).

Copilot AI review requested due to automatic review settings July 21, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 267b4063-9401-4c35-8dbc-ad3ffa264627

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
📝 Walkthrough

Walkthrough

why and peers now run recursively by default inside workspaces. Recursive peer checks honor selected projects and lockfile modes, while recursive why uses the configured workspace root and active dedicated lockfiles. Tests cover defaults, filtering, and dedicated-lockfile behavior.

Changes

Recursive workspace commands

Layer / File(s) Summary
Command defaults and recursive why
pnpm/crates/cli/src/cli_args/cli_command.rs, pnpm/crates/cli/src/cli_args/why.rs, pnpm/crates/cli/tests/why.rs, .changeset/recursive-why-peers.md
why is promoted to recursive execution in workspaces, discovers from the configured workspace root, and supports active dedicated lockfiles.
Recursive peers lockfile selection
pnpm/crates/cli/src/cli_args/peers.rs, pnpm/crates/cli/tests/peers.rs
peers selects workspace projects, maps them to lockfile importer IDs, honors filters, and supports shared or dedicated lockfiles.
Recursive default validation
pnpm/crates/cli/src/cli_args/tests.rs
Argument parsing tests cover list, why, and peers inside and outside workspaces.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI
  participant Workspace
  participant Lockfile
  User->>CLI: run why or peers
  CLI->>Workspace: enable recursive mode and select projects
  Workspace->>Lockfile: resolve importer data
  Lockfile-->>CLI: return dependency or peer results
  CLI-->>User: display command output
Loading

Possibly related issues

Possibly related PRs

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch recursive-why-peers

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.

@greptile-apps

greptile-apps Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Reviews (2): Last reviewed commit: "chore: update fast-uri to 3.1.4" | Re-trigger Greptile

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Align why/peers recursive defaults and workspace selection with pnpm CLI

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Make pnpm why and pnpm peers recursive-by-default when executed inside a workspace.
• Route recursive peers through the workspace project-selection/filter pipeline instead of
 scanning all importers.
• In dedicated-lockfile workspaces, use the active project’s lockfile for why/peers and add
 regression tests.
Diagram

graph TD
  A["CLI args"] --> B["Workspace detect"] --> C["Promote recursive"] --> D["Project selection"] --> E["Lockfile resolve"] --> F["why/peers execution"]
  subgraph Legend
    direction LR
    _cli["CLI"] ~~~ _logic["Selection logic"] ~~~ _lf[("Lockfile")]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Keep `peers` scanning all lockfile importers
  • ➕ Simpler implementation: no dependency on recursive project-selection utilities
  • ➕ Covers every importer present in the lockfile regardless of workspace filters
  • ➖ Breaks parity with TypeScript pnpm semantics for --filter
  • ➖ Work can be unnecessarily large in big workspaces; includes unselected projects
2. Build a unified 'active lockfile' abstraction for inspection commands
  • ➕ Centralizes shared-vs-dedicated lockfile resolution across why, peers, and similar commands
  • ➕ Reduces the chance of future divergence across commands
  • ➖ Larger refactor than needed for this behavior alignment
  • ➖ Higher review and regression risk compared to targeted fixes

Recommendation: The PR’s approach is the right tradeoff: it reuses existing workspace discovery/selection (discover_workspace_projects + select_recursive_projects) to make peers honor filters, and it aligns lockfile selection with pnpm by using the active project’s lockfile when sharedWorkspaceLockfile=false. A broader lockfile-resolution abstraction could be worthwhile later, but would be over-scoped for this parity fix.

Files changed (7) +165 / -70

Enhancement (4) +44 / -36
recursive-why-peers.mdAdd release note for recursive 'why'/'peers' workspace behavior +5/-0

Add release note for recursive 'why'/'peers' workspace behavior

• Introduces a minor changeset for 'pacquet' describing that 'why' and 'peers' become recursive by default in workspaces, that 'peers' honors workspace filters, and that 'why' uses the active dedicated lockfile when applicable.

.changeset/recursive-why-peers.md

cli_command.rsMark 'why' and 'peers' as recursive-by-default commands +4/-1

Mark 'why' and 'peers' as recursive-by-default commands

• Extends the 'recursive_by_default()' classification to include 'CliCommand::Why' and 'CliCommand::Peers', so 'promote_recursive_by_default()' will enable '-r' automatically inside workspaces.

pnpm/crates/cli/src/cli_args/cli_command.rs

peers.rsMake recursive 'peers' use selected workspace projects and active lockfile +32/-23

Make recursive 'peers' use selected workspace projects and active lockfile

• Adjusts lockfile directory selection to use the workspace root only for shared lockfiles and the active project dir for dedicated lockfiles. For recursive runs, discovers workspace projects and applies the standard recursive selection/filters, then checks peer issues only for importers corresponding to the selected project dirs.

pnpm/crates/cli/src/cli_args/peers.rs

why.rsAllow recursive 'why' with dedicated lockfiles by using workspace-root discovery +3/-12

Allow recursive 'why' with dedicated lockfiles by using workspace-root discovery

• Removes the previous guard that rejected recursive 'why' when 'sharedWorkspaceLockfile=false'. Workspace project discovery now uses the workspace root (when available) while keeping lockfile access tied to the active project via 'state.lockfile_dir()'.

pnpm/crates/cli/src/cli_args/why.rs

Tests (3) +121 / -34
tests.rsExpand CLI-args tests for recursive-by-default commands +26/-22

Expand CLI-args tests for recursive-by-default commands

• Updates tests to assert that 'list', 'why', and 'peers' are promoted to recursive mode inside a workspace and remain non-recursive outside one.

pnpm/crates/cli/src/cli_args/tests.rs

peers.rsAdd integration tests for recursive 'peers' defaults, filters, and dedicated lockfiles +76/-0

Add integration tests for recursive 'peers' defaults, filters, and dedicated lockfiles

• Adds tests verifying that 'peers' is recursive by default in workspaces and respects '--filter' by limiting output to selected importers. Adds a dedicated-lockfile test ensuring the active project’s lockfile is used and yields importer key '.' when run from a workspace member.

pnpm/crates/cli/tests/peers.rs

why.rsUpdate 'why' integration tests for default recursion and dedicated lockfiles +19/-12

Update 'why' integration tests for default recursion and dedicated lockfiles

• Replaces the prior failure expectation for dedicated-lockfile recursion with a success case verifying output comes from the active project. Updates the workspace test to assert 'why' is recursive by default (no explicit '-r') and includes sibling importer dependencies.

pnpm/crates/cli/tests/why.rs

Copilot AI review requested due to automatic review settings July 21, 2026 22:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.00     12.5±0.49ms    29.9 MB/sec    1.00     12.5±0.36ms    30.0 MB/sec
packument/parse                1.28     48.1±2.82µs  1378.5 MB/sec    1.00     37.7±0.29µs  1760.1 MB/sec
tarball/download_dependency    1.00      2.8±0.39ms  1543.6 KB/sec    1.03      2.9±0.25ms  1493.8 KB/sec

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Why scans workspace unnecessarily 🐞 Bug ➹ Performance
Description
In dedicated-lockfile workspaces (sharedWorkspaceLockfile=false), recursive commands like why
(and now peers) perform full workspace project discovery and filtering even though the active
dedicated lockfile typically only matches the current project importer, causing most discovered
projects to be discarded. When there are no filters and/or in --lockfile-only mode, this becomes
avoidable workspace-wide globbing and manifest reading that can materially slow large workspaces and
CI without affecting results.
Code

pnpm/crates/cli/src/cli_args/why.rs[R92-97]

        let project_dirs: Vec<PathBuf> = if state.config.recursive {
-            let (projects, _) = discover_workspace_projects(&lockfile_dir)?;
+            let workspace_root = state.config.workspace_dir.as_deref().unwrap_or(&lockfile_dir);
+            let (projects, _) = discover_workspace_projects(workspace_root)?;
            select_recursive_projects(
                &projects,
                state.config,
Evidence
The recursive flow now computes project_dirs via workspace discovery from the workspace root,
which expands pnpm-workspace.yaml patterns into a filesystem glob walk and reads each discovered
project manifest; it then maps directories to importer IDs and filters them against the active
lockfile’s importers map. In dedicated-lockfile mode, that lockfile generally contains only the
active importer (often .), so most discovered projects are dropped after doing the expensive
discovery work, and in the new peers path this happens whenever recursive=true even for
--lockfile-only, making a nominally lockfile-only command require workspace filesystem scanning in
practice.

pnpm/crates/cli/src/cli_args/why.rs[76-108]
pnpm/crates/workspace/src/projects.rs[87-230]
pnpm/crates/cli/src/cli_args/deps_tree/build.rs[155-171]
pnpm/crates/cli/src/cli_args/peers.rs[78-123]
pnpm/crates/cli/src/cli_args/recursive.rs[284-315]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Recursive operation for `why` and `peers` currently triggers full workspace discovery (`discover_workspace_projects` / `find_workspace_projects` + selection/filtering) whenever `recursive=true`, even in dedicated-lockfile workspaces (`sharedWorkspaceLockfile=false`) where the active lockfile usually only contains the current project importer and even in `--lockfile-only` mode for `peers`. This causes avoidable workspace-wide glob walking and per-project manifest reads that are later discarded and can significantly slow these commands in large workspaces/CI without changing results in the common unfiltered case.

## Issue Context
Workspace discovery expands `pnpm-workspace.yaml` patterns into a filesystem glob walk (wax) and reads each discovered project manifest. After discovery, the flow maps discovered project directories to importer IDs and filters them against the active lockfile’s `importers` map; in dedicated-lockfile mode this typically retains only the active importer (often `.`), so most work is wasted. Additionally, the new `peers` flow performs workspace discovery when `recursive=true` even for `pnpm peers --lockfile-only`, so the command is no longer effectively lockfile-only.

## Fix Focus Areas
- pnpm/crates/cli/src/cli_args/why.rs[76-108]
- pnpm/crates/cli/src/cli_args/deps_tree/build.rs[155-171]
- pnpm/crates/workspace/src/projects.rs[87-230]
- pnpm/crates/cli/src/cli_args/peers.rs[78-123]
- pnpm/crates/cli/src/cli_args/recursive.rs[284-315]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit ff81510 into main Jul 21, 2026
35 checks passed
@zkochan
zkochan deleted the recursive-why-peers branch July 21, 2026 22:43
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.46154% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.92%. Comparing base (031fafd) to head (690e698).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/cli/src/cli_args/peers.rs 86.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13205      +/-   ##
==========================================
+ Coverage   86.80%   86.92%   +0.12%     
==========================================
  Files         525      525              
  Lines       89206    89207       +1     
==========================================
+ Hits        77437    77547     +110     
+ Misses      11769    11660     -109     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants