Skip to content

fix(cli): accept top-level --if-present and stop workspace installs scaffolding a root manifest - #12919

Merged
zkochan merged 4 commits into
pnpm:mainfrom
eagarwal-notion:fix/pacquet-top-level-if-present
Jul 11, 2026
Merged

zkochan merged 4 commits into
pnpm:mainfrom
eagarwal-notion:fix/pacquet-top-level-if-present

Conversation

@eagarwal-notion

@eagarwal-notion eagarwal-notion commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Every TS-touching pull request currently fails TS CI: the repo's package manager is the pacquet-based pnpm v12 alpha, and the PR-only test-pkgs-branch script (pn --workspace-concurrency=1 --filter=...[origin/main] --no-sort --if-present .test) needs two things that binary lacks. #12914 supplied the ...[<since>] filter selector; this PR supplies the other half — top-level --if-present — and aligns the workspace no-scaffold behavior (introduced on main by #12922 to fix the run_recursive test that had been red since #12910 landed on top of #12914) with pnpm.

  1. Top-level --if-present — pnpm accepts --if-present ahead of the script name; pacquet only declared it on run / stop / restart, so the test-pkgs-branch invocation died at argument parsing (unexpected argument '--if-present' found). It is now a top-level flag like the other run-scoped options (--resume-from, --report-summary, --no-bail), merged with the subcommands' own flag, and rejected for non-script commands. Deliberately not clap-global: a propagated global flag would collide with the subcommands' own declarations. exec also rejects it — pnpm treats --if-present as an unknown option there, and threading it through would make it a silent no-op (raised in CodeRabbit review).

  2. No manifest scaffolding anywhere inside a workspace — pnpm never creates a package.json during an install inside a workspace. feat(pacquet): port the stage command and add its -/stage endpoints to pnpr #12922 already stopped persisting the scaffold when a pnpm-workspace.yaml sits next to the missing root manifest; this PR closes the remaining parity gaps: the gate is workspace membership (config.workspace_dir), so installs in workspace member directories can't scaffold one either, and the in-memory stand-in is an empty manifest instead of the init template — pnpm add -w at a rootless workspace root persists only the added dependencies (verified against the TS CLI), not npm's init template with its failing test script. Non-workspace installs keep scaffolding, and add still persists through its explicit save.

Verified against the TS CLI on identical fixtures: pnpm --filter '...[origin/main]' test on a rootless workspace selects only the changed projects, exits 0, and leaves no package.json behind — pacquet now matches. A remaining smaller gap: pacquet still writes an empty . importer to pnpm-lock.yaml where pnpm writes none.

Note for reviewers: PR TS CI can only turn green after a pnpm v12 alpha carrying #12914 plus this change is published to next-12 and the repo's packageManager is bumped. Unrelated: under plain cargo test (not nextest), patch_state's doomed-cwd test can race any test that reads the process cwd (e.g. pack_app); nextest's process-per-test isolation hides it in CI, but the doomed-cwd behavior likely belongs behind the DI seam.

No TypeScript-side change: both fixes align pacquet with existing TS behavior.

Squash Commit Body

Accept --if-present ahead of the script name, the way pnpm's option
parser does. The repo's own test-pkgs-branch script uses that spelling,
so every PR TS CI job died at argument parsing under the pacquet-based
pnpm v12. Declared top-level like the other run-scoped options but not
clap-global (run/stop/restart declare their own --if-present), merged
with the subcommand flags, validated like --resume-from/--no-bail.
Rejected for exec like pnpm, where dispatch would drop it silently.

Never scaffold a missing manifest inside a workspace. Gate State::init's
no-scaffold path on workspace membership (config.workspace_dir) rather
than a pnpm-workspace.yaml beside the missing manifest, so installs in
workspace member directories can't scaffold a package.json either —
pnpm never creates one anywhere in a workspace. Keep an empty object as
the in-memory stand-in instead of the init template: pnpm's add at a
rootless workspace root persists a manifest holding only the added
dependencies, and the template's failing test script would otherwise
ride along on any explicit save.

Together with pnpm/pnpm#12914 this unblocks the ci:test-branch job once
a pnpm v12 alpha carrying both is released and packageManager is bumped.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added or updated tests.

Written by an agent (Claude Code, claude-fable-5).

Summary by CodeRabbit

  • New Features

    • Added top-level --if-present support for script commands, including recursive execution.
    • Missing scripts now exit successfully when --if-present is used.
  • Bug Fixes

    • Prevented workspace installs from creating an unintended root manifest when one is absent.
    • Restricted --if-present to supported command contexts with clear validation errors.

@eagarwal-notion
eagarwal-notion requested a review from zkochan as a code owner July 10, 2026 19:15
@welcome

welcome Bot commented Jul 10, 2026

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Top-level --if-present is added to CLI parsing, validated for supported commands, propagated through script dispatch, and covered by CLI and integration tests. Workspace manifest loading now avoids scaffolding a missing root manifest.

Changes

CLI compatibility and workspace behavior

Layer / File(s) Summary
Top-level if-present parsing and validation
pnpm/crates/cli/src/cli_args/cli_command.rs, pnpm/crates/cli/src/cli_args/tests.rs
Adds hidden top-level --if-present parsing, command-specific validation, shared unexpected-argument errors, and tests for accepted and rejected placements.
Script dispatch propagation
pnpm/crates/cli/src/cli_args/dispatch.rs, pnpm/crates/cli/src/cli_args/dispatch_script.rs, pnpm/crates/cli/tests/run.rs, pnpm/crates/cli/tests/run_recursive.rs
Carries if_present through RunCtx and merges it into recursive, fallback, stop, and restart execution arguments; integration tests cover missing-script no-op behavior.
Workspace manifest initialization
pnpm/crates/cli/src/state.rs, pnpm/crates/cli/tests/workspace_install.rs
Passes configuration into manifest loading and returns an empty in-memory manifest when a workspace root manifest is missing, with regression coverage for install.

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

