@@ -14,7 +14,7 @@ function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
1414 cwd : rootDir ,
1515 absolute : true ,
1616 } ) ;
17- matches . forEach ( ( f ) => files . add ( f ) ) ;
17+ matches . filter ( ( f ) => ! f . includes ( 'node_modules' ) ) . forEach ( ( f ) => files . add ( f ) ) ;
1818 }
1919 return Array . from ( files ) ;
2020}
@@ -28,16 +28,27 @@ function incrementVersion(version: string): string {
2828 return parts . join ( '.' ) ;
2929}
3030
31+ // find all package.json files in the workspace
3132const workspaceFile = path . resolve ( __dirname , '../pnpm-workspace.yaml' ) ;
3233const packageFiles = getWorkspacePackageJsonFiles ( workspaceFile ) ;
3334
35+ // get version from root package.json
36+ const rootPackageJson = path . resolve ( __dirname , '../package.json' ) ;
37+ const rootPkg = JSON . parse ( fs . readFileSync ( rootPackageJson , 'utf8' ) ) as { version ?: string } ;
38+ if ( ! rootPkg . version ) throw new Error ( 'No "version" key found in package.json' ) ;
39+ const rootVersion = rootPkg . version ;
40+ const newVersion = incrementVersion ( rootVersion ) ;
41+
3442for ( const file of packageFiles ) {
3543 const content = fs . readFileSync ( file , 'utf8' ) ;
3644 const pkg = JSON . parse ( content ) as { version ?: string } ;
3745 if ( pkg . version ) {
3846 const oldVersion = pkg . version ;
39- pkg . version = incrementVersion ( pkg . version ) ;
40- fs . writeFileSync ( file , JSON . stringify ( pkg , null , 2 ) + '\n' ) ;
41- console . log ( `Updated ${ file } : ${ oldVersion } -> ${ pkg . version } ` ) ;
47+ const newVersion = incrementVersion ( pkg . version ) ;
48+ // do a string replace from oldVersion to newVersion
49+ const newContent = content . replace ( `"version": "${ oldVersion } "` , `"version": "${ newVersion } "` ) ;
50+ fs . writeFileSync ( file , newContent ) ;
4251 }
4352}
53+
54+ console . log ( `new_version=${ newVersion } ` ) ;
0 commit comments