Skip to content

fix(pnpm): write pnpmOverrides to pnpm-workspace.yaml#336

Open
unstubbable wants to merge 1 commit into
JamieMason:mainfrom
unstubbable:fix-pnpm-workspace-overrides
Open

fix(pnpm): write pnpmOverrides to pnpm-workspace.yaml#336
unstubbable wants to merge 1 commit into
JamieMason:mainfrom
unstubbable:fix-pnpm-workspace-overrides

Conversation

@unstubbable
Copy link
Copy Markdown

@unstubbable unstubbable commented Jun 2, 2026

The fix command reads overrides from pnpm-workspace.yaml but never writes the corrected versions back, so any mismatch that lint flagged was reported as fixed () while the file was actually left untouched.

The read side was added in 72ce5ef, which pointed the default pnpmOverrides dependency type at pnpm-workspace.yaml with source: PnpmWorkspace. The matching write path in copy_expected_specifier_yaml was never extended, though: it returns early for any instance without a catalog name, so the versionsByName workspace instances (i.e. overrides) fall through and nothing is written.

An overrides block is a flat name: version map with the same shape as the default catalog: block, so the single-block logic now lives in reusable build_block_insert_patch and ensure_yaml_block helpers, extracted from build_insert_patch and ensure_catalog_block (which the default catalog delegates to). Non-catalog versionsByName workspace instances route through a new insert_into_yaml_block, the single-block sibling of insert_catalog_definition. The block key comes from the dependency type's path (e.g. /overrides), so the same path also covers any user customType with source: PnpmWorkspace.

Reads and lints already detected these mismatches, so apart from the now-working write path the behaviour is unchanged. A new regression test, pnpm_fix_updates_overrides_in_yaml, asserts the override is rewritten in pnpm-workspace.yaml and the file is marked dirty.

Tip

Best reviewed with hidden whitespace changes because of the shared helper extraction.

The `fix` command reads `overrides` from `pnpm-workspace.yaml` but never
writes the corrected versions back, so any mismatch that `lint` flagged
was reported as fixed (`✓`) while the file was actually left untouched.

The read side was added in 72ce5ef, which pointed the default
`pnpmOverrides` dependency type at `pnpm-workspace.yaml` with `source:
PnpmWorkspace`. The matching write path in
`copy_expected_specifier_yaml` was never extended, though: it returns
early for any instance without a catalog name, so the `versionsByName`
workspace instances (i.e. `overrides`) fall through and nothing is
written.

An `overrides` block is a flat `name: version` map with the same shape
as the default `catalog:` block, so the single-block logic now lives in
reusable `build_block_insert_patch` and `ensure_yaml_block` helpers,
extracted from `build_insert_patch` and `ensure_catalog_block` (which
the default catalog delegates to). Non-catalog `versionsByName`
workspace instances route through a new `insert_into_yaml_block`, the
single-block sibling of `insert_catalog_definition`. The block key comes
from the dependency type's `path` (e.g. `/overrides`), so the same path
also covers any user `customType` with `source: PnpmWorkspace`.

Reads and lints already detected these mismatches, so apart from the
now-working write path the behaviour is unchanged. A new regression
test, `pnpm_fix_updates_overrides_in_yaml`, asserts the override is
rewritten in `pnpm-workspace.yaml` and the file is marked dirty.
@JamieMason
Copy link
Copy Markdown
Owner

Damn, nice catch. I checked that catalogs were written back to this file, but I must've totally overlooked overrides, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants