From e84f668025a40e56506f6fbffb7e71c42a59a4e5 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 12 Aug 2024 12:42:09 +0200 Subject: [PATCH] fix: only write to `pnpm-workspace.yaml` when changed, close #131 --- src/io/pnpmWorkspaces.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/io/pnpmWorkspaces.ts b/src/io/pnpmWorkspaces.ts index 26609da..4da52a7 100644 --- a/src/io/pnpmWorkspaces.ts +++ b/src/io/pnpmWorkspaces.ts @@ -59,13 +59,22 @@ export async function writePnpmWorkspace( if (!Object.keys(versions).length) return + let changed = false + if (catalogName === 'default') { - pkg.raw.catalog = versions + if (JSON.stringify(pkg.raw.catalog) !== JSON.stringify(versions)) { + pkg.raw.catalog = versions + changed = true + } } else { pkg.raw.catalogs ??= {} - pkg.raw.catalogs[catalogName] = versions + if (pkg.raw.catalogs[catalogName] !== versions) { + pkg.raw.catalogs[catalogName] = versions + changed = true + } } - await fs.writeFile(pkg.filepath, YAML.dump(pkg.raw), 'utf-8') + if (changed) + await fs.writeFile(pkg.filepath, YAML.dump(pkg.raw), 'utf-8') }