Skip to content

fix(lockfile): read patchedDependencies written by pnpm 10 - #13330

Merged
zkochan merged 3 commits into
mainfrom
fix-13307
Jul 25, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-13307

Conversation

@zkochan

@zkochan zkochan commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Summary

pnpm 10 serializes each patchedDependencies entry in pnpm-lock.yaml as a {hash, path} mapping, while pnpm 11 and later write the bare patch-file hash. pacquet typed Lockfile::patched_dependencies as BTreeMap<String, String>, so a lockfile committed by pnpm 10 failed to parse and every install — frozen and non-frozen alike — aborted with ERR_PNPM_BROKEN_LOCKFILE before it could regenerate anything. This is a hard upgrade blocker for any repository that patches a dependency and still has a pnpm-10-written lockfile committed (it blocks a cold frozen install of vercel/next.js).

The field now deserializes through an untagged entry accepting both shapes and collapsing the mapping to its hash, mirroring migratePatchedDependencies in lockfile/fs/src/lockfileFormatConverters.ts. The writer is unchanged, so such a lockfile installs as-is and normalizes to the bare-hash shape the next time it is written.

TypeScript CLI: no change needed — it already migrates the old shape at load time.

Closes #13307

Squash Commit Body

pnpm 10 serializes each `patchedDependencies` entry as a `{hash, path}`
mapping, while pnpm 11 and later write the bare patch-file hash. The
`Lockfile::patched_dependencies` field typed the values as plain strings,
so a lockfile committed by pnpm 10 failed to parse and every install --
frozen and non-frozen alike -- aborted with ERR_PNPM_BROKEN_LOCKFILE
before it could regenerate anything.

Deserialize the field through an untagged entry that accepts both shapes
and collapses the mapping to its hash, mirroring
`migratePatchedDependencies` in the TypeScript CLI. The path is redundant
-- patch paths come from the project's `patchedDependencies` config -- and
the writer already emits the bare hash, so such a lockfile installs
unchanged and normalizes the next time it is written.

Closes pnpm/pnpm#13307

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    (Rust-only: the TypeScript CLI already handles both shapes.)
  • 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.

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
    • Fixed frozen installs for lockfiles generated by pnpm 10 that include patched dependencies.
    • Added compatibility for both legacy and pnpm 10 patched-dependency formats.
    • Ensured patched packages install correctly, with stable lockfile handling and normalization on subsequent updates.
  • Tests
    • Added regression coverage for pnpm 10 patched-dependencies lockfile shapes to prevent future lockfile parsing/install issues.

zkochan added 2 commits July 25, 2026 13:29
pnpm 10 serializes each `patchedDependencies` entry as a `{hash, path}`
mapping, while pnpm 11 and later write the bare patch-file hash. The
`Lockfile::patched_dependencies` field typed the values as plain strings,
so a lockfile committed by pnpm 10 failed to parse and every install --
frozen and non-frozen alike -- aborted with ERR_PNPM_BROKEN_LOCKFILE
before it could regenerate anything.

Deserialize the field through an untagged entry that accepts both shapes
and collapses the mapping to its hash, mirroring
`migratePatchedDependencies` in the TypeScript CLI. The path is redundant
-- patch paths come from the project's `patchedDependencies` config -- and
the writer already emits the bare hash, so such a lockfile installs
unchanged and normalizes the next time it is written.

Closes #13307
Copilot AI review requested due to automatic review settings July 25, 2026 11:37

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: 31bd3c39-0bf2-4f8a-ad1f-a453307b244c

📥 Commits

Reviewing files that changed from the base of the PR and between aeb6580 and add5c32.

📒 Files selected for processing (2)
  • .changeset/read-pnpm-10-patched-dependencies.md
  • pnpm/crates/cli/tests/patch.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/cli/tests/patch.rs

📝 Walkthrough

Walkthrough

The lockfile loader accepts pnpm 10 {hash, path} patched-dependency entries alongside hash-only entries, normalizes them to hashes, and validates frozen and regular install behavior.

