Skip to content

fix(catalogs): honor a wanted version the catalog entry already resolves past - #13841

Merged
zkochan merged 2 commits into
mainfrom
fix/catalog-locked-version-noop
Aug 12, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix/catalog-locked-version-noop

Conversation

@zkochan

@zkochan zkochan commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #13716, which stopped catalogMode: strict from rejecting a version a
range-based catalog entry covers. That left a hole: when the entry's recorded resolution
names a different version than the one asked for, the request was dropped silently.

# pnpm-workspace.yaml — entry covers 1.1.0, but the lockfile resolves it to 1.0.0
catalogMode: strict
catalog:
  '@pnpm.e2e/foo': ^1.0.0

pnpm add @pnpm.e2e/[email protected] (or pnpm update @pnpm.e2e/[email protected]) wrote nothing — not the
lockfile, not pnpm-workspace.yaml — and raised no error. The same swallows an explicit
downgrade: with the entry resolved to 1.3.0, asking for @1.1.0 also did nothing.

A cataloged dependency takes its version from the catalog, so the wanted version now moves the
entry's resolution: the recorded resolution is cleared, along with the resolutions the
installed projects took from it, and the wanted version is preferred above the pin the lockfile
seeds. The range the workspace declared is not touched by this — saving still re-renders it
onto the resolved version, exactly as it does for a manifest dependency.

Projects outside the install keep their resolutions until they are installed themselves, which
is what already happens for any other catalog change.

Related to #13715.

Squash Commit Body

Under a non-manual catalogMode, a wanted version the catalog entry covers resolves through the
catalog. When the entry was a range whose recorded resolution named a different version, that
resolution was reused and the wanted version was dropped without a word: `pnpm add
<pkg>@<version>` and `pnpm update <pkg>@<version>` wrote nothing to the lockfile and raised no
error, so the command looked like it had worked.

The recorded resolution is now cleared for the entry, along with the resolutions the installed
projects took from it, and the wanted version is preferred above the pin the lockfile seeds, so
the entry resolves to the version that was asked for. The range the workspace declared is
untouched by this; saving still re-renders it onto the resolved version the way it does for a
manifest dependency.

Projects outside the install keep their resolutions, as they already do for any catalog change,
until they are installed themselves.

Related to pnpm/pnpm#13715.

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.

Still to port: pacquet honors the wanted version on update already — measured with a
range entry resolved to 100.0.0, pacquet update <pkg>@100.1.0 moves the lockfile to 100.1.0 —
but pacquet add <pkg>@<version> has the same silent no-op this PR fixes for pnpm. I'm working
on that port next; it belongs in this PR before it lands.

One pre-existing difference the two stacks keep either way, which this PR does not touch:
pnpm re-renders a catalog entry's declared range when a save moves it (^1.0.0 → ^1.1.0),
pacquet leaves the range alone and moves only the resolved version.


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

    • Version-pinned pnpm add and pnpm update commands now update catalog resolutions to the requested version when applicable.
    • Catalog dependency ranges and lockfile entries are updated consistently while preserving catalog: references.
    • Prevented requested dependency versions from being silently ignored when an existing catalog range resolves differently.
    • Updated projects now resolve to the requested version without unnecessarily invalidating unrelated catalog resolutions.
  • Tests

    • Added regression coverage for catalog dependency updates, importer behavior, and lockfile changes.

…ves past

Under a non-manual catalogMode, a wanted version the catalog entry covers
resolves through the catalog. When the entry was a range whose recorded
resolution named a different version, that resolution was reused and the
wanted version was dropped without a word: `pnpm add <pkg>@<version>` and
`pnpm update <pkg>@<version>` wrote nothing to the lockfile and raised no
error, so the command looked like it had worked.

The recorded resolution is now cleared for the entry, along with the
resolutions the installed projects took from it, and the wanted version is
preferred above the pin the lockfile seeds, so the entry resolves to the
version that was asked for. The range the workspace declared is untouched
by this; saving still re-renders it onto the resolved version the way it
does for a manifest dependency.

Projects outside the install keep their resolutions, as they already do
for any catalog change, until they are installed themselves.

pacquet honors the wanted version on `update` already, but has the same
silent no-op on `add`. That port is not in this commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings August 11, 2026 23:47

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 Aug 11, 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: 90326622-f258-42a1-864a-b0966063e649

📥 Commits

Reviewing files that changed from the base of the PR and between 8e9c5b1 and c7735c5.

📒 Files selected for processing (2)
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/catalogs.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/catalogs.ts

📝 Walkthrough

Walkthrough

