Skip to content

fix(cli): read the root manifest once, and through the BOM - #13380

Merged
zkochan merged 2 commits into
mainfrom
fix-legacy-pnpm-field-manifest-read
Jul 25, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix-legacy-pnpm-field-manifest-read

Conversation

@zkochan

@zkochan zkochan commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #13359, which added the "the pnpm field in package.json is no longer read" warning to pacquet. Two things came out of that PR's review after it had already been squash-merged, so they land here instead. The feature's changeset is still pending in .changeset/pacquet-legacy-pnpm-field-warning.md, so this corrects it before it ever ships — no second release note.

The warning missed manifests that open with a UTF-8 BOM. It parsed package.json with a bare serde_json::from_slice, which fails on the BOM an editor may leave at the head of the file, and a failed parse means no warning. Every other manifest read in pacquet goes through parse_manifest / parse_manifest_bytes, which strip it, so a BOM-prefixed project got the install it asked for and none of the warning. pnpm warns:

$ pnpm install     # pacquet, before
Done in 208ms using pnpm v12.0.0-alpha.21

$ pnpm install     # pnpm 11, same manifest
[WARN] The "pnpm" field in package.json is no longer read by pnpm. The following keys were ignored: "pnpm.overrides". See https://pnpm.io/settings for the new home of each setting.

It also read the root manifest twice. The warning read and parsed package.json, then package_manager_to_sync read and parsed the same file, on every install-family dispatch.

Both followed from the helper doing its own IO, so it now takes the parsed manifest. derive_config_root_and_package_manager_to_sync reads the file once through read_manifest_json — the crate's BOM-stripping reader, which is what fixes the first problem at that site — and hands the value to the warning and to the package-manager policy alike. package_manager_to_sync no longer reads anything, which leaves it infallible and drops a Result from its signature.

The up-to-date fast path keeps a read of its own, through warn_ignored_pnpm_manifest_fields_in. It holds a parsed dir/package.json already, but the warning has to read workspaceDir ?? dir — the same directory pnpm resolves the root manifest from. Those are the same path today only because promote_recursive_by_default flips recursive whenever a workspace root is found and the fast path bails on recursive installs. Anchoring the emit to an invariant enforced in another function would mean that relaxing the promotion rule later silently starts naming a workspace package's keys, so the fast path pays for one small read on a path that already reads the lockfile, .modules.yaml, and the workspace manifest.

Verification

Against a BOM-prefixed manifest declaring pnpm.overrides, pnpm 11 and pacquet now emit the same line — on a fresh install and on the repeat that takes the fast path. reports_migrated_keys_through_a_utf8_bom pins the reader as a unit test. Each emit site reads the manifest on its own, so migrated_keys_are_reported_through_a_utf8_bom covers both through the binary: the first install goes through the pipeline's emit, the repeat through the fast path's, where it also asserts the warning still precedes Already up to date. Both fail with strip_utf8_bom returning its input unchanged.

cargo nextest run -p pacquet-cli (2258 tests), clippy, cargo doc with -D warnings, and cargo dylint are clean.

Squash Commit Body

The warning parsed `package.json` with a bare `serde_json::from_slice`,
which chokes on the UTF-8 BOM an editor may leave at the head of the
file — pnpm strips it and warns, pacquet stayed silent. It also read and
parsed the manifest a second time, immediately before
`package_manager_to_sync` read and parsed the very same file.

Both follow from the helper doing its own IO. It now takes the parsed
manifest, so `derive_config_root_and_package_manager_to_sync` reads the
file once through `read_manifest_json` (the crate's BOM-stripping
reader) and hands it to the warning and to the package-manager policy
alike. `package_manager_to_sync` no longer reads anything, which leaves
it infallible.

The up-to-date fast path keeps its own read, one directory removed from
the manifest it already holds, and goes through the same reader via
`warn_ignored_pnpm_manifest_fields_in`: the two paths coincide only by
an invariant that lives in another function.

