1313 */
1414
1515import { execSync , spawnSync } from 'node:child_process'
16- import { existsSync , readdirSync , readFileSync } from 'node:fs'
16+ import { existsSync , readdirSync , readFileSync , writeFileSync } from 'node:fs'
1717import { join , relative } from 'node:path'
1818import { fileURLToPath } from 'node:url'
1919
@@ -88,7 +88,28 @@ function getReleasablePackages() {
8888}
8989
9090/**
91- * Wait for a package to appear on npm, then update its version across the monorepo.
91+ * Bump a package's version in the pnpm-workspace.yaml catalog. Returns true on
92+ * success. Other workspace packages depend on this package via "catalog:", so
93+ * updating the catalog is what makes pnpm publish resolve to the new version.
94+ */
95+ function updateCatalogVersion ( name , newVersion ) {
96+ const yamlPath = join ( root , 'pnpm-workspace.yaml' )
97+ const content = readFileSync ( yamlPath , 'utf-8' )
98+ const escaped = name . replace ( / \. / g, '\\.' )
99+ const re = new RegExp ( `^(\\s*"?${ escaped } "?\\s*:\\s*)\\^?[^\\s#]+` , 'm' )
100+ if ( ! re . test ( content ) ) {
101+ console . error ( ` Could not find catalog entry for ${ name } in pnpm-workspace.yaml` )
102+ return false
103+ }
104+ const updated = content . replace ( re , `$1^${ newVersion } ` )
105+ if ( updated === content ) return false
106+ writeFileSync ( yamlPath , updated )
107+ return true
108+ }
109+
110+ /**
111+ * Wait for a package to appear on npm, then bump its catalog entry so the next
112+ * package release picks up the new version through pnpm's catalog resolution.
92113 */
93114function waitAndUpdateDependents ( pkg ) {
94115 const newVersion = JSON . parse ( readFileSync ( join ( pkg . dir , 'package.json' ) , 'utf-8' ) ) . version
@@ -112,21 +133,21 @@ function waitAndUpdateDependents(pkg) {
112133 }
113134
114135 if ( ! available ) {
115- console . error ( `\n${ pkg . name } @${ newVersion } did not appear on npm after ${ maxAttempts } attempts. Skipping dependency update .` )
136+ console . error ( `\n${ pkg . name } @${ newVersion } did not appear on npm after ${ maxAttempts } attempts. Skipping catalog bump .` )
116137 return
117138 }
118139
119- console . log ( `Updating ${ pkg . name } version in all packages...\n` )
120- const ncuResult = spawnSync ( 'npx' , [ 'npm-check-updates' , '-u' , '--deep' , '--filter' , pkg . name ] , {
121- cwd : root ,
122- stdio : 'inherit' ,
123- env : process . env ,
124- } )
125- if ( ncuResult . status === 0 ) {
126- spawnSync ( 'pnpm' , [ 'install' ] , { cwd : root , stdio : 'inherit' , env : process . env } )
127- spawnSync ( 'git' , [ 'add' , '-A' ] , { cwd : root , stdio : 'inherit' , env : process . env } )
128- spawnSync ( 'git' , [ 'commit' , '-m' , `chore(deps): update ${ pkg . name } to v${ newVersion } ` ] , { cwd : root , stdio : 'inherit' , env : process . env } )
140+ console . log ( `Bumping ${ pkg . name } catalog entry to ^${ newVersion } ...\n` )
141+ if ( ! updateCatalogVersion ( pkg . name , newVersion ) ) return
142+
143+ const installResult = spawnSync ( 'pnpm' , [ 'install' ] , { cwd : root , stdio : 'inherit' , env : process . env } )
144+ if ( installResult . status !== 0 ) {
145+ console . error ( ` pnpm install failed; leaving catalog change uncommitted.` )
146+ return
129147 }
148+
149+ spawnSync ( 'git' , [ 'add' , 'pnpm-workspace.yaml' , 'pnpm-lock.yaml' ] , { cwd : root , stdio : 'inherit' , env : process . env } )
150+ spawnSync ( 'git' , [ 'commit' , '-m' , `chore(deps): bump ${ pkg . name } catalog to v${ newVersion } ` ] , { cwd : root , stdio : 'inherit' , env : process . env } )
130151}
131152
132153// --- Main ---
0 commit comments