Version-pinned pnpm add and pnpm update commands now update catalog resolutions when the requested version differs from the locked version. The installer invalidates affected resolutions and prioritizes the requested version.

Changes

Catalog version resolution

Layer / File(s) Summary
Preferred version option plumbing
pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts, pnpm11/installing/deps-installer/src/install/index.ts
ProcessedInstallOptions accepts preferred versions. The installer imports the resolver weight used to prioritize explicit versions.
Catalog resolution invalidation and validation
pnpm11/installing/deps-installer/src/install/index.ts, pnpm11/installing/deps-installer/test/catalogs.ts, .changeset/catalog-locked-version-noop.md
installSome invalidates affected catalog resolutions, limits lockfile changes to current project importers, and prioritizes the requested version. Regression tests verify catalog, manifest, importer, and snapshot updates. A patch changeset records the behavior change.

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

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13716 — Both modify catalog-aware installSome resolution handling and regression tests for in-range versions.
  • pnpm/pnpm#13477 — Both modify catalog resolution handling in deps-installer/src/install/index.ts.
  • pnpm/pnpm#13807 — Both modify installSome and catalog resolution handling for locked versions.

Suggested labels: product: pnpm@11

Suggested reviewers: greptile-apps

✨ 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/catalog-locked-version-noop

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

// Drop the recorded resolution, along with the ones the installed projects took from
// it, so the entry is resolved again instead of reused at the version it named before.
// Projects outside this install keep theirs until they are installed themselves.
delete ctx.wantedLockfile.catalogs?.[catalogName]?.[alias]
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix catalog strict mode to honor requested versions covered by catalog ranges

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Prevent pnpm add/update @ from becoming a silent no-op in non-manual catalog modes.
• When a catalog range covers the requested version, move the catalog’s resolved version to it.
• Add regression coverage for both add and update flows, plus a changeset.
Diagram

graph TD
  cmd["pnpm add/update"] --> mm["mutateModules()"] --> rce["resolveCatalogEntryTo()"] --> pv["preferredVersions"] --> ic["installInContext()"]
  cfg[("pnpm-workspace.yaml catalogs")] --> mm
  rce --> lf[("pnpm-lock.yaml")]
  ic --> lf
  ic --> cfg
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Fail fast on mismatched locked resolution
  • ➕ Simpler implementation (no lockfile mutation logic)
  • ➕ Makes the behavior explicit instead of auto-moving resolutions
  • ➖ Breaks legitimate workflows (e.g. Renovate-style targeted updates)
  • ➖ Less ergonomic: users must manually edit catalogs/lockfile to proceed
2. Rewrite only the catalog entry version in lockfile (no importer cleanup)
  • ➕ Less invasive lockfile edits
  • ➕ Potentially faster (smaller mutation footprint)
  • ➖ Risk of leaving importers pointing at stale versions, causing inconsistent lockfile state
  • ➖ May still allow lockfile-seeded pins to override the requested version without additional preference plumbing

Recommendation: The chosen approach (delete the recorded catalog resolution + clear affected importer resolved deps for installed projects, then bias resolution via preferredVersions with a weight above the lockfile seed) is the most robust: it avoids silent no-ops, keeps cataloged dependencies aligned across installed projects, and preserves the workspace’s declared catalog range while still honoring an explicit requested version.

Files changed (4) +138 / -8

Enhancement (1) +7 / -1
extendInstallOptions.tsExpose 'preferredVersions' in processed install options +7/-1

Expose 'preferredVersions' in processed install options

• Extends 'ProcessedInstallOptions' to optionally carry 'preferredVersions', with documentation indicating it may be provided by callers and also augmented internally by 'mutateModules' for catalog resolution moves.

pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts

Bug fix (1) +53 / -3
index.tsMove catalog resolution to requested covered version via lockfile reset + preference +53/-3

Move catalog resolution to requested covered version via lockfile reset + preference

• When 'catalogMode' is not 'manual' and a requested version is covered by the catalog specifier, introduces 'resolveCatalogEntryTo()' to clear stale recorded catalog and importer resolutions for installed projects. Also injects a high-weight 'preferredVersions' entry so resolution favors the requested version over lockfile-seeded pins.

pnpm11/installing/deps-installer/src/install/index.ts

Tests (1) +72 / -4
catalogs.tsAdd regression test for add() moving a locked catalog range; tighten update expectations +72/-4

Add regression test for add() moving a locked catalog range; tighten update expectations

• Adds a new test asserting that 'add <pkg>@<version>' moves a catalog entry that is range-based but locked to another version. Updates the strict-mode update test to assert the requested version is chosen (not the newest in-range) and that importers and snapshots reflect the moved resolution.

