Skip to content

fix(add): add to the existing allowBuilds instead of replacing it - #13873

Merged
zkochan merged 3 commits into
pnpm:mainfrom
lazerg:fix/issue-13872-add-allow-build-merge
Aug 20, 2026
Merged

zkochan merged 3 commits into
pnpm:mainfrom
lazerg:fix/issue-13872-add-allow-build-merge

Conversation

@lazerg

@lazerg lazerg commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

pnpm add --allow-build=foo writes allowBuilds from scratch out of the names the flag carried, so anything already in pnpm-workspace.yaml is gone after the command:

$ pnpm add unrs-resolver --allow-build=unrs-resolver
$ cat pnpm-workspace.yaml
allowBuilds:
  unrs-resolver: true

$ pnpm add esbuild --allow-build=esbuild
$ cat pnpm-workspace.yaml
allowBuilds:
  esbuild: true

The next install then reports unrs-resolver as an ignored build again.

The handler built two maps. One started empty and went to writeSettings, the other started from opts.allowBuilds and went to installDeps. Only the second carried what was already on disk, which is why the install itself still ran every approved build while the file quietly lost entries. Seeding the written map the same way fixes it and makes the second map redundant. approve-builds and pnpm add -g already merge this way.

pacquet needs no counterpart: set_allow_builds upserts one entry at a time into the existing document and never rewrites the block.

Fixes #13872

Squash Commit Body

`pnpm add --allow-build` built the `allowBuilds` map it wrote to
pnpm-workspace.yaml out of the flag's names alone, dropping every entry
already there. A second map, seeded from the current settings, was built
for the install itself, so the approved builds still ran and only the
file lost entries.

Seed the written map from the current settings too, and drop the now
redundant second one. This matches `approve-builds` and `pnpm add -g`,
which already merge. pacquet upserts entries individually and was never
affected.

Fixes pnpm/pnpm#13872

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

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
    • pnpm add --allow-build now preserves existing allowBuilds entries while adding newly approved packages.
  • Bug Fixes
    • Prevented existing build permissions from being unintentionally replaced when approving additional packages.
    • Existing build approvals in pnpm-workspace.yaml remain effective after adding new package approvals.

@lazerg
lazerg requested a review from zkochan as a code owner August 12, 2026 16:48
@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 Aug 12, 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: 24ccd9ca-ca7b-43e8-aff1-dea46d81afac

📥 Commits

Reviewing files that changed from the base of the PR and between eead54f and 22af21c.

📒 Files selected for processing (3)
  • .changeset/add-allow-build-keeps-existing-entries.md
  • pnpm11/installing/commands/src/add.ts
  • pnpm11/pnpm/test/install/lifecycleScripts.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • pnpm11/pnpm/test/install/lifecycleScripts.ts
  • .changeset/add-allow-build-keeps-existing-entries.md
  • pnpm11/installing/commands/src/add.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

pnpm add --allow-build now preserves existing allowBuilds entries, adds the newly approved package, passes the merged policy to installation, and documents the change. An integration test verifies both approvals remain in pnpm-workspace.yaml.

Changes

Allow-build policy update

Layer / File(s) Summary
Merge and validate the build policy
pnpm11/installing/commands/src/add.ts, pnpm11/pnpm/test/install/lifecycleScripts.ts, .changeset/add-allow-build-keeps-existing-entries.md
The add command copies existing allowBuilds entries before adding new approvals. Installation receives the merged policy. The integration test verifies both entries remain, and the changeset documents the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 22af2

This change preserves existing allowBuilds entries when adding a new approved build, with no actionable merge-blocking risk remaining beyond normal checks and review.

Assessment against linked issues

