Skip to content

fix(workspace.manifest-writer): preserve formatting in pnpm-workspace.yaml when updating catalogs#10430

Merged
zkochan merged 7 commits intopnpm:mainfrom
prgmr99:fix-10425-preserve-yaml-formatting
Jan 26, 2026
Merged

fix(workspace.manifest-writer): preserve formatting in pnpm-workspace.yaml when updating catalogs#10430
zkochan merged 7 commits intopnpm:mainfrom
prgmr99:fix-10425-preserve-yaml-formatting

Conversation

@prgmr99
Copy link
Copy Markdown
Contributor

@prgmr99 prgmr99 commented Jan 9, 2026

Description

Fixes an issue where running commands like pnpm update causes unintentional formatting changes in pnpm-workspace.yaml.

Problem

When updating dependencies, the catalog section lost its original quoting style even when values remained unchanged:

Before pnpm update:

catalog:
  'zod': '3.24.3'
  "lodash": "4.17.21"

After pnpm update:

  catalog:
    zod: 3.24.3
    lodash: 4.17.21

Root Cause

The issue was in the addCatalogs function (workspace/manifest-writer/src/index.ts):

  1. shouldBeUpdated was set to true unconditionally, even when no values changed
  2. This triggered unnecessary file rewrites
  3. Although patchDocument preserves formatting, values were overwritten in memory before comparison, causing new nodes to be created without original quote styles

Solution

Modified addCatalogs to only flag updates when necessary:

  • Check if targetCatalog[dependencyName] differs from the new specifier before updating
  • Set shouldBeUpdated = true only when:
    • A value actually changes, OR
    • A new catalog is being added

This prevents unnecessary in-memory modifications, allowing patchDocument to preserve original YAML formatting.

Closes #10425

…space.yaml

Ensure that the original formatting (quotes, etc.) in pnpm-workspace.yaml
is preserved when running commands like \`pnpm update\`.

Closes pnpm#10425
@prgmr99 prgmr99 requested a review from zkochan as a code owner January 9, 2026 07:29
@prgmr99 prgmr99 changed the title fix: preserve yaml formatting fix(workspace.manifest-writer): preserve yaml formatting Jan 9, 2026
Copy link
Copy Markdown
Member

@zkochan zkochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked locally and your change is not doing anything. The quotes are currently preserved without your fix. I even added a test.

@prgmr99
Copy link
Copy Markdown
Contributor Author

prgmr99 commented Jan 14, 2026

I checked locally and your change is not doing anything. The quotes are currently preserved without your fix. I even added a test.

Thanks for checking and for adding a test — I appreciate it.

I’ll take another look on my side to better understand why the change isn’t having an effect. Once I’ve verified the behavior and have something concrete, I’ll follow up and mention you again.

@prgmr99 prgmr99 changed the title fix(workspace.manifest-writer): preserve yaml formatting fix(workspace.manifest-writer): preserve formatting in pnpm-workspace.yaml when updating catalogs Jan 17, 2026
@prgmr99
Copy link
Copy Markdown
Contributor Author

prgmr99 commented Jan 17, 2026

@zkochan Thank you for your patience.

I've identified the root cause and pushed a fix. The issue was in the addCatalogs function — shouldBeUpdated was being set to true unconditionally, which triggered unnecessary file rewrites even when
catalog values hadn't changed.

The fix ensures shouldBeUpdated is only set when:

  • A catalog value actually changes
  • A new catalog is being added

I've verified that the test you added (updateWorkspaceManifest preserves quotes) now passes, and I've also confirmed the fix works with an actual pnpm update command.

When you have a moment, could you please take another look? I'd really appreciate your feedback.

@zkochan zkochan merged commit 4f66fbe into pnpm:main Jan 26, 2026
11 of 12 checks passed
@welcome
Copy link
Copy Markdown

welcome bot commented Jan 26, 2026

Congrats on merging your first pull request! 🎉🎉🎉

zkochan added a commit that referenced this pull request Feb 6, 2026
….yaml when updating catalogs (#10430)

* fix(workspace.manifest-writer): preserve yaml formatting in pnpm-workspace.yaml

Ensure that the original formatting (quotes, etc.) in pnpm-workspace.yaml
is preserved when running commands like \`pnpm update\`.

Close #10425

* docs: add changeset

* fix(workspace/manifest-writer): restore formats

* test: manifest writer preservers quotes in catalogs

* fix(workspace.manifest-writer): only update catalog when values change

* fix: remove redundant code

* test: adding catalog

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
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.

pnpm commands (e.g. pnpm update) do not preserve pnpm-workspace.yaml formatting

2 participants