1
1
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
+ }
5
24
6
25
async function versionPackages ( ) {
7
26
const preConfigPath = join ( process . cwd ( ) , '.changeset' , 'pre.json' )
@@ -28,18 +47,33 @@ async function versionPackages() {
28
47
console . log (
29
48
'▲ Preparing to bump the canary version, checking if there are any changesets.'
30
49
)
50
+
31
51
// Create an empty changeset for `next` to bump the canary version
32
52
// 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
+ ] )
38
59
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
+ }
41
75
42
- if ( ! res . stdout . includes ( '- next' ) ) {
76
+ if ( ! hasNextChangeset ) {
43
77
console . log (
44
78
'▲ No changesets found for `next`, creating an empty changeset.'
45
79
)
@@ -55,6 +89,8 @@ async function versionPackages() {
55
89
await execa ( 'pnpm' , [ 'changeset' , 'version' ] , {
56
90
stdio : 'inherit' ,
57
91
} )
92
+ // TODO: Update the pnpm-lock.yaml since the packages' depend on
93
+ // each other. Remove this once they use `workspace:` protocol.
58
94
await execa ( 'pnpm' , [ 'install' , '--no-frozen-lockfile' ] , {
59
95
stdio : 'inherit' ,
60
96
} )
0 commit comments