pnpm11/installing/deps-installer/test/catalogs.ts

Documentation (1) +6 / -0
catalog-locked-version-noop.mdAdd changeset describing catalog wanted-version fix +6/-0

Add changeset describing catalog wanted-version fix

• Adds a patch changeset for both '@pnpm/installing.deps-installer' and 'pnpm'. Documents the prior silent no-op behavior and the new behavior of moving catalog resolution to the requested version under non-manual catalog modes.

.changeset/catalog-locked-version-noop.md

@greptile-apps

greptile-apps Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Reviews (2): Last reviewed commit: "fix(catalogs): build the preferred-versi..." | Re-trigger Greptile

@qodo-code-review

qodo-code-review Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Pacquet catalog move not ported 📘 Rule violation ⌂ Architecture
Description
This PR changes pnpm’s user-visible add/update behavior under non-manual catalogMode by
forcing the catalog entry to re-resolve to the requested version. The equivalent pacquet (Rust)
behavior is not updated in this PR, risking pnpm/pacquet divergence for the same inputs.
Code

pnpm11/installing/deps-installer/src/install/index.ts[R1253-1256]

+        ...opts.preferredVersions,
+        [alias]: {
+          ...opts.preferredVersions?.[alias],
+          [version]: { selectorType: 'version', weight: EXISTING_VERSION_SELECTOR_WEIGHT + 1 },
Relevance

●●● Strong

Repo frequently enforces TS/Rust parity for user-visible behavior; missing pacquet port likely
flagged to fix or track.

PR-#12789
PR-#13074

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changeset and new pnpm installer logic show a user-visible behavior change: pnpm now biases
resolution to the requested version even when the catalog range already covers it. Pacquet’s
catalog-mode decision path, by contrast, keeps using the existing catalog entry when the range
covers the requested version (updated_entry: None), with no corresponding “move the recorded
resolution” mechanism shown here, so parity is not maintained within this PR.

Rule 713428: Keep pnpm TypeScript and pacquet Rust user-visible behavior changes in sync
.changeset/catalog-locked-version-noop.md[6-6]
pnpm11/installing/deps-installer/src/install/index.ts[1235-1258]
pnpm/crates/package-manager/src/catalog_mode.rs[158-165]

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

## Issue description
pnpm (TypeScript) now forces a catalog entry to move its recorded resolution when a command requests a version that the catalog range already covers, but pacquet (Rust) does not implement the same behavior in this PR. This creates a user-visible divergence between pnpm and pacquet.

## Issue Context
The PR introduces logic that clears the recorded catalog resolution / importer resolutions and adds a higher-weight `preferredVersions` entry so resolution prefers the user-requested version.

## Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/index.ts[1235-1258]
- pnpm/crates/package-manager/src/catalog_mode.rs[158-165]
- .changeset/catalog-locked-version-noop.md[6-6]

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


2. Missing trailing comma in type 📘 Rule violation ⚙ Maintainability
Description
A new multi-line TypeScript type literal is missing a trailing comma on the last property, violating
the required trailing-comma style and increasing diff churn. This can also conflict with repo
formatting expectations for TS multi-line constructs.
Code

pnpm11/installing/deps-installer/src/install/index.ts[R1228-1231]

+        alias: string
+        catalogName: string
+        version: string
+      }
Relevance

●● Moderate

Trailing-comma enforcement is inconsistent: some accepted, many rejected, and no close precedent for
type-literal trailing comma.

PR-#13779
PR-#13804

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist requires trailing commas in multi-line TypeScript constructs. The newly added object
type for the resolveCatalogEntryTo parameter ends its last property (version: string) without a
trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-installer/src/install/index.ts[1227-1231]

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 multi-line TypeScript type literal was added without a trailing comma on the last property.

## Issue Context
The repo policy requires trailing commas in multi-line TypeScript constructs (including type/object definitions).

## Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/index.ts[1227-1231]

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


3. Unneeded importer full-scan 🐞 Bug ➹ Performance
Description
resolveCatalogEntryTo() scans every lockfile importer and then filters by installedProjectIds,
adding O(total importers) work per catalog-entry move. In large workspaces (many importers) and
multi-selector add/update operations, this introduces avoidable overhead in lockfile handling paths.
Code

pnpm11/installing/deps-installer/src/install/index.ts[R1239-1242]