Sequence Diagram(s)

sequenceDiagram
  participant CliArgs
  participant RunCtx
  participant dispatch_script
  participant RunArgs
  CliArgs->>RunCtx: pass top-level if_present
  RunCtx->>dispatch_script: provide execution context
  dispatch_script->>RunArgs: merge if_present
  RunArgs->>dispatch_script: execute script command
Loading

Possibly related PRs

  • pnpm/pnpm#12093: Covers related recursive --if-present no-script success behavior.
  • pnpm/pnpm#12543: Modifies stop and restart argument handling for --if-present.
  • pnpm/pnpm#12910: Overlaps with the workspace manifest-loading path in state.rs.

Suggested labels: product: pacquet, product: pnpm@11

Suggested reviewers: zkochan, qodo-code-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.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pnpm/crates/cli/src/cli_args/cli_command.rs (1)

210-239: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject --if-present for exec, or thread it through to the executor — this validator currently accepts pnpm --if-present exec ..., but dispatch_script::exec drops ctx.if_present and ExecArgs has no corresponding field, so the flag becomes a silent no-op.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/cli/src/cli_args/cli_command.rs` around lines 210 - 239, Reject
--if-present for the exec command, or explicitly propagate it through
dispatch_script::exec by adding the necessary ExecArgs field and executor
handling. Update validate_if_present_top_level_option and related validation so
the flag cannot be silently ignored, while preserving its existing support for
restart and valid commands.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pnpm/crates/cli/src/cli_args/cli_command.rs`:
- Around line 210-239: Reject --if-present for the exec command, or explicitly
propagate it through dispatch_script::exec by adding the necessary ExecArgs
field and executor handling. Update validate_if_present_top_level_option and
related validation so the flag cannot be silently ignored, while preserving its
existing support for restart and valid commands.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2bc85599-a7a2-4190-ab32-bdc89a560571

📥 Commits

Reviewing files that changed from the base of the PR and between 78c2245 and a136959.

📒 Files selected for processing (8)
  • pnpm/crates/cli/src/cli_args/cli_command.rs
  • pnpm/crates/cli/src/cli_args/dispatch.rs
  • pnpm/crates/cli/src/cli_args/dispatch_script.rs
  • pnpm/crates/cli/src/cli_args/tests.rs
  • pnpm/crates/cli/src/state.rs
  • pnpm/crates/cli/tests/run.rs
  • pnpm/crates/cli/tests/run_recursive.rs
  • pnpm/crates/cli/tests/workspace_install.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 10, 2026
@codecov-commenter

codecov-commenter commented Jul 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.44%. Comparing base (2b02764) to head (7c7f48f).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12919      +/-   ##
==========================================
- Coverage   85.51%   85.44%   -0.08%     
==========================================
  Files         469      474       +5     
  Lines       72988    74565    +1577     
==========================================
+ Hits        62417    63712    +1295     
- Misses      10571    10853     +282     

☔ 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.

