mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
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:
8
.changeset/solid-eagles-mate.md
Normal file
8
.changeset/solid-eagles-mate.md
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user