From 23754c7a3d9e1004cbfdab38978d8c8e7ece0905 Mon Sep 17 00:00:00 2001 From: "R.P. Pedraza" Date: Wed, 26 Feb 2025 18:42:28 +0800 Subject: [PATCH] fix: updateWorkspaceManifest not writing to manifest file (#9171) * fix: updateWorkspaceManifest not writing to manifest file close #9168 * fix: updating fields in pnpm-workspace.yaml * refactor: import statement --------- Co-authored-by: Zoltan Kochan --- .changeset/fifty-trainers-unite.md | 6 ++++++ pnpm-lock.yaml | 9 +++++++++ workspace/manifest-writer/package.json | 12 ++++++++---- workspace/manifest-writer/src/index.ts | 6 ++++-- workspace/manifest-writer/test/tsconfig.json | 17 +++++++++++++++++ .../test/updateWorkspaceManifest.test.ts | 19 +++++++++++++++++++ workspace/manifest-writer/tsconfig.json | 6 ++++++ 7 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 .changeset/fifty-trainers-unite.md create mode 100644 workspace/manifest-writer/test/tsconfig.json create mode 100644 workspace/manifest-writer/test/updateWorkspaceManifest.test.ts diff --git a/.changeset/fifty-trainers-unite.md b/.changeset/fifty-trainers-unite.md new file mode 100644 index 0000000000..deb2b16bc5 --- /dev/null +++ b/.changeset/fifty-trainers-unite.md @@ -0,0 +1,6 @@ +--- +"@pnpm/workspace.manifest-writer": patch +"pnpm": patch +--- + +Fix the update of `pnpm-workspace.yaml` by the `pnpm approve-builds` command [#9168](https://github.com/pnpm/pnpm/issues/9168). diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e070021ce5..999d346827 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8048,6 +8048,9 @@ importers: workspace/manifest-writer: dependencies: + '@pnpm/constants': + specifier: workspace:* + version: link:../../packages/constants '@pnpm/workspace.read-manifest': specifier: workspace:* version: link:../read-manifest @@ -8055,9 +8058,15 @@ importers: specifier: 'catalog:' version: 5.0.0 devDependencies: + '@pnpm/prepare-temp-dir': + specifier: workspace:* + version: link:../../__utils__/prepare-temp-dir '@pnpm/workspace.manifest-writer': specifier: workspace:* version: 'link:' + read-yaml-file: + specifier: 'catalog:' + version: 2.1.0 workspace/pkgs-graph: dependencies: diff --git a/workspace/manifest-writer/package.json b/workspace/manifest-writer/package.json index 83cc8168d5..000f96caac 100644 --- a/workspace/manifest-writer/package.json +++ b/workspace/manifest-writer/package.json @@ -12,10 +12,11 @@ "node": ">=18.12" }, "scripts": { - "lint": "eslint \"src/**/*.ts\"", - "test": "pnpm run compile", + "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", + "test": "pnpm run compile && pnpm run _test", "prepublishOnly": "pnpm run compile", - "compile": "tsc --build && pnpm run lint --fix" + "compile": "tsc --build && pnpm run lint --fix", + "_test": "jest" }, "repository": "https://github.com/pnpm/pnpm/blob/main/workspace/manifest-writer", "keywords": [ @@ -28,12 +29,15 @@ }, "homepage": "https://github.com/pnpm/pnpm/blob/main/workspace/manifest-writer#readme", "dependencies": { + "@pnpm/constants": "workspace:*", "@pnpm/workspace.read-manifest": "workspace:*", "write-yaml-file": "catalog:" }, "funding": "https://opencollective.com/pnpm", "devDependencies": { - "@pnpm/workspace.manifest-writer": "workspace:*" + "@pnpm/prepare-temp-dir": "workspace:*", + "@pnpm/workspace.manifest-writer": "workspace:*", + "read-yaml-file": "catalog:" }, "exports": { ".": "./lib/index.js" diff --git a/workspace/manifest-writer/src/index.ts b/workspace/manifest-writer/src/index.ts index 61d29c3c3d..558a8b7089 100644 --- a/workspace/manifest-writer/src/index.ts +++ b/workspace/manifest-writer/src/index.ts @@ -1,10 +1,12 @@ +import path from 'path' import { readWorkspaceManifest, type WorkspaceManifest } from '@pnpm/workspace.read-manifest' +import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants' import writeYamlFile from 'write-yaml-file' export async function updateWorkspaceManifest (dir: string, updatedFields: Partial): Promise { const manifest = await readWorkspaceManifest(dir) - await writeYamlFile(dir, { + await writeYamlFile(path.join(dir, WORKSPACE_MANIFEST_FILENAME), { ...manifest, - updatedFields, + ...updatedFields, }) } diff --git a/workspace/manifest-writer/test/tsconfig.json b/workspace/manifest-writer/test/tsconfig.json new file mode 100644 index 0000000000..74036126c6 --- /dev/null +++ b/workspace/manifest-writer/test/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "../test.lib", + "rootDir": "." + }, + "include": [ + "**/*.ts", + "../../../__typings__/**/*.d.ts" + ], + "references": [ + { + "path": ".." + } + ] +} diff --git a/workspace/manifest-writer/test/updateWorkspaceManifest.test.ts b/workspace/manifest-writer/test/updateWorkspaceManifest.test.ts new file mode 100644 index 0000000000..497cbf6fe1 --- /dev/null +++ b/workspace/manifest-writer/test/updateWorkspaceManifest.test.ts @@ -0,0 +1,19 @@ +import path from 'path' +import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants' +import { tempDir } from '@pnpm/prepare-temp-dir' +import { updateWorkspaceManifest } from '@pnpm/workspace.manifest-writer' +import { sync as readYamlFile } from 'read-yaml-file' +import { sync as writeYamlFile } from 'write-yaml-file' + +test('updateWorkspaceManifest', async () => { + const dir = tempDir(false) + const filePath = path.join(dir, WORKSPACE_MANIFEST_FILENAME) + writeYamlFile(filePath, { packages: ['*'] }) + await updateWorkspaceManifest(dir, { + onlyBuiltDependencies: [], + }) + expect(readYamlFile(filePath)).toStrictEqual({ + packages: ['*'], + onlyBuiltDependencies: [], + }) +}) diff --git a/workspace/manifest-writer/tsconfig.json b/workspace/manifest-writer/tsconfig.json index ef43e9ee20..aa058c6ff8 100644 --- a/workspace/manifest-writer/tsconfig.json +++ b/workspace/manifest-writer/tsconfig.json @@ -9,6 +9,12 @@ "../../__typings__/**/*.d.ts" ], "references": [ + { + "path": "../../__utils__/prepare-temp-dir" + }, + { + "path": "../../packages/constants" + }, { "path": "../read-manifest" }