mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
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:
6
.changeset/free-chairs-cough.md
Normal file
6
.changeset/free-chairs-cough.md
Normal 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
3
pnpm-lock.yaml
generated
@@ -8270,6 +8270,9 @@ importers:
|
|||||||
'@pnpm/constants':
|
'@pnpm/constants':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../packages/constants
|
version: link:../../packages/constants
|
||||||
|
'@pnpm/object.key-sorting':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../object/key-sorting
|
||||||
'@pnpm/workspace.read-manifest':
|
'@pnpm/workspace.read-manifest':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../read-manifest
|
version: link:../read-manifest
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pnpm/constants": "workspace:*",
|
"@pnpm/constants": "workspace:*",
|
||||||
|
"@pnpm/object.key-sorting": "workspace:*",
|
||||||
"@pnpm/workspace.read-manifest": "workspace:*",
|
"@pnpm/workspace.read-manifest": "workspace:*",
|
||||||
"ramda": "catalog:",
|
"ramda": "catalog:",
|
||||||
"write-yaml-file": "catalog:"
|
"write-yaml-file": "catalog:"
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import { readWorkspaceManifest, type WorkspaceManifest } from '@pnpm/workspace.r
|
|||||||
import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants'
|
import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants'
|
||||||
import writeYamlFile from 'write-yaml-file'
|
import writeYamlFile from 'write-yaml-file'
|
||||||
import equals from 'ramda/src/equals'
|
import equals from 'ramda/src/equals'
|
||||||
|
import { sortKeysByPriority } from '@pnpm/object.key-sorting'
|
||||||
|
|
||||||
export async function updateWorkspaceManifest (dir: string, updatedFields: Partial<WorkspaceManifest>): Promise<void> {
|
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
|
let shouldBeUpdated = false
|
||||||
for (const [key, value] of Object.entries(updatedFields)) {
|
for (const [key, value] of Object.entries(updatedFields)) {
|
||||||
if (!equals(manifest[key as keyof WorkspaceManifest], value)) {
|
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))
|
await fs.promises.rm(path.join(dir, WORKSPACE_MANIFEST_FILENAME))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
manifest = sortKeysByPriority({
|
||||||
|
priority: { packages: 0 },
|
||||||
|
deep: false,
|
||||||
|
}, manifest)
|
||||||
await writeYamlFile(path.join(dir, WORKSPACE_MANIFEST_FILENAME), manifest, {
|
await writeYamlFile(path.join(dir, WORKSPACE_MANIFEST_FILENAME), manifest, {
|
||||||
lineWidth: -1, // This is setting line width to never wrap
|
lineWidth: -1, // This is setting line width to never wrap
|
||||||
blankLines: true,
|
blankLines: true,
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
{
|
{
|
||||||
"path": "../../__utils__/prepare-temp-dir"
|
"path": "../../__utils__/prepare-temp-dir"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "../../object/key-sorting"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "../../packages/constants"
|
"path": "../../packages/constants"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user