Skip to content

fix: normalize empty bundledDependencies array in lockfile - #13154

Closed
Ayush442842q wants to merge 2 commits into
pnpm:mainfrom
Ayush442842q:fix/bundled-deps-empty-array
Closed

Ayush442842q wants to merge 2 commits into
pnpm:mainfrom
Ayush442842q:fix/bundled-deps-empty-array

Conversation

@Ayush442842q

@Ayush442842q Ayush442842q commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Resolves non-deterministic addition/removal of bundledDependencies: [] in
pnpm-lock.yaml (the empty-array variant of #7576).

Some packages (e.g. [email protected]) publish a tarball package.json
containing "bundledDependencies": [], while the registry version metadata
for the same version omits the field entirely. Depending on which manifest
source pnpm resolves from (store-derived vs. registry metadata), the
lockfile serializer would write the empty array in one case and omit it in
the other — causing lockfile churn with no actual dependency changes.

This PR normalizes empty bundledDependencies / bundleDependencies arrays
so they are never serialized, since an empty array carries no information
(equivalent to the field being absent).

Fixes #13123

Squash Commit Body

fix: normalize empty bundledDependencies array in lockfile

Some packages publish a tarball package.json containing
"bundledDependencies": [] while the registry version metadata for the
same version omits the field. Depending on which manifest source pnpm
resolves from (store-derived vs. registry metadata), the lockfile
serializer wrote the empty array in one case and omitted it in the
other, causing non-deterministic lockfile churn across machines/caches
with no real dependency changes.

Add a length check before serializing bundledDependencies and
bundleDependencies so empty arrays are normalized away, matching how
`bundledDependencies: false` was already handled (pnpm/pnpm#7580).
An empty array carries no information and should be treated as
equivalent to the field being absent.

The Rust pnpm/ port already discards empty arrays via
(!out.is_empty()).then_some(out) in read_string_list, so no parity
change is needed there.

Fixes pnpm/pnpm#13123

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    (Rust port already immune — see commit body.)
  • 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.
  • Updated the documentation if needed.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented empty bundledDependencies / bundleDependencies from being written to lockfiles, reducing non-deterministic lockfile diffs.
    • Preserved bundled dependency information when non-empty lists (and true) are present during lockfile updates.
  • Tests
    • Added coverage to verify correct lockfile output for empty, non-empty, and boolean true bundled dependency settings.

Normalize empty bundledDependencies and bundleDependencies arrays to
prevent them from being serialized in the lockfile. This prevents
non-deterministic lockfile churn when different metadata sources are used.

Related to pnpm#13123
@Ayush442842q
Ayush442842q requested a review from zkochan as a code owner July 19, 2026 18:55
@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 Jul 19, 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: db11b306-b535-43fa-b86c-816ae052896b

📥 Commits

Reviewing files that changed from the base of the PR and between dc47488 and 2514989.

📒 Files selected for processing (1)
  • pnpm11/installing/deps-resolver/test/updateLockfile.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm11/installing/deps-resolver/test/updateLockfile.test.ts

📝 Walkthrough

Walkthrough

The lockfile dependency serializer now omits empty bundledDependencies and bundleDependencies arrays while retaining non-empty arrays and true. Tests cover normalization and preservation, and a patch changeset was added.

Changes

Bundled dependency lockfile normalization

Layer / File(s) Summary
Normalize and validate bundled dependency metadata
pnpm11/installing/deps-resolver/src/updateLockfile.ts, pnpm11/installing/deps-resolver/test/updateLockfile.test.ts, .changeset/bundled-dependencies-empty-array.md
toLockfileDependency excludes empty bundled dependency arrays, tests verify empty, non-empty, and boolean values, and a patch changeset documents the behavior.

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

Assessment against linked issues

Objective Addressed Explanation
Normalize empty bundledDependencies arrays so they are omitted from the lockfile and prevent nondeterministic lockfile changes [#13123] ✅
Apply the same normalization to the bundleDependencies alias [#13123] ✅

Possibly related PRs

  • pnpm/pnpm#13148: Updates the same lockfile serializer and tests empty bundled dependency array normalization.

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 Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the change is a targeted two-line guard that only removes empty arrays from lockfile serialization, with no risk of dropping real bundled-dependency information.

The fix is minimal and correct: an empty bundledDependencies array carries no information, and normalizing it away matches both the existing false handling and the Rust port's behavior. Tests cover the main branches introduced. The only gap is a missing test for the bundleDependencies (legacy alias) non-empty fallback path.

No files require special attention beyond the optional test gap noted in updateLockfile.test.ts.

Reviews (2): Last reviewed commit: "test: add unit test for boolean true bun..." | Re-trigger Greptile

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 19, 2026
@zkochan

zkochan commented Jul 30, 2026

Copy link
Copy Markdown
Member

Closing as a duplicate of #13148, which fixes the same issue (#13123) with the identical guard in updateLockfile.ts and additionally covers the empty-array fallback cases in its test matrix and mirrors the change in the Rust port (pacquet). Thank you for the contribution — the root-cause analysis here matched exactly.


Written by an agent (Claude Code, claude-fable-5) on behalf of zkochan.

@zkochan zkochan closed this Jul 30, 2026
@Ayush442842q
Ayush442842q deleted the fix/bundled-deps-empty-array branch August 22, 2026 12:21
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bundledDependencies: [] nondeterministically added/removed in pnpm-lock.yaml (empty-array variant of #7576)

2 participants