Skip to content

Commit 3a20974

Browse files
committed
feat: initial support for monorepo with single changelog
1 parent aa23c85 commit 3a20974

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

bin/updateVersion.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const HEADER = `# Changelog\n\nAll notable changes to this project will be docum
3838
const execPromise = (command) => new Promise((r) => exec(command, (e, out) => (e && r(e)) || r(out)))
3939

4040
const packageFile = JSON.parse(await readFile('./package.json', { encoding: 'utf-8' }))
41+
const isMonoRepo = !!packageFile.workspaces
4142

4243
if (!packageFile.homepage) {
4344
console.error('No repository homepage specified in the package.json, exiting...')
@@ -159,14 +160,23 @@ if (!cli.flags.dryRun) {
159160

160161
// update the package.json
161162
if (existsSync('.yarn')) {
162-
// yarn 3 needs a different command
163-
await execPromise('yarn version ' + nextVersion)
163+
if (isMonoRepo) {
164+
// Update all workspaces
165+
await execPromise('yarn workspaces foreach --all version -d ' + nextVersion)
166+
await execPromise('yarn version apply --all')
167+
} else {
168+
// yarn 3 needs a different command
169+
await execPromise('yarn version ' + nextVersion)
170+
}
164171
} else {
165172
await execPromise('yarn version --no-git-tag-version --new-version ' + nextVersion)
166173
}
167174

168175
// git commit
169176
await execPromise(`git add package.json yarn.lock CHANGELOG.md`)
177+
if (isMonoRepo) {
178+
await execPromise(`git add */package.json`)
179+
}
170180

171181
await execPromise(`git commit -m "chore(release): v${nextVersion}"`)
172182

0 commit comments

Comments
 (0)