Skip to content

feat(napi): add allowUnusedPatches install option - #13677

Merged
zkochan merged 3 commits into
mainfrom
napi-patch
Aug 6, 2026
Merged

zkochan merged 3 commits into
mainfrom
napi-patch

Conversation

@zkochan

@zkochan zkochan commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Exposes allowUnusedPatches as 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 with
allowUnusedPatches in pnpm-workspace.yaml, but the Node API accepted
patchedDependencies only — an embedder that ships its own patches had no way
to reach the setting.

This blocks teambit/bit#10572,
which ships a Bit-owned patch for `@teambit/react.react-env`'s phantom
tsconfig dependency under the global virtual store. The phantom dependency
only 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 workspace
that resolves 2.x then matches no key and fails the install. allowUnusedPatches
is what makes a version-ranged, embedder-supplied patch safe to ship.

Related to teambit/bit#10572.

Squash Commit Body

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.

Threads the flag through InstallOptions -> ConfigOverlay ->
Config::allow_unused_patches, which the fresh-lockfile path already reads
when it calls verify_patches. No engine-side change is needed; this is
purely the missing binding surface.

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.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.

    N/A — @pnpm/napi is the Rust engine's Node binding; it has no
    TypeScript counterpart. The setting itself already exists in both stacks.
  • 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.

    allow_unused_patches_downgrades_an_unmatched_patch_to_a_warning runs a
    real install with an unmatched patch key: it asserts ERR_PNPM_UNUSED_PATCH
    without the option and success with it.
  • Updated the documentation if needed.

    pnpm/npm/napi/index.d.ts documents the new option.

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


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Added an allowUnusedPatches install option.
    • Unmatched patched dependencies can now generate a warning instead of causing installation to fail when enabled.
  • Bug Fixes

    • Preserved the default error behavior for unused patches when the option is not enabled.
  • Tests

    • Added coverage for failing and warning-based handling of unmatched patches.
    • Verified the new option is correctly applied during installation.

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.
Copilot AI lite review requested due to automatic review settings August 6, 2026 08:15

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 Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ceba39e-14c0-4983-9a2a-5bda615abbc1

📥 Commits

Reviewing files that changed from the base of the PR and between 51041e7 and f3f49a8.

📒 Files selected for processing (1)
  • pnpm/crates/napi/src/install/tests.rs

📝 Walkthrough

Walkthrough

The NAPI install API adds an optional allowUnusedPatches setting. The option flows into resolved configuration and changes unmatched patch handling from ERR_PNPM_UNUSED_PATCH failure to a warning. Tests cover both behaviors.

Changes

Unused patch handling

Layer / File(s) Summary
NAPI option and configuration wiring
pnpm/crates/napi/src/install.rs, pnpm/crates/napi/src/config.rs, pnpm/npm/napi/index.d.ts, .changeset/napi-allow-unused-patches.md
The install API and TypeScript declarations expose the new option. The option is forwarded through ConfigOverlay into resolved configuration. The changeset documents the release.
Unmatched patch behavior validation
pnpm/crates/napi/src/install/tests.rs
Tests verify that unmatched patches fail by default and complete with a warning when the option is enabled.

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
Loading

Possibly related PRs

  • pnpm/pnpm#13139: The main PR directly extends the same allow_unused_patches configuration and install behavior.
  • pnpm/pnpm#13488: Both PRs modify NAPI install behavior and install tests.
  • pnpm/pnpm#13489: Both PRs add an optional InstallOptions field and forward it through ConfigOverlay.

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch napi-patch

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.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

feat(napi): expose allowUnusedPatches in install options

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Expose allowUnusedPatches on @pnpm/napi InstallOptions for embedders shipping patches.
• Thread the flag through the N-API overlay into engine config (allow_unused_patches).
• Add a real-install test plus updated typings and a changeset release note.
Diagram

