Skip to content

Commit a4fb810

Browse files
devjiwonchoieps1lon
andcommitted
rely on json output
Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
1 parent 4de869a commit a4fb810

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

scripts/release/version-packages.ts

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
import execa from 'execa'
2-
import { existsSync } from 'node:fs'
3-
import { writeFile } from 'node:fs/promises'
4-
import { join } from 'node:path'
2+
import { existsSync } from 'fs'
3+
import { writeFile, readFile, unlink } from 'fs/promises'
4+
import { join } from 'path'
5+
6+
// NOTE: This type may change over time.
7+
type ChangesetStatusJson = {
8+
changesets: {
9+
releases: {
10+
name: string
11+
type: string
12+
summary: string
13+
id: string
14+
}[]
15+
}[]
16+
releases: {
17+
name: string
18+
type: string
19+
oldVersion: string
20+
changesets: string[]
21+
newVersion: string
22+
}[]
23+
}
524

625
async function versionPackages() {
726
const preConfigPath = join(process.cwd(), '.changeset', 'pre.json')
@@ -28,18 +47,33 @@ async function versionPackages() {
2847
console.log(
2948
'▲ Preparing to bump the canary version, checking if there are any changesets.'
3049
)
50+
3151
// Create an empty changeset for `next` to bump the canary version
3252
// even if there are no changesets for `next`.
33-
const res = await execa('pnpm', ['changeset', 'status'], {
34-
// If there are no changesets, this will error. Set reject: false
35-
// to avoid trycatch and handle the rest based on the stdout.
36-
reject: false,
37-
})
53+
await execa('pnpm', [
54+
'changeset',
55+
'status',
56+
'--output',
57+
'./changeset-status.json',
58+
])
3859

39-
console.log('▲ Changeset Status:')
40-
console.log({ ...res })
60+
let hasNextChangeset = false
61+
if (existsSync('./changeset-status.json')) {
62+
const changesetStatus: ChangesetStatusJson = JSON.parse(
63+
await readFile('./changeset-status.json', 'utf8')
64+
)
65+
66+
console.log('▲ Changeset Status:')
67+
console.log(changesetStatus)
68+
69+
hasNextChangeset =
70+
changesetStatus.releases.find((release) => release.name === 'next') !==
71+
undefined
72+
73+
await unlink('./changeset-status.json')
74+
}
4175

42-
if (!res.stdout.includes('- next')) {
76+
if (!hasNextChangeset) {
4377
console.log(
4478
'▲ No changesets found for `next`, creating an empty changeset.'
4579
)
@@ -55,6 +89,8 @@ async function versionPackages() {
5589
await execa('pnpm', ['changeset', 'version'], {
5690
stdio: 'inherit',
5791
})
92+
// TODO: Update the pnpm-lock.yaml since the packages' depend on
93+
// each other. Remove this once they use `workspace:` protocol.
5894
await execa('pnpm', ['install', '--no-frozen-lockfile'], {
5995
stdio: 'inherit',
6096
})

0 commit comments

Comments
 (0)