@@ -5,10 +5,10 @@ import path from 'node:path';
55const root = process . cwd ( ) ;
66const [ command , ...options ] = process . argv . slice ( 2 ) ;
77if (
8- ! [ 'sync' , 'check' , 'pack' ] . includes ( command ) ||
8+ ! [ 'sync' , 'check' , 'pack' , 'publish' ] . includes ( command ) ||
99 options . some ( ( option ) => option !== '--stage' )
1010) {
11- throw new Error ( 'Usage: node scripts/release-workspace.mjs <sync|check|pack> [--stage]' ) ;
11+ throw new Error ( 'Usage: node scripts/release-workspace.mjs <sync|check|pack|publish > [--stage]' ) ;
1212}
1313const packages = JSON . parse (
1414 execFileSync ( 'pnpm' , [ 'list' , '--recursive' , '--depth' , '-1' , '--json' ] , {
@@ -39,6 +39,7 @@ if (command === 'sync') {
3939 }
4040 }
4141 if ( command === 'pack' ) packWorkspacePackages ( ) ;
42+ if ( command === 'publish' ) publishWorkspacePackages ( ) ;
4243}
4344
4445function syncVersions ( ) {
@@ -63,9 +64,9 @@ function packWorkspacePackages() {
6364 destination ,
6465 `${ pkg . manifest . name . replace ( '@' , '' ) . replace ( '/' , '-' ) } -${ version } .tgz` ,
6566 ) ;
66- const args = [ 'pack' , '--out' , tarball ] ;
67- if ( pkg . directory === root ) args . push ( '--config.ignore-scripts=true' ) ;
68- execFileSync ( 'pnpm' , args , { cwd : pkg . directory , stdio : 'inherit' } ) ;
67+ if ( pkg . directory !== root ) {
68+ execFileSync ( 'pnpm' , [ 'pack' , '--out' , tarball ] , { cwd : pkg . directory , stdio : 'inherit' } ) ;
69+ }
6970 const packed = JSON . parse (
7071 execFileSync ( 'tar' , [ '-xOf' , tarball , 'package/package.json' ] , { encoding : 'utf8' } ) ,
7172 ) ;
@@ -100,3 +101,36 @@ function checkPackedIdentity(packed, name) {
100101 throw new Error ( 'Packed package identity differs from the synchronized public package.' ) ;
101102 }
102103}
104+
105+ function publishWorkspacePackages ( ) {
106+ const dryRun = process . env . npm_config_dry_run === 'true' ;
107+ const args = [
108+ '--recursive' ,
109+ '--include-workspace-root' ,
110+ 'publish' ,
111+ '--access' ,
112+ 'public' ,
113+ '--no-git-checks' ,
114+ '--ignore-scripts' ,
115+ ] ;
116+ if ( process . env . npm_lifecycle_event === 'postpublish' ) {
117+ args . push ( '--filter' , `!${ rootPackage . manifest . name } ` ) ;
118+ }
119+ if ( dryRun ) args . push ( '--dry-run' ) ;
120+ execFileSync ( 'pnpm' , args , { cwd : root , stdio : 'inherit' } ) ;
121+ if ( dryRun ) return ;
122+ execFileSync ( process . execPath , [ 'scripts/release-mark-dev.mjs' ] , { cwd : root , stdio : 'inherit' } ) ;
123+ execFileSync (
124+ 'git' ,
125+ [
126+ 'commit' ,
127+ '--only' ,
128+ '-m' ,
129+ `chore: mark ${ version } as released` ,
130+ '--' ,
131+ ...publicPackages . map ( ( pkg ) => pkg . manifestPath ) ,
132+ path . join ( root , 'server.json' ) ,
133+ ] ,
134+ { cwd : root , stdio : 'inherit' } ,
135+ ) ;
136+ }
0 commit comments