Repository navigation
feat(napi): add allowUnusedPatches install option - #13677
Conversation
pnpm fails an install when a configured patch matches no installed package (ERR_PNPM_UNUSED_PATCH). The CLI lets a workspace opt out via allowUnusedPatches in pnpm-workspace.yaml, but the binding accepted patchedDependencies only, so an embedder that ships its own patches had no way to reach the setting. Bit needs it to ship a patch keyed to a version range (`@teambit/react.react-env@1`) from its own config: workspaces that resolve 2.x match no key and would otherwise fail the install. See teambit/bit#10572.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe NAPI install API adds an optional ChangesUnused patch handling
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller as NAPI caller
participant Install as NAPI install
participant Config as Resolved Config
participant Validation as Patch validation
Caller->>Install: set allowUnusedPatches
Install->>Config: apply allow_unused_patches
Config->>Validation: allow unmatched patches
Validation-->>Caller: warning instead of ERR_PNPM_UNUSED_PATCH
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 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 Qodofeat(napi): expose allowUnusedPatches in install options
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (3): Last reviewed commit: "test(napi): pin allowUnusedPatches to th..." | Re-trigger Greptile |
Code Review by Qodo
1. Changeset missing pnpm entry
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Greptile flagged the doc comment on allow_unused_patches_downgrades_an_unmatched_patch_to_a_warning as restating what the name and assertions already say. Rename the patch fixture to WELL_FORMED_PATCH too: the borrowed MARKER_PATCH name described a marker file the test never observes, since an unmatched key is never applied — the content only has to be a valid patch on disk.
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/napi/src/install/tests.rs`:
- Around line 555-557: Update the allowUnusedPatches test around
run_install_inner to capture the existing install warning output and assert it
contains the canonical ERR_PNPM_UNUSED_PATCH warning, while preserving the
successful install assertion. Ensure the integration test covers both the error
path and the allowed-warning path as required by REVIEW_GUIDE.md.
🪄 Autofix
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: 1c98606f-da89-4dd5-99f8-fd5a6b67d45e
📒 Files selected for processing (5)
.changeset/napi-allow-unused-patches.mdpnpm/crates/napi/src/config.rspnpm/crates/napi/src/install.rspnpm/crates/napi/src/install/tests.rspnpm/npm/napi/index.d.ts
The install-level test asserted only that the install stops failing, so a binding that swallowed the UnusedPatch error instead of threading the setting would have passed it — and would have dropped the warning the engine emits in its place. Assert the resolved Config.allow_unused_patches directly, mirroring resolved_config_applies_trust_lockfile. The warning emission itself is already pinned by unused_patch_warns_when_allow_unused_patches_is_set in crates/cli/tests/patch.rs; napi's contract is that the option reaches the config the engine reads.
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
Re: Qodo rule 713436, "Changeset missing Adding
This PR is Rust-only — it changes the Node binding to the Rust engine and touches no TypeScript package. Qodo itself rates the finding Written by an agent (Claude Code, claude-opus-5). |
|
Code review by qodo was updated up to the latest commit f3f49a8 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13677 +/- ##
==========================================
+ Coverage 88.09% 88.11% +0.01%
==========================================
Files 608 608
Lines 99080 99084 +4
==========================================
+ Hits 87288 87305 +17
+ Misses 11792 11779 -13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Exposes
allowUnusedPatchesas an install option on@pnpm/napi.pnpm fails an install when a configured patch matches no installed package
(
ERR_PNPM_UNUSED_PATCH). The CLI lets a workspace opt out withallowUnusedPatchesinpnpm-workspace.yaml, but the Node API acceptedpatchedDependenciesonly — an embedder that ships its own patches had no wayto reach the setting.
This blocks teambit/bit#10572,
which ships a Bit-owned patch for
`@teambit/react.react-env`'s phantomtsconfigdependency under the global virtual store. The phantom dependencyonly exists on the package's 1.x line (2.x already inlines the config), so the
patch has to be keyed
`@teambit/react.react-env@1`— and every workspacethat resolves 2.x then matches no key and fails the install.
allowUnusedPatchesis what makes a version-ranged, embedder-supplied patch safe to ship.
Related to teambit/bit#10572.
Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.N/A —
@pnpm/napiis the Rust engine's Node binding; it has noTypeScript counterpart. The setting itself already exists in both stacks.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
allow_unused_patches_downgrades_an_unmatched_patch_to_a_warningruns areal install with an unmatched patch key: it asserts
ERR_PNPM_UNUSED_PATCHwithout the option and success with it.
pnpm/npm/napi/index.d.tsdocuments the new option.Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
New Features
allowUnusedPatchesinstall option.Bug Fixes
Tests