Objective Addressed Explanation
Modify existing allowBuilds entries instead of replacing them [#13872] ✅

Suggested labels: product: pnpm@11

Suggested reviewers: zkochan

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

@greptile-apps

greptile-apps Bot commented Aug 12, 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(add): call the workspace manifest w..." | Re-trigger Greptile

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 12, 2026

@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 `@pnpm11/pnpm/test/install/lifecycleScripts.ts`:
- Line 191: Update the execPnpmSync call in the lifecycleScripts regression test
to pass { expectSuccess: true }, ensuring pnpm add failures abort the test
before manifest assertions while preserving validation of both allowBuilds
entries.
🪄 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: cca0ff57-b4e9-44de-a508-afa411c96a90

📥 Commits

Reviewing files that changed from the base of the PR and between e6f2249 and 0e18f13.

📒 Files selected for processing (3)
  • .changeset/add-allow-build-keeps-existing-entries.md
  • pnpm11/installing/commands/src/add.ts
  • pnpm11/pnpm/test/install/lifecycleScripts.ts

@greptile-apps
greptile-apps Bot dismissed their stale review August 12, 2026 17:02

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 12, 2026
greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 12, 2026
@lazerg

lazerg commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

The red windows shard fails the same way on a clean main with nothing applied: a git dependency gets recorded as git+https://github.com/kevva/is-negative.git instead of github:kevva/is-negative. The rebuilds dependencies failure on the first commit here is the same thing, with a codeload tarball URL. Neither comes from this change.

@karlhorky

Copy link
Copy Markdown
Member

@lazerg some maintainer feedback from @btea in #13872 (comment)

However, it appears that #13873 only fixed the JavaScript version and did not synchronize with the Rust version.

Can you sync this with the Rust version?

@lazerg

lazerg commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@karlhorky @btea I checked the Rust side before changing anything, and I don't think it has this bug.

On the Rust CLI, --allow-build goes through apply_allow_build in pnpm/crates/cli/src/cli_args/add.rs, which calls set_allow_builds in pnpm/crates/workspace-manifest-writer/src/lib.rs. That function upserts one key at a time into the parsed pnpm-workspace.yaml document. It never rewrites the whole allowBuilds map, so entries that are already there survive.

Tested with the Rust binary built from current main (pnpm 12.0.0-rc.6):

# pnpm-workspace.yaml before
packages:
  - "."
allowBuilds:
  esbuild: true
$ pnpm add is-positive --allow-build=unrs-resolver
# pnpm-workspace.yaml after
packages:
  - "."
allowBuilds:
  esbuild: true
  unrs-resolver: true

Two add --allow-build runs in a row also keep both entries. allow_builds_upserts_existing_entry in pnpm/crates/workspace-manifest-writer/src/tests.rs covers the same behaviour at the unit level.

The TS handler was the only one that started from an empty map, so the fix in this PR is TS only. If you tested against a Rust build and saw the entry disappear, tell me the version and the manifest you started from and I will dig in again.

lazerg and others added 3 commits August 17, 2026 14:46
The allowBuilds regression test read `pnpm-workspace.yaml` into a
variable named `modulesManifest`, which names a different file.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zkochan
zkochan force-pushed the fix/issue-13872-add-allow-build-merge branch from f435f7c to 22af21c Compare August 17, 2026 13:19
@greptile-apps
greptile-apps Bot dismissed their stale review August 17, 2026 13:19

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@karlhorky

karlhorky commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

@zkochan thanks for the commit 22af21c improving the variable name in the test!

Is this PR ready for merge now?

@zkochan
zkochan merged commit 8680ece into pnpm:main Aug 20, 2026
30 checks passed
@zkochan

zkochan commented Aug 20, 2026

Copy link
Copy Markdown
Member

@karlhorky you are a member. You can approve PRs.

zkochan added a commit to jibin7jose/pnpm that referenced this pull request Aug 20, 2026
The allowBuilds merge fix already landed on main with its own changeset,
so this one would duplicate the release note. The remaining PR content is
internal/test-only and needs no changeset.

Co-Authored-By: Claude Fable 5 <[email protected]>
zkochan added a commit that referenced this pull request Aug 20, 2026
The scalar-budget regression test built a 96 MB lockfile out of a
million importer lines, so parsing allocated a million AST nodes and
the test ran for many minutes (or timed out) instead of exercising the
one thing it guards: that a document larger than the parser's 64 MiB
default scalar budget still parses. A single 65 MiB scalar crosses the
same budget and parses in under a second.

Also drops a needless `return` in pnpm-fs's is_symlink_or_junction,
uses `.cast()` instead of `as _` for the raw handle passed to
GetFileInformationByHandle in the injected-deps syncer, and extends
the --allow-build merge test with a string-valued allowBuilds entry.

The allowBuilds fix this PR originally carried was superseded by
#13873 (Closes #13872 there).

---------

Co-authored-by: Zoltan Kochan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm add --allow-build replaces existing allowBuilds config in pnpm-workspace.yaml

3 participants