Skip to content

Commit

Permalink
fix: only write to pnpm-workspace.yaml when changed, close #131
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 12, 2024
1 parent c7b09ad commit e84f668
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/io/pnpmWorkspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

0 comments on commit e84f668

Please sign in to comment.