refactor: workspace setting sorted by key (#9453)

* refactor: workspace setting sorted by key

* fix: always put the packages field as the first one in pnpm-workspace.yaml

* docs: add changeset

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
btea
2025-04-25 18:51:15 +08:00
committed by GitHub
parent 7c7f0d6bf1
commit 2bcb40247c
5 changed files with 19 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/workspace.manifest-writer": patch
"pnpm": patch
---
Sort keys in `pnpm-workspace.yaml` [#9453](https://github.com/pnpm/pnpm/pull/9453).

3
pnpm-lock.yaml generated
View File

@@ -8270,6 +8270,9 @@ importers:
'@pnpm/constants':
specifier: workspace:*
version: link:../../packages/constants
'@pnpm/object.key-sorting':
specifier: workspace:*
version: link:../../object/key-sorting
'@pnpm/workspace.read-manifest':
specifier: workspace:*
version: link:../read-manifest

View File

@@ -31,6 +31,7 @@
},
"dependencies": {
"@pnpm/constants": "workspace:*",
"@pnpm/object.key-sorting": "workspace:*",
"@pnpm/workspace.read-manifest": "workspace:*",
"ramda": "catalog:",
"write-yaml-file": "catalog:"

View File

@@ -4,9 +4,10 @@ import { readWorkspaceManifest, type WorkspaceManifest } from '@pnpm/workspace.r
import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants'
import writeYamlFile from 'write-yaml-file'
import equals from 'ramda/src/equals'
import { sortKeysByPriority } from '@pnpm/object.key-sorting'
export async function updateWorkspaceManifest (dir: string, updatedFields: Partial<WorkspaceManifest>): Promise<void> {
const manifest = await readWorkspaceManifest(dir) ?? {} as WorkspaceManifest
let manifest = await readWorkspaceManifest(dir) ?? {} as WorkspaceManifest
let shouldBeUpdated = false
for (const [key, value] of Object.entries(updatedFields)) {
if (!equals(manifest[key as keyof WorkspaceManifest], value)) {
@@ -26,6 +27,10 @@ export async function updateWorkspaceManifest (dir: string, updatedFields: Parti
await fs.promises.rm(path.join(dir, WORKSPACE_MANIFEST_FILENAME))
return
}
manifest = sortKeysByPriority({
priority: { packages: 0 },
deep: false,
}, manifest)
await writeYamlFile(path.join(dir, WORKSPACE_MANIFEST_FILENAME), manifest, {
lineWidth: -1, // This is setting line width to never wrap
blankLines: true,

View File

@@ -12,6 +12,9 @@
{
"path": "../../__utils__/prepare-temp-dir"
},
{
"path": "../../object/key-sorting"
},
{
"path": "../../packages/constants"
},