Changes

Patched dependencies compatibility

Layer / File(s) Summary
Normalize patched dependency entries
pnpm/crates/lockfile/src/lib.rs, pnpm/crates/lockfile/src/load_lockfile/tests.rs
The deserializer accepts both patched-dependency representations and stores normalized key-to-hash mappings, with multiline and inline YAML coverage.
Validate installation and normalization
pnpm/crates/cli/tests/patch.rs, .changeset/read-pnpm-10-patched-dependencies.md
The regression test verifies frozen installs preserve the pnpm 10 lockfile, while regular installs apply updated patches and write the canonical hash-only format; the changeset documents the fix.

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

Assessment against linked issues

Objective Addressed Explanation
Accept pnpm 10 patchedDependencies mappings in the Rust lockfile loader [#13307] ✅
Allow frozen and regular installs to proceed, apply patches, and normalize the lockfile [#13307] ✅

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13149 — Touches patched-dependency lockfile handling and related CLI tests.

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 fix-13307

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 lockfile parsing for pnpm 10 patchedDependencies entries

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Accept pnpm 10 {hash, path} patchedDependencies entries when loading pnpm-lock.yaml.
• Preserve lockfile contents on frozen installs and normalize to bare-hash on rewrite.
• Add regression tests and a changeset release note for pnpm/pnpm#13307.
Diagram

graph TD
  CLI["pacquet install"] --> LF[("pnpm-lock.yaml")] --> Loader["Lockfile::load_current"] --> De["deserialize_patched_dependencies"] --> Parsed["patched_dependencies map"] --> Install["Install continues"]
  Install --> Write["Lockfile writer"] --> LF
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Model patchedDependencies values as an enum in the Lockfile struct
  • ➕ Keeps both wire formats explicitly represented in the type system
  • ➕ Could preserve the legacy path for debugging/telemetry if ever needed
  • ➖ Higher surface area: type changes propagate through callers/serialization logic
  • ➖ Still requires normalization logic somewhere to match current behavior
2. Pre-parse/migrate YAML before serde struct deserialization
  • ➕ Keeps Lockfile struct fields simple (string map)
  • ➕ Centralizes all lockfile migrations in one pass
  • ➖ Requires a YAML AST/value pass and rewriting logic before typed parsing
  • ➖ More code and potential edge cases than a targeted field deserializer

Recommendation: Keep the current targeted serde deserialize_with using an untagged enum. It is the smallest change that unblocks pnpm-10-written lockfiles, matches the TypeScript migration behavior, preserves frozen-lockfile semantics, and naturally normalizes on the next write without expanding the Lockfile surface area.

Files changed (4) +139 / -5

Bug fix (1) +40 / -5
lib.rsSupport deserializing pnpm 10 patchedDependencies entries via custom serde handler +40/-5

Support deserializing pnpm 10 patchedDependencies entries via custom serde handler

• Changes 'Lockfile::patched_dependencies' deserialization to accept either a bare hash string or an object containing 'hash' (and optionally 'path'). Collapses legacy objects to their hash and keeps serialization behavior unchanged (still writes the modern bare-hash form).

pnpm/crates/lockfile/src/lib.rs

Tests (2) +94 / -0
patch.rsAdd install regression test for pnpm 10 patchedDependencies lockfile shape +54/-0

Add install regression test for pnpm 10 patchedDependencies lockfile shape

• Introduces an end-to-end CLI regression test that rewrites 'pnpm-lock.yaml' to the pnpm 10 '{hash, path}' form and verifies both frozen and non-frozen installs succeed. Confirms frozen installs do not modify the lockfile and non-frozen rewrites normalize entries back to the bare-hash form.

pnpm/crates/cli/tests/patch.rs

tests.rsAdd lockfile loader unit test for mixed pnpm 10 + modern patchedDependencies entries +40/-0

Add lockfile loader unit test for mixed pnpm 10 + modern patchedDependencies entries

• Adds a regression test that loads a minimal lockfile containing both the pnpm 10 mapping form and the modern string form. Asserts the parsed 'patched_dependencies' map contains only the expected hashes.

pnpm/crates/lockfile/src/load_lockfile/tests.rs

Documentation (1) +5 / -0
read-pnpm-10-patched-dependencies.mdAdd changeset for pnpm 10 patchedDependencies lockfile compatibility fix +5/-0

Add changeset for pnpm 10 patchedDependencies lockfile compatibility fix

• Adds a user-facing release note describing the fix for ERR_PNPM_BROKEN_LOCKFILE when reading pnpm 10 lockfiles with patchedDependencies. Explains acceptance of both '{hash, path}' and bare-hash shapes and normalization on rewrite.

.changeset/read-pnpm-10-patched-dependencies.md

@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 @.changeset/read-pnpm-10-patched-dependencies.md:
- Line 5: Revise the changeset entry to describe only the fixed pnpm lockfile
install compatibility for patched dependencies, removing the `{hash, path}`
format, bare hash, normalization, and issue-reference implementation details.
Keep the release note concise and focused on user-visible behavior.
🪄 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: b2f3f484-e33c-4af8-90c3-331a0825288e

📥 Commits

Reviewing files that changed from the base of the PR and between 875073e and aeb6580.

📒 Files selected for processing (4)
  • .changeset/read-pnpm-10-patched-dependencies.md
  • pnpm/crates/cli/tests/patch.rs
  • pnpm/crates/lockfile/src/lib.rs
  • pnpm/crates/lockfile/src/load_lockfile/tests.rs

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Comment says used to abort ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
A newly added doc comment describes historical behavior using used to, which violates the rule to
keep comments focused on current behavior/contract. This increases maintenance burden and can become
incorrect as behavior evolves.
Code

pnpm/crates/cli/tests/patch.rs[R467-470]

+/// Regression test for <https://github.com/pnpm/pnpm/issues/13307>: a
+/// lockfile committed by pnpm 10 records each patched dependency as a
+/// `{hash, path}` mapping instead of the bare hash. Installing over it
+/// used to abort with `ERR_PNPM_BROKEN_LOCKFILE`, frozen or not.
Relevance

⭐⭐⭐ High

Repo often accepts rewording comments to remove historical phrasing like “used to” in new
tests/docs.

PR-#13138
PR-#13246

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 prohibits historical/temporal phrasing like used to in comments. The added
regression-test doc comment explicitly says installation used to abort with a specific error code,
describing past behavior rather than the current contract the test enforces.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/cli/tests/patch.rs[467-470]

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

## Issue description
A new comment uses historical phrasing (`used to abort`) instead of describing the current expected behavior/contract.

## Issue Context
Comments should document what the code does now (inputs/outputs/invariants), not past behavior.

## Fix Focus Areas
- pnpm/crates/cli/tests/patch.rs[467-470]

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



Informational

2. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only bumps pacquet and does not declare a bump for pnpm, which violates the
requirement to explicitly include pnpm in changesets. This can cause the release tooling/notes to
miss the intended pnpm version bump classification for this user-visible lockfile parsing change.
Code

.changeset/read-pnpm-10-patched-dependencies.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

⭐ Low

Multiple PRs rejected adding required "pnpm" entry when changeset only bumped pacquet.

PR-#12981
PR-#13285
PR-#13297

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires every changeset to include an explicit pnpm package entry with a
valid bump type. The added changeset front-matter includes only "pacquet": patch and no `"pnpm":
...` entry.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/read-pnpm-10-patched-dependencies.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 changeset `.changeset/read-pnpm-10-patched-dependencies.md` is missing a `pnpm` entry in its front-matter.

## Issue Context
Compliance requires changesets to explicitly declare the `pnpm` package and a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/read-pnpm-10-patched-dependencies.md[1-3]

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


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.

@greptile-apps

greptile-apps Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The compatibility fix appears safe to merge, with only the previously reported redundant test documentation still outstanding.

The new deserializer accepts both lockfile representations and normalizes them to the existing in-memory shape; the remaining concern is limited to maintainability of the regression test's redundant rustdoc.

Files Needing Attention: pnpm/crates/cli/tests/patch.rs

Reviews (2): Last reviewed commit: "docs: address review feedback on the pnp..." | Re-trigger Greptile

Comment thread pnpm/crates/cli/tests/patch.rs Resolved
@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.03     11.8±0.04ms    31.6 MB/sec    1.00     11.5±0.10ms    32.5 MB/sec
packument/parse                1.01     36.2±0.11µs  1832.5 MB/sec    1.00     35.9±0.07µs  1847.3 MB/sec
tarball/download_dependency    1.00      2.2±0.06ms  1933.9 KB/sec    1.02      2.3±0.06ms  1902.7 KB/sec

@codecov-commenter

codecov-commenter commented Jul 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.05%. Comparing base (875073e) to head (add5c32).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13330      +/-   ##
==========================================
- Coverage   87.05%   87.05%   -0.01%     
==========================================
  Files         532      532              
  Lines       91601    91616      +15     
==========================================
+ Hits        79741    79753      +12     
- Misses      11860    11863       +3     

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

Drop the historical framing and the restatement of the test body from the
regression test's doc comment, and trim the changeset to the user-visible
effect.
Copilot AI review requested due to automatic review settings July 25, 2026 11:50

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.

@zkochan

zkochan commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

Review feedback addressed in add5c326ce:

  • Qodo — "used to abort" historical phrasing (fixed): the regression test's doc comment is now just the issue link. AGENTS.md bans "used to" / "previously" framing in source; that context belongs in the commit message.
  • Greptile — redundant regression-test rustdoc (fixed): same edit. The test name, setup, and assertions carry it, per "Tests are documentation. Do not duplicate them in prose."
  • CodeRabbit — implementation detail in the changeset (fixed): trimmed to "Fixed ERR_PNPM_BROKEN_LOCKFILE when installing with a pnpm 10 lockfile that has a patchedDependencies section."

Qodo — changeset missing a pnpm entry: not applying this one, the rule misfires here. This change is Rust-only, and AGENTS.md is explicit: "Do not add "pnpm" to a Rust-only changeset: in changesets, pnpm always means the TypeScript CLI package. A changeset whose implementation is Rust-only and targets pacquet must omit "pnpm"." Adding it would cut a TypeScript CLI release for a change that ships no TypeScript code. The TypeScript side already migrates the pnpm 10 shape via migratePatchedDependencies, so there is nothing to mirror.


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

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

@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 merged commit 352125d into main Jul 25, 2026
35 checks passed
@zkochan
zkochan deleted the fix-13307 branch July 25, 2026 11:56
kairosci added a commit to kairosci/pnpm that referenced this pull request Jul 27, 2026
pnpm 10 serializes each `patchedDependencies` entry as a `{hash, path}`
mapping, while pnpm 11 and later write the bare patch-file hash. The
`Lockfile::patched_dependencies` field typed the values as plain strings,
so a lockfile committed by pnpm 10 failed to parse and every install --
frozen and non-frozen alike -- aborted with ERR_PNPM_BROKEN_LOCKFILE
before it could regenerate anything.

Deserialize the field through an untagged entry that accepts both shapes
and collapses the mapping to its hash, mirroring
`migratePatchedDependencies` in the TypeScript CLI. The path is redundant
-- patch paths come from the project's `patchedDependencies` config -- and
the writer already emits the bare hash, so such a lockfile installs
unchanged and normalizes the next time it is written.

Closes pnpm#13307
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.

pnpm 12 cannot read a pnpm 10 lockfile with patchedDependencies (ERR_PNPM_BROKEN_LOCKFILE)

3 participants