graph TD
  A["Embedder / Node app"] --> B["@pnpm/napi InstallOptions"] --> C["build_overlay()"] --> D["ConfigOverlay"] --> E["build_config()"] --> F["Config.allow_unused_patches"] --> G["verify_patches"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Generic config passthrough object
  • ➕ Reduces future PRs that only add another single boolean option
  • ➕ Allows embedders to access more engine settings without expanding the typed surface each time
  • ➖ Weaker type-safety/IDE discoverability vs explicit fields
  • ➖ Higher risk of exposing unstable/unsupported internal settings
2. Make unused patches non-fatal by default for the N-API
  • ➕ Simplifies embedder setup (no extra option required)
  • ➕ Avoids install failures for version-ranged patch keys out of the box
  • ➖ Behavioral change that could hide misconfigurations
  • ➖ Diverges from CLI defaults and expected strictness

Recommendation: Keep the explicit allowUnusedPatches field as implemented. It matches existing CLI semantics, preserves strict defaults, and maintains a typed, intentionally-scoped API surface while unblocking embedders that ship version-ranged patches.

Files changed (5) +80 / -0

Enhancement (2) +13 / -0
config.rsAdd allow_unused_patches to ConfigOverlay and apply to Config +7/-0

Add allow_unused_patches to ConfigOverlay and apply to Config

• Extends 'ConfigOverlay' with 'allow_unused_patches' and threads it into 'build_config()' so the engine 'Config' can be overridden from N-API install options.

pnpm/crates/napi/src/config.rs

install.rsExpose allow_unused_patches on InstallOptions and overlay mapping +6/-0

Expose allow_unused_patches on InstallOptions and overlay mapping

• Adds 'allow_unused_patches' to the N-API 'InstallOptions' struct and passes it through 'build_overlay()' into 'ConfigOverlay'.

pnpm/crates/napi/src/install.rs

Tests (1) +56 / -0
tests.rsAdd integration test for unused patch warning behavior +56/-0

Add integration test for unused patch warning behavior

• Introduces a marker patch payload and a test that asserts installs fail with 'ERR_PNPM_UNUSED_PATCH' by default, but succeed when 'allow_unused_patches' is enabled.

pnpm/crates/napi/src/install/tests.rs

Documentation (2) +11 / -0
napi-allow-unused-patches.mdAdd changeset for new allowUnusedPatches option +5/-0

Add changeset for new allowUnusedPatches option

• Adds a minor changeset for '@pnpm/napi' documenting the new 'allowUnusedPatches' install option and its effect on 'ERR_PNPM_UNUSED_PATCH'.

.changeset/napi-allow-unused-patches.md

index.d.tsDocument allowUnusedPatches in TypeScript InstallOptions +6/-0

Document allowUnusedPatches in TypeScript InstallOptions

• Updates the public 'InstallOptions' TypeScript definitions to include 'allowUnusedPatches' with documentation describing its effect and embedder use case.

pnpm/npm/napi/index.d.ts

@greptile-apps

greptile-apps Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (3): Last reviewed commit: "test(napi): pin allowUnusedPatches to th..." | Re-trigger Greptile

Comment thread pnpm/crates/napi/src/install/tests.rs Resolved
@qodo-code-review

qodo-code-review Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Informational

1. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only bumps @pnpm/napi and does not include a pnpm entry, which violates the
changeset policy requiring an explicit pnpm bump type. This can lead to inconsistent release
metadata and tooling behavior.
Code

.changeset/napi-allow-unused-patches.md[R1-3]

+---
+"@pnpm/napi": minor
+---
Relevance

● Weak

Prior reviews rejected adding pnpm bumps for Rust/@pnpm/napi-only changesets; they prefer not
bumping TS CLI unnecessarily.

PR-#13513
PR-#12996

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to include a pnpm entry with a valid bump type. The
added changeset front-matter lists only @pnpm/napi and omits pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/napi-allow-unused-patches.md[1-3]

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

## Issue description
The new changeset is missing the required `pnpm` package entry and bump type.

## Issue Context
Compliance requires every changeset to explicitly include a `pnpm` entry with a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/napi-allow-unused-patches.md[1-3]

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


Grey Divider

Context used
✅ Compliance rules (platform): 24 rules

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Previous review results

Review updated until commit f3f49a8 ⚖️ Balanced

Results up to commit 7a0c098 ⚖️ Balanced


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


Informational
1. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only bumps @pnpm/napi and does not include a pnpm entry, which violates the
changeset policy requiring an explicit pnpm bump type. This can lead to inconsistent release
metadata and tooling behavior.
Code

.changeset/napi-allow-unused-patches.md[R1-3]

+---
+"@pnpm/napi": minor
+---
Relevance

● Weak

Prior reviews rejected adding pnpm bumps for Rust/@pnpm/napi-only changesets; they prefer not
bumping TS CLI unnecessarily.

PR-#13513
PR-#12996

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to include a pnpm entry with a valid bump type. The
added changeset front-matter lists only @pnpm/napi and omits pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/napi-allow-unused-patches.md[1-3]

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

## Issue description
The new changeset is missing the required `pnpm` package entry and bump type.

## Issue Context
Compliance requires every changeset to explicitly include a `pnpm` entry with a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/napi-allow-unused-patches.md[1-3]

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


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.

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.
Copilot AI review requested due to automatic review settings August 6, 2026 08:19

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 74577d7 and 7a0c098.

📒 Files selected for processing (5)
  • .changeset/napi-allow-unused-patches.md
  • pnpm/crates/napi/src/config.rs
  • pnpm/crates/napi/src/install.rs
  • pnpm/crates/napi/src/install/tests.rs
  • pnpm/npm/napi/index.d.ts

Comment thread pnpm/crates/napi/src/install/tests.rs Resolved

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.

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.
Copilot AI review requested due to automatic review settings August 6, 2026 08:21

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.

@zkochan

zkochan commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

Re: Qodo rule 713436, "Changeset missing pnpm entry" — rejecting this one.

Adding "pnpm" here would be wrong. Per the root AGENTS.md ("Changesets for the Rust products"):

Do not add "pnpm" to a Rust-only changeset: in changesets, pnpm always means the TypeScript CLI package.

This PR is Rust-only — it changes the Node binding to the Rust engine and touches no TypeScript package. @pnpm/napi is the correct and only target; it is a versioning.fixed group with pacquet, so it bumps together with the Rust CLI on the rc lane.

Qodo itself rates the finding Weak and notes that prior reviews (#13513, #12996) rejected the same suggestion. The rule appears to match the release-note prose, which AGENTS.md requires to say pnpm rather than pacquet — so a correctly written Rust-only changeset trips it every time.


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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit f3f49a8

@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 github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     17.7±1.93ms    21.2 MB/sec    1.09     19.3±4.06ms    19.4 MB/sec
packument/parse                                  1.00     43.2±1.94µs  1536.3 MB/sec    1.08     46.7±3.95µs  1419.5 MB/sec
tarball/download_dependency                      1.00      2.9±0.49ms  1510.0 KB/sec    1.29      3.7±0.54ms  1171.0 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00   242.7±14.21ms 65.9 KElem/sec    1.23   297.9±33.58ms 53.7 KElem/sec
workspace_resolution/hoist_heavy                 1.00   402.5±37.96ms        ? ?/sec    1.01   406.6±28.35ms        ? ?/sec

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.11%. Comparing base (74577d7) to head (f3f49a8).

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

@zkochan
zkochan merged commit cba0df1 into main Aug 6, 2026
36 checks passed
@zkochan
zkochan deleted the napi-patch branch August 6, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants