Repository navigation
fix(cli): read the root manifest once, and through the BOM - #13380
Conversation
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.
|
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 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. ChangesManifest policy handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
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 QodoFix CLI root manifest warning: BOM-safe read and single parse
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
Confidence Score: 5/5The 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 |
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewPrevious review resultsReview updated until commit 457746e Results up to commit 74db22b
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
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/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
📒 Files selected for processing (7)
pnpm/crates/cli/src/cli_args/install.rspnpm/crates/cli/src/cli_args/legacy_pnpm_field.rspnpm/crates/cli/src/cli_args/legacy_pnpm_field/tests.rspnpm/crates/cli/src/cli_args/package_manager.rspnpm/crates/cli/src/cli_args/pipelines.rspnpm/crates/cli/src/cli_args/tests.rspnpm/crates/cli/tests/install.rs
Micro-Benchmark ResultsLinux |
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.
|
Code review by qodo was updated up to the latest commit 457746e |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
Summary
Follow-up to #13359, which added the "the
pnpmfield 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.jsonwith a bareserde_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 throughparse_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:It also read the root manifest twice. The warning read and parsed
package.json, thenpackage_manager_to_syncread 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_syncreads the file once throughread_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_syncno longer reads anything, which leaves it infallible and drops aResultfrom its signature.The up-to-date fast path keeps a read of its own, through
warn_ignored_pnpm_manifest_fields_in. It holds a parseddir/package.jsonalready, but the warning has to readworkspaceDir ?? dir— the same directory pnpm resolves the root manifest from. Those are the same path today only becausepromote_recursive_by_defaultflipsrecursivewhenever 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_bompins the reader as a unit test. Each emit site reads the manifest on its own, somigrated_keys_are_reported_through_a_utf8_bomcovers both through the binary: the firstinstallgoes through the pipeline's emit, the repeat through the fast path's, where it also asserts the warning still precedesAlready up to date. Both fail withstrip_utf8_bomreturning its input unchanged.cargo nextest run -p pacquet-cli(2258 tests), clippy,cargo docwith-D warnings, andcargo dylintare clean.Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.(TypeScript already strips the BOM and warns; this is the pacquet side.)
pnpm changeset) if this PR changes any publishedpackage. 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.)
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
Bug Fixes
pnpmsettings inpackage.json, ensuring migrated-field warnings are emitted consistently, including when installs finish via the “already up to date” path.pnpmfields.Tests