fix(workspace.manifest-writer): preserve formatting in pnpm-workspace.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>
This commit is contained in:
Yeom
2026-01-26 15:07:28 +09:00
committed by GitHub
parent 8eee41691c
commit 4f66fbe6fa
3 changed files with 67 additions and 3 deletions

View File

@@ -0,0 +1,8 @@
---
"@pnpm/workspace.manifest-writer": patch
"pnpm": patch
---
Fix YAML formatting preservation in `pnpm-workspace.yaml` when running commands like `pnpm update`. Previously, quotes and other formatting were lost even when catalog values didn't change.
Closes #10425

View File

@@ -115,13 +115,14 @@ function addCatalogs (manifest: Partial<WorkspaceManifest>, newCatalogs: Catalog
}
targetCatalog ??= {}
targetCatalog[dependencyName] = specifier
if (targetCatalog[dependencyName] !== specifier) {
targetCatalog[dependencyName] = specifier
shouldBeUpdated = true
}
}
if (targetCatalog == null) continue
shouldBeUpdated = true
if (targetCatalogWasNil) {
if (catalogName === 'default') {
manifest.catalog = targetCatalog

View File

@@ -98,3 +98,58 @@ test('updateWorkspaceManifest updates allowBuilds', async () => {
},
})
})
test('updateWorkspaceManifest adds a new catalog', async () => {
const dir = tempDir(false)
const filePath = path.join(dir, WORKSPACE_MANIFEST_FILENAME)
fs.writeFileSync(filePath, 'packages:\n - \'*\'\n')
await updateWorkspaceManifest(dir, {
updatedCatalogs: {
default: {
foo: '1.0.0',
},
},
})
expect(readYamlFile(filePath)).toStrictEqual({
packages: ['*'],
catalog: { foo: '1.0.0' },
})
})
test('updateWorkspaceManifest preserves quotes', async () => {
const dir = tempDir(false)
const filePath = path.join(dir, WORKSPACE_MANIFEST_FILENAME)
const manifest = `\
catalog:
"bar": "2.0.0"
'foo': '1.0.0'
qar: 3.0.0
`
const expected = `\
catalog:
"bar": "2.0.0"
'foo': '1.0.0'
qar: 3.0.0
zoo: 4.0.0
`
fs.writeFileSync(filePath, manifest)
await updateWorkspaceManifest(dir, {
updatedCatalogs: {
default: {
foo: '1.0.0',
bar: '2.0.0',
qar: '3.0.0',
zoo: '4.0.0',
},
},
})
expect(fs.readFileSync(filePath).toString()).toStrictEqual(expected)
})