Follow-up to pnpm/pnpm#13359, whose changeset is still pending, so the
fix ships with the feature.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    (TypeScript already strips the BOM and warns; this is the pacquet side.)
  • 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.
    (The feature's changeset from feat(cli): warn about install settings left under package.json's pnpm field #13359 is still unreleased and covers this.)
  • Added or updated tests.
  • Updated the documentation if needed.

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

  • Bug Fixes

    • Improved handling of legacy pnpm settings in package.json, ensuring migrated-field warnings are emitted consistently, including when installs finish via the “already up to date” path.
    • Enhanced manifest parsing so warnings are still shown correctly with UTF-8 BOMs and tolerate malformed or non-object pnpm fields.
  • Tests

    • Added a regression test for UTF-8 BOM behavior.
    • Updated and expanded install coverage to include workspace and lockfile-only scenarios.

The warning parsed `package.json` with a bare `serde_json::from_slice`,
which chokes on the UTF-8 BOM an editor may leave at the head of the
file — pnpm strips it and warns, pacquet stayed silent. It also read and
parsed the manifest a second time, immediately before
`package_manager_to_sync` read and parsed the very same file.

Both follow from the helper doing its own IO. It now takes the parsed
manifest, so `derive_config_root_and_package_manager_to_sync` reads the
file once through `read_manifest_json` (the crate's BOM-stripping
reader) and hands it to the warning and to the package-manager policy
alike. `package_manager_to_sync` no longer reads anything, which leaves
it infallible. The up-to-date fast path keeps its own read, one
directory removed from the manifest it already holds, and goes through
the same reader via `warn_ignored_pnpm_manifest_fields_in`.

Verified against pnpm 11 on a BOM-prefixed manifest declaring
`pnpm.overrides`: both stacks now emit the same warning, on a fresh
install and on the repeat that takes the fast path.

The workspace-root test drops to `--lockfile-only`, matching its
siblings: it asserts on output, and nothing about the assertion needs
packages on disk.
Copilot AI review requested due to automatic review settings July 25, 2026 22:32

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 Jul 25, 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: ad0b931c-49c0-4328-bf88-41a76bc53868

📥 Commits

Reviewing files that changed from the base of the PR and between 74db22b and 457746e.

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

📝 Walkthrough

Walkthrough

The CLI now reads the root manifest once and passes parsed data to legacy pnpm-field warnings and package-manager synchronization. The install fast path uses a manifest-loading warning wrapper, with tests updated for BOM handling, malformed manifests, and workspace lockfile-only installs.

Changes

Manifest policy handling

Layer / File(s) Summary
Parsed manifest warning API
pnpm/crates/cli/src/cli_args/legacy_pnpm_field.rs, pnpm/crates/cli/src/cli_args/legacy_pnpm_field/tests.rs
Warning and ignored-key helpers now consume parsed manifests, while tests cover ordering, BOM-prefixed manifests, missing keys, malformed JSON, and non-object fields.
Root manifest policy integration
pnpm/crates/cli/src/cli_args/package_manager.rs, pnpm/crates/cli/src/cli_args/pipelines.rs, pnpm/crates/cli/src/cli_args/tests.rs
The pipeline reads package.json once and passes the parsed manifest to warning and package-manager synchronization logic.
Install fast-path wiring
pnpm/crates/cli/src/cli_args/install.rs, pnpm/crates/cli/tests/install.rs
The already-up-to-date path uses the directory-based warning wrapper, and install tests cover BOM warnings and workspace lockfile-only installation.

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

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13327: Provides related UTF-8 BOM parsing changes used by the warning flow.
  • pnpm/pnpm#13359: Wires related legacy-field warnings into the install fast path.
  • pnpm/pnpm#13376: Modifies related ignored package.json#pnpm warning plumbing.

Suggested labels: product: pacquet

Suggested reviewers: copilot, aqeelat

✨ 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 fix-legacy-pnpm-field-manifest-read

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

Fix CLI root manifest warning: BOM-safe read and single parse

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Read root package.json once and reuse its parsed JSON across install-family dispatch.
• Parse root manifests via BOM-stripping reader so legacy pnpm warnings always fire.
• Update unit/integration tests for BOM handling and workspace-root warning behavior.
Diagram

graph TD
  A["Install command"] --> B["derive_config_root..."] --> C["read_manifest_json"] --> D[("package.json")]
  A --> I["Up-to-date fast path"] --> C
  C --> E["warn_ignored_pnpm..."] --> G["Reporter emit"]
  C --> F["package_manager_to_sync"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Make fast path reuse already-parsed manifest only
  • ➕ Avoids the extra root-manifest read on the up-to-date path
  • ➖ Couples warning semantics to current workspace-promotion behavior (risking wrong-root warnings if rules change)
  • ➖ More plumbing: would require passing/deriving the pnpm root-manifest location into the fast-path check
2. Strip BOM locally in legacy warning parser
  • ➕ Minimal change surface (keep warning helper self-contained)
  • ➖ Duplicates BOM-handling logic already standardized in read_manifest_json/parse_manifest
  • ➖ Leaves inconsistent parsing behavior across the CLI codebase

Recommendation: Current approach is the best trade-off: it removes redundant root manifest IO on the main install-family path, fixes BOM parsing by routing through the shared manifest reader, and keeps the fast-path warning anchored to pnpm’s root-manifest resolution semantics (even at the cost of a small additional read).

Files changed (7) +64 / -46

Bug fix (3) +28 / -19
install.rsFast path warning uses BOM-safe root-manifest reader +2/-2

Fast path warning uses BOM-safe root-manifest reader

• Switches the up-to-date fast path to call 'warn_ignored_pnpm_manifest_fields_in', which reads/parses the root manifest via the shared BOM-stripping reader. This ensures the warning behavior matches the full install path.

pnpm/crates/cli/src/cli_args/install.rs

legacy_pnpm_field.rsWarning logic accepts parsed manifest and adds BOM-safe root read helper +21/-13

Warning logic accepts parsed manifest and adds BOM-safe root read helper

• Refactors 'warn_ignored_pnpm_manifest_fields' to take an optional parsed 'serde_json::Value' instead of doing its own filesystem read and JSON parse. Introduces 'warn_ignored_pnpm_manifest_fields_in'/'root_manifest' to support callers that still want a convenience wrapper while ensuring parsing goes through 'read_manifest_json' (BOM-safe).

pnpm/crates/cli/src/cli_args/legacy_pnpm_field.rs

pipelines.rsDerive package-manager policy from a single root manifest read +5/-4

Derive package-manager policy from a single root manifest read

• 'derive_config_root_and_package_manager_to_sync' now reads/parses the root 'package.json' once via 'read_manifest_json', then passes the parsed value to both the legacy warning emitter and 'package_manager_to_sync'. This removes duplicate IO and ensures BOM-safe parsing at the policy/early-warning site.

pnpm/crates/cli/src/cli_args/pipelines.rs

Refactor (1) +8 / -15
package_manager.rsMake package_manager_to_sync infallible by accepting parsed manifest +8/-15

Make package_manager_to_sync infallible by accepting parsed manifest

• Changes 'package_manager_to_sync' to take a parsed manifest and return 'Option<PackageManagerToSync>' (dropping the 'Result' and internal manifest IO). This allows callers to reuse a single root-manifest parse and simplifies error handling in policy derivation.

pnpm/crates/cli/src/cli_args/package_manager.rs

Tests (3) +28 / -12
tests.rsAdd BOM coverage and adapt tests to new manifest plumbing +22/-8

Add BOM coverage and adapt tests to new manifest plumbing

• Updates unit tests to build ignored-key lists from a parsed root manifest instead of a directory read inside the function. Adds a regression test that verifies migrated keys are detected when 'package.json' begins with a UTF-8 BOM.

pnpm/crates/cli/src/cli_args/legacy_pnpm_field/tests.rs

tests.rsUpdate package_manager_to_sync test to pass parsed manifest +4/-3

Update package_manager_to_sync test to pass parsed manifest

• Adjusts the devEngines specifier test to read the manifest via 'read_manifest_json' and call the new infallible 'package_manager_to_sync(&Value, ...)' signature.

pnpm/crates/cli/src/cli_args/tests.rs

install.rsMake workspace-root warning test lockfile-only +2/-1

Make workspace-root warning test lockfile-only

• Changes the workspace-root warning integration test to run 'install --lockfile-only', aligning it with other output-asserting tests and avoiding unnecessary on-disk package installs while still validating warning selection/output.

pnpm/crates/cli/tests/install.rs

@greptile-apps

greptile-apps Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "test(cli): cover the BOM through the CLI..." | Re-trigger Greptile

@qodo-code-review

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

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

Previous review results

Review updated until commit 457746e ⚖️ Balanced

Results up to commit 74db22b ⚖️ Balanced


No changes from previous review

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.

@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/cli/src/cli_args/legacy_pnpm_field/tests.rs`:
- Around line 32-39: Extend the BOM manifest test coverage around keys_in to
exercise the CLI warning/event, not just extraction: write a BOM-prefixed
workspace-root manifest and assert the warning is emitted in both
--lockfile-only and already-up-to-date paths, with the warning appearing before
“Already up to date”. Ensure the assertions verify actual emitted output/events
for both regressions.
🪄 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: 5df25906-46d5-449b-b2a9-09553fa513b9

📥 Commits

Reviewing files that changed from the base of the PR and between 063094d and 74db22b.

📒 Files selected for processing (7)
  • pnpm/crates/cli/src/cli_args/install.rs
  • pnpm/crates/cli/src/cli_args/legacy_pnpm_field.rs
  • pnpm/crates/cli/src/cli_args/legacy_pnpm_field/tests.rs
  • pnpm/crates/cli/src/cli_args/package_manager.rs
  • pnpm/crates/cli/src/cli_args/pipelines.rs
  • pnpm/crates/cli/src/cli_args/tests.rs
  • pnpm/crates/cli/tests/install.rs

@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.00     11.4±0.28ms    32.7 MB/sec    1.04     11.9±0.10ms    31.4 MB/sec
packument/parse                1.00     38.2±0.04µs  1734.4 MB/sec    1.00     38.4±0.07µs  1728.9 MB/sec
tarball/download_dependency    1.00      2.4±0.06ms  1813.4 KB/sec    1.00      2.4±0.06ms  1820.7 KB/sec

The unit test pins the reader, but each emit site reads the root
manifest on its own, so neither is covered by it. This one runs the
binary twice against a BOM-prefixed manifest: the first run goes through
the install pipeline's emit, the second through the up-to-date fast
path's, where it also asserts the warning still precedes "Already up to
date".

Making `strip_utf8_bom` return its input unchanged fails it.
Copilot AI review requested due to automatic review settings July 25, 2026 22:39

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.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 25, 2026
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 457746e

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

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.26%. Comparing base (d17710c) to head (457746e).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13380      +/-   ##
==========================================
+ Coverage   87.22%   87.26%   +0.04%     
==========================================
  Files         536      540       +4     
  Lines       92059    92644     +585     
==========================================
+ Hits        80297    80846     +549     
- Misses      11762    11798      +36     

☔ 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 2d6c35e into main Jul 25, 2026
35 checks passed
@zkochan
zkochan deleted the fix-legacy-pnpm-field-manifest-read branch July 25, 2026 22:47
kairosci added a commit to kairosci/pnpm that referenced this pull request Jul 27, 2026
The warning parsed `package.json` with a bare `serde_json::from_slice`,
which chokes on the UTF-8 BOM an editor may leave at the head of the
file — pnpm strips it and warns, pacquet stayed silent. It also read and
parsed the manifest a second time, immediately before
`package_manager_to_sync` read and parsed the very same file.

Both follow from the helper doing its own IO. It now takes the parsed
manifest, so `derive_config_root_and_package_manager_to_sync` reads the
file once through `read_manifest_json` (the crate's BOM-stripping
reader) and hands it to the warning and to the package-manager policy
alike. `package_manager_to_sync` no longer reads anything, which leaves
it infallible.

The up-to-date fast path keeps its own read, one directory removed from
the manifest it already holds, and goes through the same reader via
`warn_ignored_pnpm_manifest_fields_in`: the two paths coincide only by
an invariant that lives in another function.

Follow-up to pnpm#13359, whose changeset is still pending, so the
fix ships with the feature.
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