+      for (const [id, importer] of Object.entries(ctx.wantedLockfile.importers ?? {})) {
+        if (!installedProjectIds.has(id)) continue
+        const specifier = importer.specifiers?.[alias]
+        if (specifier == null || parseCatalogProtocol(specifier) !== catalogName) continue
Relevance

●● Moderate

Perf-only refactor; repo has rejected some “avoid full scans” micro-opts, but no close importer-scan
precedent.

PR-#13803
PR-#13600

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR computes installedProjectIds but still walks the entire wantedLockfile.importers map and
checks membership for each entry, which is strictly more work than necessary when only installed
projects need mutation. This is in a lockfile/importer-handling path that the repo explicitly treats
as performance-sensitive.

pnpm11/installing/deps-installer/src/install/index.ts[977-978]
pnpm11/installing/deps-installer/src/install/index.ts[1238-1246]
REVIEW_GUIDE.md[20-22]

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

## Issue description
`resolveCatalogEntryTo()` currently iterates over **all** lockfile importers (`Object.entries(ctx.wantedLockfile.importers ?? {})`) and then filters by `installedProjectIds`. This makes each catalog-entry move O(total importers in lockfile), which is avoidable because the code already computed the exact set of installed project IDs.

## Issue Context
This code runs in `mutateModules()` during add/update flows and touches lockfile importer snapshots (a performance-sensitive area per repo guidance).

## Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/index.ts[977-978]
- pnpm11/installing/deps-installer/src/install/index.ts[1238-1246]

### Suggested fix
Change the loop to iterate `installedProjectIds` and direct-index into `ctx.wantedLockfile.importers`:

- Cache `const importers = ctx.wantedLockfile.importers ?? {}`.
- `for (const id of installedProjectIds) { const importer = importers[id]; if (!importer) continue; ... }`

This preserves behavior while avoiding a full traversal of unrelated importers.

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



Informational

4. Missing trailing commas in test 📘 Rule violation ⚙ Maintainability
Description
New multi-line TypeScript constructs in the added test omit required trailing commas (e.g., the
final array element and the final argument in a multi-line call). This violates the trailing-comma
rule and makes future edits noisier.
Code

pnpm11/installing/deps-installer/test/catalogs.ts[R1660-1662]

+        dir: path.join(options.lockfileDir, 'project1'),
+        allowNew: true,
+      })
Relevance

● Weak

Close rejection precedent: trailing-comma nits in TS tests/calls (incl. addDependenciesToPackage)
were rejected previously.

PR-#13289
PR-#13803

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist mandates trailing commas for multi-line TypeScript collections/argument lists. In the
added test, the multi-line array passed to preparePackagesAndReturnObjects ends the last element
without a trailing comma, and the multi-line addDependenciesToPackage(...) call closes its last
argument without a trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-installer/test/catalogs.ts[1626-1636]
pnpm11/installing/deps-installer/test/catalogs.ts[1655-1662]

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 new test introduces multi-line TypeScript constructs without trailing commas, including:
- the final element in a multi-line array literal
- the final argument in a multi-line function call

## Issue Context
The repo policy requires trailing commas in multi-line TypeScript collections and argument lists.

## Fix Focus Areas
- pnpm11/installing/deps-installer/test/catalogs.ts[1626-1636]
- pnpm11/installing/deps-installer/test/catalogs.ts[1655-1662]

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


Grey Divider

Context
✅ Compliance rules (platform): 18 rules

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

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.

@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: 2

🤖 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/installing/deps-installer/src/install/index.ts`:
- Around line 1187-1191: The add installation flow around resolveCatalogEntryTo
must invalidate the affected dependency’s catalog snapshot when a concrete
requested version is covered by an existing catalog range, while retaining the
catalog entry itself. Ensure UpdateSeedPolicy::KeepAll cannot reuse the stale
snapshot, and add a regression test covering this concrete-version request
scenario.

In `@pnpm11/installing/deps-installer/test/catalogs.ts`:
- Around line 1679-1682: Extend the assertions in the catalog lockfile test
after the project1 mutation to verify that project2 still resolves `@pnpm.e2e/foo`
at 1.0.0 and that the 1.0.0 snapshot remains present. Keep the existing project1
and catalog assertions unchanged.
🪄 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: 428d56e4-c7e0-45b0-94e8-b0ec0cf3980a

📥 Commits

Reviewing files that changed from the base of the PR and between 676324f and 8e9c5b1.

📒 Files selected for processing (4)
  • .changeset/catalog-locked-version-noop.md
  • pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/catalogs.ts

A package named `__proto__` reached an object literal's computed key, so
the merge could touch Object.prototype instead of adding an own property.
Build both merge targets with Object.create(null), matching the seed merge
in installInContext.

Also pin that a project outside the install keeps the version the catalog
entry resolved to before, and drop the comments that restated the
assertions and the deletions they sit next to.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 12, 2026 05:25

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.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit c7735c5

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

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.

3 participants