@github-actions

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 55e0a71be415

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.033 ± 0.133 3.833 4.231 1.89 ± 0.13
pacquet@main 4.120 ± 0.225 3.890 4.668 1.93 ± 0.16
pnpr@HEAD 2.172 ± 0.142 1.981 2.367 1.02 ± 0.09
pnpr@main 2.138 ± 0.129 2.013 2.338 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.03251457044,
      "stddev": 0.132990601510945,
      "median": 4.03182646054,
      "user": 3.7901553,
      "system": 3.494241,
      "min": 3.83337024804,
      "max": 4.23097965804,
      "times": [
        4.09132451004,
        4.23097965804,
        3.9723284110400003,
        3.94980533504,
        3.91226027204,
        3.83337024804,
        4.10228126004,
        4.10035484604,
        3.9247870860400003,
        4.20765407804
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.12030257134,
      "stddev": 0.22494964101103201,
      "median": 4.07408843104,
      "user": 3.775013,
      "system": 3.4957247000000002,
      "min": 3.89040195204,
      "max": 4.66805205604,
      "times": [
        4.66805205604,
        4.277974868039999,
        4.0459333940399995,
        4.102243468039999,
        3.96478106704,
        3.89040195204,
        4.10559885904,
        4.020849505039999,
        4.18828354704,
        3.93890699704
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.1720399263400005,
      "stddev": 0.14203582578676996,
      "median": 2.14890822804,
      "user": 2.6772621,
      "system": 3.0025876000000005,
      "min": 1.98128192204,
      "max": 2.36726771404,
      "times": [
        2.21587655704,
        2.31038510204,
        2.22783455904,
        2.07935737204,
        2.36726771404,
        1.98128192204,
        2.03726378204,
        2.0592675810400003,
        2.35992477504,
        2.08193989904
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.1380563538400006,
      "stddev": 0.12888703521312725,
      "median": 2.07911452704,
      "user": 2.6453647000000005,
      "system": 3.0201519,
      "min": 2.01305482304,
      "max": 2.33798331804,
      "times": [
        2.0147085810400003,
        2.1116594870400003,
        2.33798331804,
        2.2701807510400003,
        2.04656956704,
        2.0283994240400003,
        2.0381596340400003,
        2.2446752230400002,
        2.27517273004,
        2.01305482304
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 642.3 ± 11.9 628.2 666.2 1.00
pacquet@main 661.8 ± 47.0 635.4 790.7 1.03 ± 0.08
pnpr@HEAD 715.6 ± 18.7 690.7 746.8 1.11 ± 0.04
pnpr@main 772.9 ± 21.2 737.0 802.5 1.20 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6423485445400001,
      "stddev": 0.01189424970944471,
      "median": 0.6390641475400001,
      "user": 0.37630231999999997,
      "system": 1.32910356,
      "min": 0.62815937204,
      "max": 0.6662117400400001,
      "times": [
        0.65921081504,
        0.62815937204,
        0.63925936504,
        0.63237410504,
        0.63742390004,
        0.63886893004,
        0.6662117400400001,
        0.6462222440400001,
        0.6348976270400001,
        0.6408573470400001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6618180186400001,
      "stddev": 0.04697591697018613,
      "median": 0.64631333154,
      "user": 0.39845922,
      "system": 1.3230283600000001,
      "min": 0.63535206604,
      "max": 0.7907380780400001,
      "times": [
        0.63585906804,
        0.64530129104,
        0.63623814504,
        0.66767533104,
        0.66854702404,
        0.63535206604,
        0.65335992404,
        0.6473253720400001,
        0.63778388704,
        0.7907380780400001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.7155561407400001,
      "stddev": 0.018677919430166542,
      "median": 0.7120875335400001,
      "user": 0.40645032,
      "system": 1.3718026600000002,
      "min": 0.6906613650400001,
      "max": 0.74683496204,
      "times": [
        0.74683496204,
        0.7140101360400001,
        0.71016493104,
        0.71486654804,
        0.6906613650400001,
        0.69852022104,
        0.70940019004,
        0.73808973704,
        0.69817569404,
        0.73483762304
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.7729245890400002,
      "stddev": 0.02122919368839561,
      "median": 0.7671701185400001,
      "user": 0.4177842199999999,
      "system": 1.41593496,
      "min": 0.73696183904,
      "max": 0.80252451704,
      "times": [
        0.7656756490400001,
        0.73696183904,
        0.80252451704,
        0.7556351010400001,
        0.76734730904,
        0.7830934270400001,
        0.8000920570400001,
        0.75793269904,
        0.79299036404,
        0.7669929280400001
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.218 ± 0.039 4.190 4.320 1.90 ± 0.11
pacquet@main 4.203 ± 0.045 4.143 4.281 1.90 ± 0.11
pnpr@HEAD 2.228 ± 0.110 2.044 2.367 1.00 ± 0.08
pnpr@main 2.217 ± 0.132 2.035 2.456 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.2177586246,
      "stddev": 0.03908067215367826,
      "median": 4.2054769103,
      "user": 3.7139254999999998,
      "system": 3.37621872,
      "min": 4.1899647503,
      "max": 4.3204091802999995,
      "times": [
        4.3204091802999995,
        4.2026817883,
        4.2145373133,
        4.1899647503,
        4.2082720323,
        4.1923762733,
        4.1994184873,
        4.211735357299999,
        4.2424181853,
        4.1957728783
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.2029189375,
      "stddev": 0.04469311662522019,
      "median": 4.2054980503,
      "user": 3.7119790999999998,
      "system": 3.3890107199999995,
      "min": 4.1427630763,
      "max": 4.2814316293,
      "times": [
        4.2625640393,
        4.2109439992999995,
        4.2814316293,
        4.1885422783,
        4.1427630763,
        4.1473833003,
        4.1698717643,
        4.2146931873,
        4.2098232253,
        4.2011728753
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.2279873709,
      "stddev": 0.11048702008283207,
      "median": 2.2119555668000004,
      "user": 2.4929037999999997,
      "system": 2.9320865200000004,
      "min": 2.0435997403000004,
      "max": 2.3667877213,
      "times": [
        2.3667877213,
        2.1740747893,
        2.3189304693,
        2.3510199343000004,
        2.3345607803000004,
        2.2286054053,
        2.0435997403000004,
        2.1953057283,
        2.1321286343000003,
        2.1348605063000003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 2.2170666482000003,
      "stddev": 0.13152759955190335,
      "median": 2.2268718483,
      "user": 2.4934658,
      "system": 2.90237412,
      "min": 2.0347979743000004,
      "max": 2.4560539773000003,
      "times": [
        2.2693795943,
        2.2145573773000002,
        2.2877635473000004,
        2.1211389393,
        2.3370259473000004,
        2.0347979743000004,
        2.4560539773000003,
        2.0398491473,
        2.1709136583000004,
        2.2391863193000003
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.367 ± 0.018 1.337 1.398 2.01 ± 0.06
pacquet@main 1.386 ± 0.062 1.341 1.556 2.04 ± 0.11
pnpr@HEAD 0.679 ± 0.018 0.653 0.724 1.00
pnpr@main 0.692 ± 0.074 0.658 0.901 1.02 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.36729034092,
      "stddev": 0.01773090773622481,
      "median": 1.3687137051200002,
      "user": 1.3053524199999997,
      "system": 1.72872828,
      "min": 1.33666818062,
      "max": 1.3983222376200002,
      "times": [
        1.3619408906200001,
        1.3983222376200002,
        1.37464347262,
        1.33666818062,
        1.34847791662,
        1.3838899096200001,
        1.35560629162,
        1.3759270996200001,
        1.36785644362,
        1.3695709666200002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.38622555022,
      "stddev": 0.06186215559227677,
      "median": 1.3646222516200002,
      "user": 1.3446249199999998,
      "system": 1.7115653800000001,
      "min": 1.3405064506200002,
      "max": 1.5560813526200001,
      "times": [
        1.36825589162,
        1.3606549356200002,
        1.5560813526200001,
        1.3975537106200002,
        1.36098861162,
        1.37155878962,
        1.38956744662,
        1.3581501496200001,
        1.3405064506200002,
        1.3589381636200002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.67927198782,
      "stddev": 0.018320154190912118,
      "median": 0.67705669712,
      "user": 0.33634132,
      "system": 1.30535948,
      "min": 0.6528865766199999,
      "max": 0.72434933662,
      "times": [
        0.66474099962,
        0.67863199062,
        0.67717202662,
        0.67694136762,
        0.6528865766199999,
        0.67593182862,
        0.72434933662,
        0.68331156462,
        0.67470818762,
        0.68404599962
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.69174190392,
      "stddev": 0.07388620114406251,
      "median": 0.66564351812,
      "user": 0.34911981999999997,
      "system": 1.2987139799999998,
      "min": 0.65806499362,
      "max": 0.90081714662,
      "times": [
        0.6618380766199999,
        0.67625969262,
        0.65806499362,
        0.66472516362,
        0.68266227962,
        0.67816492562,
        0.66401758462,
        0.66430730362,
        0.66656187262,
        0.90081714662
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.078 ± 0.055 3.023 3.169 4.46 ± 0.13
pacquet@main 3.037 ± 0.029 2.996 3.092 4.40 ± 0.11
pnpr@HEAD 0.697 ± 0.014 0.675 0.724 1.01 ± 0.03
pnpr@main 0.690 ± 0.016 0.667 0.721 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.07792039554,
      "stddev": 0.05473155594171144,
      "median": 3.0646285403399998,
      "user": 1.7661765199999997,
      "system": 2.03124672,
      "min": 3.02325207184,
      "max": 3.16921030984,
      "times": [
        3.16921030984,
        3.0638704618399997,
        3.03615422684,
        3.1093197928399996,
        3.02369373784,
        3.02325207184,
        3.0287625878399997,
        3.06538661884,
        3.09963297784,
        3.1599211698399996
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.03681470914,
      "stddev": 0.029383502516071212,
      "median": 3.02362425284,
      "user": 1.79880542,
      "system": 1.96459652,
      "min": 2.99586510484,
      "max": 3.09178599984,
      "times": [
        3.06142330584,
        3.05574871984,
        3.0140567198399997,
        3.0208991258399998,
        3.02248412384,
        3.02476438184,
        3.01867533684,
        2.99586510484,
        3.09178599984,
        3.0624442728399996
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.6968450945400001,
      "stddev": 0.013603034514439687,
      "median": 0.69734383734,
      "user": 0.34252112,
      "system": 1.3519156200000002,
      "min": 0.6753160758400001,
      "max": 0.72352890684,
      "times": [
        0.6907520328400001,
        0.6753160758400001,
        0.70687624784,
        0.72352890684,
        0.69745675984,
        0.69386119984,
        0.6972309148400001,
        0.70349105584,
        0.7000671138400001,
        0.67987063784
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.6904351272400001,
      "stddev": 0.016330837771050856,
      "median": 0.6918574308400001,
      "user": 0.36385892000000003,
      "system": 1.3058962199999997,
      "min": 0.66694694684,
      "max": 0.7214324078400001,
      "times": [
        0.6994875608400001,
        0.70106559984,
        0.6812865128400001,
        0.66694694684,
        0.69269116484,
        0.6671499268400001,
        0.7214324078400001,
        0.6970457388400001,
        0.6910236968400001,
        0.68622171684
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 664.4 ± 32.7 626.7 719.8 6.15 ± 0.31
pacquet@main 640.7 ± 17.8 606.0 661.9 5.93 ± 0.18
pnpr@HEAD 109.0 ± 2.8 106.7 118.4 1.01 ± 0.03
pnpr@main 108.1 ± 1.5 105.6 113.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.66440139982,
      "stddev": 0.03272731014722693,
      "median": 0.65810155362,
      "user": 0.6178261199999999,
      "system": 0.16087926000000002,
      "min": 0.62672050862,
      "max": 0.71984429762,
      "times": [
        0.65950912762,
        0.71984429762,
        0.71448696462,
        0.6874911876199999,
        0.64863034962,
        0.63094739162,
        0.62672050862,
        0.6391395466199999,
        0.66055064462,
        0.65669397962
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.64073017252,
      "stddev": 0.01778664167673489,
      "median": 0.64549448512,
      "user": 0.60764822,
      "system": 0.15385136,
      "min": 0.60604893262,
      "max": 0.66194516362,
      "times": [
        0.66194516362,
        0.6434005806199999,
        0.65885458062,
        0.64772033462,
        0.61965839262,
        0.64758838962,
        0.60604893262,
        0.65285615062,
        0.62764915362,
        0.64158004662
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.10898378057999998,
      "stddev": 0.002828660615846932,
      "median": 0.10817583162000001,
      "user": 0.02701578,
      "system": 0.020293159999999998,
      "min": 0.10668939162,
      "max": 0.11837259662,
      "times": [
        0.10684699362,
        0.10786914762000001,
        0.10811845462,
        0.10772128162,
        0.10791135762000001,
        0.10853680762000001,
        0.10722082262,
        0.10846700862,
        0.10843986562,
        0.11495856762000001,
        0.11520804962,
        0.10820618762,
        0.10817583162000001,
        0.10896388662,
        0.10826272462,
        0.11837259662,
        0.10808670462,
        0.10725353562,
        0.10792735662,
        0.10790858162,
        0.10828069562,
        0.10737283962000001,
        0.10906180962,
        0.10668939162,
        0.10873401562
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.10810385845999998,
      "stddev": 0.0014744984500667975,
      "median": 0.10779123762000001,
      "user": 0.027483899999999995,
      "system": 0.01937332,
      "min": 0.10555280062,
      "max": 0.11297504862,
      "times": [
        0.10766795162000001,
        0.10765982662000001,
        0.10738873862000001,
        0.10899660662,
        0.10733874662000001,
        0.10772322462,
        0.10734989662000001,
        0.10904488762,
        0.10776445162,
        0.10716640862,
        0.10983582762,
        0.10589047662,
        0.10852558662,
        0.11297504862,
        0.10823493162,
        0.10823387462,
        0.10656570562,
        0.10842851462,
        0.10863780562,
        0.11038364562,
        0.10555280062,
        0.10724366862000001,
        0.10780936162,
        0.10779123762000001,
        0.10838723662000001
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 6.911 ± 0.158 6.749 7.170 1.38 ± 0.04
pacquet@main 6.776 ± 0.106 6.666 7.049 1.35 ± 0.03
pnpr@HEAD 5.042 ± 0.143 4.852 5.331 1.01 ± 0.03
pnpr@main 5.007 ± 0.090 4.929 5.209 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 6.9114230299,
      "stddev": 0.15819096581319814,
      "median": 6.8585473479,
      "user": 3.9834718199999997,
      "system": 3.7995512,
      "min": 6.7488887479,
      "max": 7.1704611849,
      "times": [
        6.7884459348999995,
        7.1704611849,
        6.8883619249,
        7.1418390169,
        6.8287327709,
        6.8064140429,
        7.0604622839,
        6.7604253948999995,
        6.7488887479,
        6.9201989969
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 6.776409427899999,
      "stddev": 0.10612419742139297,
      "median": 6.7475614164,
      "user": 3.97688092,
      "system": 3.7470444,
      "min": 6.665797599899999,
      "max": 7.0490504239,
      "times": [
        6.665797599899999,
        6.7543704209,
        6.7665480499,
        7.0490504239,
        6.722813224899999,
        6.7190493829,
        6.7353257219,
        6.7637750219,
        6.7407524119,
        6.8466120209
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 5.0424711937,
      "stddev": 0.14293976575825917,
      "median": 5.0739820048999995,
      "user": 2.75242142,
      "system": 3.2699278,
      "min": 4.8521312269,
      "max": 5.3306600859,
      "times": [
        5.0956979299,
        4.966644286899999,
        4.8521312269,
        4.9212764089,
        5.0522660799,
        5.1114333729,
        5.3306600859,
        5.1016149939,
        5.1164006379,
        4.8765869139
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 5.006930432399999,
      "stddev": 0.08980922192246045,
      "median": 4.9798319859,
      "user": 2.77879812,
      "system": 3.2662682,
      "min": 4.9292493349,
      "max": 5.2085563599,
      "times": [
        4.9915426639,
        5.2085563599,
        4.9412036849,
        5.0314698209,
        5.1093661389,
        4.9681213079,
        4.9292493349,
        4.930471305899999,
        4.953085940899999,
        5.0062377659
      ]
    }
  ]
}

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12919
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
4,217.76 ms
(-1.12%)Baseline: 4,265.61 ms
5,118.74 ms
(82.40%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
3,077.92 ms
(+1.16%)Baseline: 3,042.71 ms
3,651.25 ms
(84.30%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
1,367.29 ms
(+0.14%)Baseline: 1,365.37 ms
1,638.44 ms
(83.45%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
664.40 ms
(+2.19%)Baseline: 650.18 ms
780.21 ms
(85.16%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
4,032.51 ms
(-1.83%)Baseline: 4,107.80 ms
4,929.37 ms
(81.81%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
6,911.42 ms
(-0.60%)Baseline: 6,953.40 ms
8,344.08 ms
(82.83%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
642.35 ms
(+0.38%)Baseline: 639.91 ms
767.90 ms
(83.65%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12919
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,227.99 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
696.85 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
679.27 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
108.98 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,172.04 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
5,042.47 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
715.56 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan force-pushed the fix/pacquet-top-level-if-present branch from 55e0a71 to 821e255 Compare July 10, 2026 22:54
@qodo-code-review

qodo-code-review Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Remediation recommended

1. New package.json mode 0600 🐞 Bug ⛨ Security ⭐ New
Description
When a workspace has no root package.json, State::init now returns an in-memory manifest, so
later persistence (e.g. add) creates package.json via the atomic temp-file path that starts at
0o600 and only preserves permissions when overwriting an existing file. This can produce a root
package.json unreadable to other users/tools and diverges from prior scaffolding behavior.
Code

pnpm/crates/cli/src/state.rs[R124-126]

+        if config.workspace_dir.is_some() {
+            return Ok(PackageManifest::from_value(manifest_path, serde_json::json!({})));
+        }
Evidence
The new workspace-root behavior returns a manifest that is never scaffolded to disk, so persistence
flows now go through save_and_get_written_value(). That save path uses write_atomic, which
explicitly notes the tempfile is created with 0o600 and only copies permissions when the
destination already exists; therefore a newly created package.json will keep 0o600.

pnpm/crates/cli/src/state.rs[108-126]
pnpm/crates/package-manager/src/add.rs[308-313]
pnpm/crates/package-manifest/src/lib.rs[100-119]
pnpm/crates/package-manifest/src/lib.rs[88-97]

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

### Issue description
A rootless workspace now uses an in-memory manifest (`PackageManifest::from_value`) rather than scaffolding `package.json` on disk. When a command later persists that manifest (notably `add` via `save_and_get_written_value()`), `PackageManifest::write_atomic` writes through a `NamedTempFile` that starts with mode `0o600` and *only* copies permissions from the target path if it already exists. For a brand-new `package.json`, no metadata exists to copy, so the newly created file keeps `0o600`.

This is a permissions/interop regression vs the previous behavior (which created the file via `fs::write`, inheriting the platform default/umask).

### Issue Context
This is triggered specifically by the new “in-memory manifest inside a workspace when root `package.json` is missing” flow.

### Fix Focus Areas
- pnpm/crates/package-manifest/src/lib.rs[100-119]
- pnpm/crates/cli/src/state.rs[117-126]

### Suggested fix approach
1. Adjust `PackageManifest::write_atomic` so that **when the destination path does not exist**, the temp file is created with a more standard mode (e.g. `0o666` masked by umask) instead of the tempfile default `0o600`.
  - On Unix, consider using `tempfile::Builder` with `.permissions(std::fs::Permissions::from_mode(0o666))` when creating the temp file (and keep the existing “copy permissions from target file” logic for overwrite cases).
2. Add a focused unit/integration test covering: in a rootless workspace, run a command that saves the manifest (e.g. `add`), then assert `package.json` permissions are not `0o600` on Unix (guard with `#[cfg(unix)]`).

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


2. Historical note in load_or_create_manifest ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
Newly added doc/test comments use past-regression framing (e.g., scaffolding “broke/poisoned
recursive runs”) instead of describing the current contract, invariant, and rationale in
present-tense terms. This can leave misleading or obsolete guidance as behavior and surrounding code
evolves.
Code

pnpm/crates/cli/src/state.rs[R108-115]

+/// Inside a workspace, a missing root manifest is tolerated rather
+/// than scaffolded: pnpm installs such a workspace with no root
+/// importer and never creates a `package.json` there, so the stand-in
+/// manifest stays in memory only. (Scaffolding it broke recursive
+/// runs too: the created manifest carries the default failing `test`
+/// script, and the root then joined the workspace graph as a
+/// selectable project.) Commands that save the manifest (`add`)
+/// still persist it through their explicit save.
Evidence
The cited comment text explicitly explains behavior by referencing prior negative effects
(“Scaffolding … broke/poisoned recursive runs”), which demonstrates it is documenting historical
regressions rather than the current contract or invariant being asserted; this directly conflicts
with the compliance requirement that comments describe present behavior and constraints, not past
implementations or regressions.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/cli/src/state.rs[108-115]
pnpm/crates/cli/tests/workspace_install.rs[144-148]

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

## Issue description
Some newly added inline comments (including a test comment) explain behavior using historical/past-regression framing (e.g., describing what scaffolding “broke” or “poisoned”) instead of stating the current contract/invariant and rationale in present-tense terms.

## Issue Context
Per repo compliance guidance, comments should document current behavior and constraints (what the code does now and what the test asserts), not historical implementations or regressions, because historical narratives are likely to become stale and misleading over time.

## Fix Focus Areas
- pnpm/crates/cli/src/state.rs[108-115]
- pnpm/crates/cli/tests/workspace_install.rs[144-148]

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


3. Workspace root check too broad 🐞 Bug ≡ Correctness
Description
load_or_create_manifest now returns an in-memory empty manifest whenever config.workspace_dir is
set, which is true for subdirectory invocations inside a workspace, not just the workspace root.
This can change behavior for workspace subdirs that lack package.json (e.g. pacquet test can
become a silent no-op because it runs with if_present=true, instead of scaffolding the default
init manifest).
Code

pnpm/crates/cli/src/state.rs[R127-129]

+        if config.workspace_dir.is_some() {
+            return Ok(PackageManifest::from_value(manifest_path, serde_json::json!({})));
+        }
Evidence
The new early return is controlled only by config.workspace_dir.is_some(), but config loading is
designed to set workspace_dir for subdirectory invocations (workspace yaml in ancestors), so the
new behavior applies beyond the workspace root. Skipping scaffolding changes behavior relative to
PackageManifest::create_if_needed, which writes a default init manifest including a failing test
script; pacquet test is dispatched with if_present=true, making the empty-manifest path
particularly likely to change outcomes.

pnpm/crates/cli/src/state.rs[101-132]
pnpm/crates/config/src/lib.rs[1960-1991]
pnpm/crates/config/src/workspace_yaml.rs[807-810]
pnpm/crates/package-manifest/src/lib.rs[73-86]
pnpm/crates/package-manifest/src/lib.rs[148-156]
pnpm/crates/cli/src/cli_args/dispatch_script.rs[39-41]

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

### Issue description
`load_or_create_manifest` is intended to avoid scaffolding *only the workspace root* `package.json` when it’s missing, but the current condition (`config.workspace_dir.is_some()`) applies to any directory inside a workspace whose `package.json` is missing.

This broadens the behavior beyond the documented intent and can subtly change command semantics for subdirectory invocations inside a workspace.

### Issue Context
- `Config::current` explicitly resolves a workspace dir for subdirectory invocations, so `config.workspace_dir.is_some()` is true in many more cases than “workspace root”.
- `PackageManifest::create_if_needed` scaffolds a default manifest including npm’s default failing `test` script; skipping scaffolding changes `pacquet test` behavior because it is dispatched with `if_present=true`.

### Fix Focus Areas
- pnpm/crates/cli/src/state.rs[116-130]

### Suggested fix
1. Change the workspace-only branch to trigger **only when the missing manifest path is the workspace root manifest**.
  - For example, gate on `config.workspace_dir.as_deref() == Some(project_dir)` (where `project_dir` is `manifest_path.parent()`), or an equivalent normalized/canonical comparison.
  - If the cwd is a workspace subdirectory and `package.json` is missing there, fall through to the existing behavior (`PackageManifest::create_if_needed`) or deliberately error—whichever matches intended CLI semantics.
2. Add a regression test covering a workspace with `pnpm-workspace.yaml` at the root and a *non-root* subdirectory with no `package.json`, asserting the intended behavior for `install`/`test` from that subdirectory.

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


Grey Divider

Previous review results

Review updated until commit 7c7f48f

Results up to commit 821e255


🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Historical note in load_or_create_manifest ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
Newly added doc/test comments use past-regression framing (e.g., scaffolding “broke/poisoned
recursive runs”) instead of describing the current contract, invariant, and rationale in
present-tense terms. This can leave misleading or obsolete guidance as behavior and surrounding code
evolves.
Code

pnpm/crates/cli/src/state.rs[R108-115]

+/// Inside a workspace, a missing root manifest is tolerated rather
+/// than scaffolded: pnpm installs such a workspace with no root
+/// importer and never creates a `package.json` there, so the stand-in
+/// manifest stays in memory only. (Scaffolding it broke recursive
+/// runs too: the created manifest carries the default failing `test`
+/// script, and the root then joined the workspace graph as a
+/// selectable project.) Commands that save the manifest (`add`)
+/// still persist it through their explicit save.
Evidence
The cited comment text explicitly explains behavior by referencing prior negative effects
(“Scaffolding … broke/poisoned recursive runs”), which demonstrates it is documenting historical
regressions rather than the current contract or invariant being asserted; this directly conflicts
with the compliance requirement that comments describe present behavior and constraints, not past
implementations or regressions.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/cli/src/state.rs[108-115]
pnpm/crates/cli/tests/workspace_install.rs[144-148]

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

## Issue description
Some newly added inline comments (including a test comment) explain behavior using historical/past-regression framing (e.g., describing what scaffolding “broke” or “poisoned”) instead of stating the current contract/invariant and rationale in present-tense terms.

## Issue Context
Per repo compliance guidance, comments should document current behavior and constraints (what the code does now and what the test asserts), not historical implementations or regressions, because historical narratives are likely to become stale and misleading over time.

## Fix Focus Areas
- pnpm/crates/cli/src/state.rs[108-115]
- pnpm/crates/cli/tests/workspace_install.rs[144-148]

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


2. Workspace root check too broad 🐞 Bug ≡ Correctness
Description
load_or_create_manifest now returns an in-memory empty manifest whenever config.workspace_dir is
set, which is true for subdirectory invocations inside a workspace, not just the workspace root.
This can change behavior for workspace subdirs that lack package.json (e.g. pacquet test can
become a silent no-op because it runs with if_present=true, instead of scaffolding the default
init manifest).
Code

pnpm/crates/cli/src/state.rs[R127-129]

+        if config.workspace_dir.is_some() {
+            return Ok(PackageManifest::from_value(manifest_path, serde_json::json!({})));
+        }
Evidence
The new early return is controlled only by config.workspace_dir.is_some(), but config loading is
designed to set workspace_dir for subdirectory invocations (workspace yaml in ancestors), so the
new behavior applies beyond the workspace root. Skipping scaffolding changes behavior relative to
PackageManifest::create_if_needed, which writes a default init manifest including a failing test
script; pacquet test is dispatched with if_present=true, making the empty-manifest path
particularly likely to change outcomes.

pnpm/crates/cli/src/state.rs[101-132]
pnpm/crates/config/src/lib.rs[1960-1991]
pnpm/crates/config/src/workspace_yaml.rs[807-810]
pnpm/crates/package-manifest/src/lib.rs[73-86]
pnpm/crates/package-manifest/src/lib.rs[148-156]
pnpm/crates/cli/src/cli_args/dispatch_script.rs[39-41]

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

### Issue description
`load_or_create_manifest` is intended to avoid scaffolding *only the workspace root* `package.json` when it’s missing, but the current condition (`config.workspace_dir.is_some()`) applies to any directory inside a workspace whose `package.json` is missing.

This broadens the behavior beyond the documented intent and can subtly change command semantics for subdirectory invocations inside a workspace.

### Issue Context
- `Config::current` explicitly resolves a workspace dir for subdirectory invocations, so `config.workspace_dir.is_some()` is true in many more cases than “workspace root”.
- `PackageManifest::create_if_needed` scaffolds a default manifest including npm’s default failing `test` script; skipping scaffolding changes `pacquet test` behavior because it is dispatched with `if_present=true`.

### Fix Focus Areas
- pnpm/crates/cli/src/state.rs[116-130]

### Suggested fix
1. Change the workspace-only branch to trigger **only when the missing manifest path is the workspace root manifest**.
  - For example, gate on `config.workspace_dir.as_deref() == Some(project_dir)` (where `project_dir` is `manifest_path.parent()`), or an equivalent normalized/canonical comparison.
  - If the cwd is a workspace subdirectory and `package.json` is missing there, fall through to the existing behavior (`PackageManifest::create_if_needed`) or deliberately error—whichever matches intended CLI semantics.
2. Add a regression test covering a workspace with `pnpm-workspace.yaml` at the root and a *non-root* subdirectory with no `package.json`, asserting the intended behavior for `install`/`test` from that subdirectory.

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


Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to 7c7f48f

Warning

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

CategorySuggestion                                                                                                                                    Impact
Possible issue
Limit root-only manifest suppression

Restrict the empty in-memory manifest substitution strictly to the workspace
root.

pnpm/crates/cli/src/state.rs [124-126]

-if config.workspace_dir.is_some() {
+if config.workspace_dir.as_deref() == Some(project_dir) {
     return Ok(PackageManifest::from_value(manifest_path, serde_json::json!({})));
 }
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion identifies a critical logic flaw introduced in the PR, ensuring that missing package.json files in workspace subdirectories are correctly handled rather than silently substituted with an empty manifest.

High
  • More

Previous suggestions

Suggestions up to commit 1c9638a
CategorySuggestion                                                                                                                                    Impact
Possible issue
Limit root-only manifest handling

Restrict the empty in-memory manifest fallback to the workspace root directory
only. Check if project_dir matches config.workspace_dir to prevent inadvertently
skipping manifest scaffolding in new workspace subdirectories.

pnpm/crates/cli/src/state.rs [124-126]

-if config.workspace_dir.is_some() {
+if config.workspace_dir.as_deref() == Some(project_dir) {
     return Ok(PackageManifest::from_value(manifest_path, serde_json::json!({})));
 }
Suggestion importance[1-10]: 9

__

Why: This suggestion correctly identifies that the new behavior would improperly apply to all missing manifests within a workspace rather than just the root manifest, and provides a precise fix to address this bug.

High
Suggestions up to commit b8651b8
CategorySuggestion                                                                                                                                    Impact
Possible issue
Restrict root-only manifest fallback

Limit the in-memory empty manifest fallback to only apply at the actual
workspace root. Compare the manifest's parent directory with
config.workspace_dir to ensure new packages in workspaces are scaffolded
correctly.

pnpm/crates/cli/src/state.rs [127-129]

-if config.workspace_dir.is_some() {
+if config.workspace_dir.as_deref() == Some(project_dir) {
     return Ok(PackageManifest::from_value(manifest_path, serde_json::json!({})));
 }
Suggestion importance[1-10]: 9

__

Why: The current implementation incorrectly suppresses manifest scaffolding for any directory within a workspace, rather than exclusively targeting the workspace root.

High
Suggestions up to commit 821e255
CategorySuggestion                                                                                                                                    Impact
Possible issue
Restrict root-only manifest skipping

Restrict the empty in-memory manifest logic to apply only to the workspace root.

pnpm/crates/cli/src/state.rs [127-129]

-if config.workspace_dir.is_some() {
+if config.workspace_dir.as_deref() == Some(project_dir) {
     return Ok(PackageManifest::from_value(manifest_path, serde_json::json!({})));
 }
Suggestion importance[1-10]: 9

__

Why: The current check disables manifest scaffolding for all directories within a workspace, not just the workspace root as intended, which breaks expected behavior when initializing new packages.

High

@eagarwal-notion
eagarwal-notion force-pushed the fix/pacquet-top-level-if-present branch from 821e255 to c66c5ef Compare July 10, 2026 23:02
zkochan added a commit to eagarwal-notion/pnpm that referenced this pull request Jul 10, 2026
The top-level --if-present validator accepted `pnpm --if-present exec`,
but exec has no if-present semantics and dispatch dropped the flag
silently. pnpm rejects the option for exec (Unknown option), so pacquet
now returns the same UnknownArgument validation error it uses for the
other non-script commands. Raised in CodeRabbit review of pnpm#12919.

Co-Authored-By: Claude Fable 5 <[email protected]>
@zkochan

zkochan commented Jul 10, 2026

Copy link
Copy Markdown
Member

The CodeRabbit review finding (top-level --if-present accepted for exec but silently dropped) is addressed in b8651b8: the validator now rejects --if-present for exec with the same UnknownArgument error used for the other non-script commands, matching the TS CLI, which fails with Unknown option: 'if-present' for pnpm --if-present exec. Covered by a new case in if_present_flag_rejects_non_script_commands.


Written by an agent (Claude Code, claude-fable-5).

pnpm's option parser accepts --if-present before the script
(`pnpm --workspace-concurrency=1 --no-sort --if-present .test`), but
pacquet's clap surface only declared it on the run/stop/restart
subcommands, so the top-level spelling failed to parse. This is the
exact shape of the repo's own test-pkgs-branch script, which every
pull-request TS CI job runs — together with the changed-packages
filter selector (pnpm#12914), this unblocks the ci:test-branch
job once a pnpm v12 alpha carrying both is released and the repo's
packageManager is bumped.

The flag is declared top-level like the other run-scoped options
(--resume-from, --report-summary, --no-bail) but deliberately not
clap-global: run/stop/restart declare their own --if-present, and a
propagated global flag would collide with theirs. Validation rejects
it for non-script commands the same way as the other run-scoped
flags, plus restart, which also runs scripts.

Co-Authored-By: Claude Fable 5 <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 1c9638a

eagarwal-notion and others added 3 commits July 11, 2026 01:22
Gate State::init's no-scaffold path on workspace membership
(config.workspace_dir) rather than a pnpm-workspace.yaml beside the
missing manifest, so installs in workspace member directories can't
scaffold a package.json either — pnpm never creates one anywhere in a
workspace. Keep an empty object as the in-memory stand-in instead of
the init template: pnpm's add at a rootless workspace root persists a
manifest holding only the added dependencies, and the template's
failing test script would otherwise ride along on any explicit save.

Co-Authored-By: Claude Fable 5 <[email protected]>
The top-level --if-present validator accepted `pnpm --if-present exec`,
but exec has no if-present semantics and dispatch dropped the flag
silently. pnpm rejects the option for exec (Unknown option), so pacquet
now returns the same UnknownArgument validation error it uses for the
other non-script commands. Raised in CodeRabbit review of pnpm#12919.

Co-Authored-By: Claude Fable 5 <[email protected]>
The scaffolding-broke-recursive-runs story lives in the commit
message; the doc comment and test keep only the current contract.
The exec case in if_present_flag_rejects_non_script_commands is
documented on validate_if_present_top_level_option.

Co-Authored-By: Claude Fable 5 <[email protected]>
@zkochan
zkochan force-pushed the fix/pacquet-top-level-if-present branch from 1c9638a to 7c7f48f Compare July 10, 2026 23:24
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 7c7f48f

@zkochan
zkochan merged commit b2b1cf6 into pnpm:main Jul 11, 2026
28 checks passed
@welcome

welcome Bot commented Jul 11, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

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