Repository navigation
fix(pacquet): honor --no-optional for transitive optional dependencies - #12965
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughFresh installs now skip optional lockfile snapshots when optional dependencies are disabled. Tests cover transitive optional dependency exclusion and DropAll updates that re-resolve widened dependency ranges. ChangesInstall resolution behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI test
participant Fresh lockfile installer
participant Lockfile
participant Virtual store
CLI test->>Fresh lockfile installer: install --no-optional
Fresh lockfile installer->>Lockfile: mark optional snapshots skipped
Fresh lockfile installer->>Virtual store: materialize non-optional dependencies
CLI test->>Virtual store: verify optional package is absent
CLI test->>Fresh lockfile installer: install with Optional enabled
Fresh lockfile installer->>Virtual store: restore optional package
Possibly related PRs
Suggested labels: ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
PR Summary by QodoHonor --no-optional for transitive optional deps on fresh installs
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Confidence Score: 5/5Safe to merge. The fix is a targeted, well-guarded addition to one code path, with no changes to the lockfile format or on-disk state files. The change mirrors an already-working pattern from the frozen-lockfile path and is gated behind is_full_install to avoid incorrectly dropping optionals during pacquet add. Both the CLI test and the unit test provide concrete regression coverage. TypeScript pnpm already handles this correctly, so no cross-stack change is needed. No files require special attention. Reviews (7): Last reviewed commit: "fix(pacquet): scope the --no-optional ex..." | Re-trigger Greptile |
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
Micro-Benchmark ResultsLinux |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
pnpm/crates/package-manager/src/install/tests.rs (2)
217-222: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDoc comment (
///) on a private test function.Per coding guidelines, rustdoc comments (
///) are for public API contracts, and regular comments (//) are for implementation rationale. This is a private test fn explaining rationale, not a public contract.As per coding guidelines: "Use rustdoc comments for public API contracts and regular comments for implementation rationale."
✏️ Suggested fix
-/// The napi `install` path with `update: true` — what `bit install -/// --update` reaches — must re-resolve a dependency to the highest -/// version in its range, overriding the lockfile pin. It runs through -/// `Install` with `UpdateSeedPolicy::DropAll` (not the dedicated `Update` -/// subcommand path), so this guards that the `DropAll` seed policy -/// actually drops the pin and re-resolves. +// The napi `install` path with `update: true` — what `bit install +// --update` reaches — must re-resolve a dependency to the highest +// version in its range, overriding the lockfile pin. It runs through +// `Install` with `UpdateSeedPolicy::DropAll` (not the dedicated `Update` +// subcommand path), so this guards that the `DropAll` seed policy +// actually drops the pin and re-resolves.🤖 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/package-manager/src/install/tests.rs` around lines 217 - 222, Replace the rustdoc comment above the private test function with a regular block comment, preserving the existing rationale about the napi install path, UpdateSeedPolicy::DropAll, and lockfile pin re-resolution.
217-345: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSolid regression test for
DropAllseed-policy behavior.The two-pass structure (pin exactly, widen the range, reload the lockfile, re-install with
DropAll) correctly exercises the seed-drop + reuse-scope-none path ininstall_with_fresh_lockfile.rsand should fail without the fix.Two small, optional improvements:
- Consider also asserting that the old
100.0.0slot undervirtual_store_dirno longer exists after theDropAllinstall, to confirm the stale pinned version is pruned rather than just co-existing with the new one (mirrors the pattern ininstall_prunes_surplus_virtual_store_dir).🤖 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/package-manager/src/install/tests.rs` around lines 217 - 345, Extend install_with_drop_all_seed_policy_bumps_dependency_within_range to assert that the old 100.0.0 virtual-store slot no longer exists after the DropAll install, alongside the existing 100.1.0 assertion, confirming stale pinned packages are pruned.pnpm/crates/cli/tests/install.rs (1)
56-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGood regression test for transitive optional exclusion; consider also covering the restorability claim.
This test correctly validates the core fix: the prod dependency stays installed and the transitive optional (
[email protected]) is excluded. That directly guards against both under- and over-exclusion, per the review guide's "smallest correct change" concern.The PR objective specifically calls out that excluded snapshots are "not recorded in
.modules.yaml.skipped, allowing a later install without--no-optionalto restore them" — that restorability behavior isn't exercised here. Consider adding an assertion (or a follow-up test) that inspects.modules.yamlfor the absence of the optional exclusion from the permanentskippedlist, or that a secondinstallwithout--no-optionalactually restoresis-positive.🤖 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/tests/install.rs` around lines 56 - 90, The regression test no_optional_excludes_transitive_optional_dependencies should also verify excluded optionals remain restorable. After the --no-optional install, run a subsequent install without that flag and assert [email protected] is materialized, or inspect .modules.yaml to confirm it was not permanently recorded in the skipped list; prefer the end-to-end restoration assertion.
🤖 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.
Nitpick comments:
In `@pnpm/crates/cli/tests/install.rs`:
- Around line 56-90: The regression test
no_optional_excludes_transitive_optional_dependencies should also verify
excluded optionals remain restorable. After the --no-optional install, run a
subsequent install without that flag and assert [email protected] is
materialized, or inspect .modules.yaml to confirm it was not permanently
recorded in the skipped list; prefer the end-to-end restoration assertion.
In `@pnpm/crates/package-manager/src/install/tests.rs`:
- Around line 217-222: Replace the rustdoc comment above the private test
function with a regular block comment, preserving the existing rationale about
the napi install path, UpdateSeedPolicy::DropAll, and lockfile pin
re-resolution.
- Around line 217-345: Extend
install_with_drop_all_seed_policy_bumps_dependency_within_range to assert that
the old 100.0.0 virtual-store slot no longer exists after the DropAll install,
alongside the existing 100.1.0 assertion, confirming stale pinned packages are
pruned.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b76de492-323a-41c1-b848-3bce2ea0215c
📒 Files selected for processing (3)
pnpm/crates/cli/tests/install.rspnpm/crates/package-manager/src/install/tests.rspnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
PR Code Suggestions ✨Warning
Explore these optional code suggestions:
|
||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@pnpm/crates/cli/tests/install.rs`:
- Around line 77-87: Extend the install test after the --no-optional assertions
by verifying the optional dependency snapshot remains in the lockfile and is
absent from .modules.yaml.skipped, then run a normal install and assert
virtual_store/[email protected] exists. Keep the existing assertions for
production dependency installation and initial optional-dependency exclusion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 72485ee9-114b-48bc-a3ff-5d4b384f2443
📒 Files selected for processing (3)
pnpm/crates/cli/tests/install.rspnpm/crates/package-manager/src/install/tests.rspnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
- pnpm/crates/package-manager/src/install/tests.rs
|
Code review by qodo was updated up to the latest commit 311bb95 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
|
Thanks — on the two Qodo findings:
— Claude Code (Claude Fable 5) |
|
Code review by qodo was updated up to the latest commit cc1e265 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
|
Code review by qodo was updated up to the latest commit a4eb511 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
|
Update on the earlier "Redundant no-optional host check" reply: I've reverted that perf change. As the follow-up review caught, gating the optional-installability pass on the — Claude Code (Claude Fable 5) |
A fresh install with `--no-optional` dropped only the root importer's own optionalDependencies. Transitive optionals — an `optionalDependencies` entry of a resolved package — stayed in the graph and were materialized into node_modules, so `install <pkg> --no-optional` still linked `<pkg>`'s optional deps. Mirror the frozen-lockfile path: after resolution, add every snapshot marked optional (reachable only through optional edges, already computed on the fresh lockfile) to the transient `optional_excluded` skip set when Optional is not in the requested dependency groups. They propagate through the same gate as installability skips, stay out of `.modules.yaml.skipped` (a later install without the flag brings them back), and remain in the lockfile. Co-Authored-By: Claude Fable 5 <[email protected]>
`install --update` reaches the engine as napi `install()` with `update: true`, which runs `Install` with `UpdateSeedPolicy::DropAll` rather than the dedicated `update` subcommand's `Update` path. Add a package-manager integration test that pins a dependency at 100.0.0, then re-installs with `DropAll` against a widened range and asserts it re-resolves to the highest in-range 100.1.0 — the pin is dropped and the dependency is bumped. Co-Authored-By: Claude Fable 5 <[email protected]>
…able Strengthen the transitive-optional test to prove the full contract: the excluded optional stays in the lockfile, is not recorded in .modules.yaml.skipped, and is restored by a later install without --no-optional. Co-Authored-By: Claude Fable 5 <[email protected]>
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
|
Code review by qodo was updated up to the latest commit 2f53626 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
CI status: the failing tests are unrelated to this changeEvery run of this branch fails only on the
They fail with Why this is not caused by the change:
Best guess: the two added tests do real (npm-proxied) installs, and under nextest's parallelism the extra concurrent network load tips the large Could a maintainer advise how you'd like to proceed — a re-run, or is this a known-flaky area? Happy to adjust the added tests if their network footprint is the trigger. — Claude Code (Claude Fable 5) |
The transitive-optional exclusion keyed off `dependency_groups` not containing `Optional`. That is the right signal for a full `install --no-optional`, but a partial `add` (and the package installs built on it — `dlx`, global add, and the engine install in `self_update`) passes `dependency_groups` to name the manifest group to save the added package under, not to express `--no-optional`. Those callers pass `[Prod]`, so the exclusion wrongly dropped the added package's transitive optionals — e.g. `@pnpm/exe`'s platform binary, which is an optionalDependency — breaking `pnpm with <version>`, the packageManager-pinned `--version`, and `dlx`. Thread `is_full_install` into the fresh-lockfile path and gate the exclusion on it. Full installs (including bit's napi `install`) still honor `--no-optional`; partial add-style installs keep their optionals. The existing `version`, `with`, and `dlx` integration tests cover the regression. Co-Authored-By: Claude Fable 5 <[email protected]>
Correction: the
|
|
Code review by qodo was updated up to the latest commit cfc640e |
PR Code Suggestions ✨Warning
No code suggestions found for the PR.
|
Carries the --no-optional fix (pnpm/pnpm#12965): a fresh install with --no-optional now excludes transitive optional dependencies from materialization, scoped to full installs so partial add-style installs keep their optionals. Verified: the install.e2e.ts "install --no-optional" test ("should not install optional dependencies") now passes. Co-Authored-By: Claude Fable 5 <[email protected]>
What
A fresh install with
--no-optional(includeOptionalDeps: false) only dropped the root importer's ownoptionalDependencies. A transitive optional — anoptionalDependenciesentry of a resolved package — stayed in the graph and was materialized intonode_modules. Soinstall <pkg> --no-optionalstill linked<pkg>'s optional deps.Why
The
dependency_groupsfilter excludes the Optional group when building the root importer's direct-dep set, butextract_childrenin the deps resolver descends into every resolved package'soptionalDependenciesunconditionally. The frozen-lockfile path already compensates for this (it adds everyoptionalsnapshot to the transientoptional_excludedskip set when Optional isn't requested); the fresh-resolve path did not.Fix
In
install_with_fresh_lockfile.rs, after resolution, mirror the frozen path: whenOptionalis not in the requesteddependency_groups, add everybuilt_lockfilesnapshot withoptional == truetoskipped.add_optional_excluded(key). Those snapshots:.modules.yaml.skipped, so a later install without--no-optionalbrings them back,The fresh path already re-derives
snapshot.optional(optional-only-reachable) independencies_graph_to_lockfile.rs, so the flag is available.Tests
no_optional_excludes_transitive_optional_dependencies— installs@pnpm.e2e/pkg-with-good-optional(whoseoptionalDependenciespull inis-positive) with--no-optionaland asserts the transitive optional is not materialized while the prod dep is. Verified it fails without the fix and passes with it.install_with_drop_all_seed_policy_bumps_dependency_within_rangeguarding an adjacent path:InstallwithUpdateSeedPolicy::DropAll(what napiinstall({ update: true })uses) must re-resolve within range and drop the lockfile pin. It passes on unchanged engine code — included to lock down the contract that programmaticinstall --updateconsumers depend on.cargo fmt+clippy -D warningsclean; all install/prune integration tests and the 693 package-manager unit tests pass.Context
Found while bringing Bit up on the Rust engine (
bit install --no-optionalleaked optional deps). No behavior change for installs that don't pass--no-optional/ a restricted dependency-group set.🤖 Generated with Claude Code
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by CodeRabbit
pnpm install --no-optionalso optional-only snapshots are not materialized while their entries remain in the lockfile for future optional-enabled installs.node_modulesafter--no-optional, then restored by a subsequent standard install.install({ update: true }).