@@ -6,7 +6,8 @@ import { runCheck } from "./check.mjs";
66import { headSha7 , utcDateStamp } from "./lib/git.mjs" ;
77import { npmViewExists , pnpmPublish } from "./lib/npm.mjs" ;
88import {
9- findPackage ,
9+ ALL_PACKAGES ,
10+ PACKAGES ,
1011 packageJsonPath ,
1112 readPackageJson ,
1213 writePackageJson ,
@@ -25,28 +26,30 @@ const { values } = parseArgs({
2526 options : {
2627 channel : { type : "string" } ,
2728 "dry-run" : { type : "boolean" , default : false } ,
29+ knowledge : { type : "boolean" , default : false } ,
2830 } ,
2931 allowPositionals : false ,
3032} ) ;
3133const channel = values . channel ;
3234const dryRun = values [ "dry-run" ] ;
35+ const knowledge = values . knowledge ;
36+ const packages = knowledge ? ALL_PACKAGES : PACKAGES ;
3337assertChannel ( channel ) ;
3438
3539if ( ! dryRun && ! process . env . CI ) {
3640 process . stderr . write ( "publish-channel is CI-only. Pass --dry-run to test locally.\n" ) ;
3741 process . exit ( 1 ) ;
3842}
3943
40- const core = findPackage ( "core" ) ;
41- const cli = findPackage ( "cli" ) ;
42- const corePath = packageJsonPath ( core ) ;
43- const cliPath = packageJsonPath ( cli ) ;
44- const coreOriginal = readFileSync ( corePath , "utf-8" ) ;
45- const cliOriginal = readFileSync ( cliPath , "utf-8" ) ;
44+ // Snapshot every package.json so the temporary version bump is reverted in
45+ // `finally`, even when the release fails midway.
46+ const originals = packages . map ( ( pkg ) => {
47+ const path = packageJsonPath ( pkg ) ;
48+ return { pkg , path , content : readFileSync ( path , "utf-8" ) } ;
49+ } ) ;
4650
4751function restoreOriginals ( ) {
48- writeFileSync ( corePath , coreOriginal ) ;
49- writeFileSync ( cliPath , cliOriginal ) ;
52+ for ( const { path, content } of originals ) writeFileSync ( path , content ) ;
5053}
5154
5255try {
@@ -57,32 +60,29 @@ try {
5760 log ( `channel=${ channel } version=${ betaVersion } ` ) ;
5861
5962 step ( "temporarily bump package.json (not committed)" ) ;
60- const coreJson = readPackageJson ( core ) ;
61- const cliJson = readPackageJson ( cli ) ;
62- coreJson . version = betaVersion ;
63- cliJson . version = betaVersion ;
64- writePackageJson ( core , coreJson ) ;
65- writePackageJson ( cli , cliJson ) ;
66- // pnpm pack resolves `workspace:*` to the in-tree version, so CLI tarball
67- // will depend on bailian-cli-core@<betaVersion> after this bump.
63+ for ( const pkg of packages ) {
64+ const json = readPackageJson ( pkg ) ;
65+ json . version = betaVersion ;
66+ writePackageJson ( pkg , json ) ;
67+ }
6868
69- await runCheck ( { channel : true } ) ;
69+ await runCheck ( { channel : true , knowledge } ) ;
7070
7171 step ( `idempotency: check ${ betaVersion } against registry` ) ;
72- const corePublished = npmViewExists ( core . name , betaVersion ) ;
73- const cliPublished = npmViewExists ( cli . name , betaVersion ) ;
74- log ( `${ core . name } @${ betaVersion } : ${ corePublished ? "already published" : "to publish" } ` ) ;
75- log ( `${ cli . name } @${ betaVersion } : ${ cliPublished ? "already published" : "to publish" } ` ) ;
76- if ( corePublished && cliPublished ) {
77- log ( "\nboth packages already published; nothing to do." ) ;
72+ const published = new Map ( ) ;
73+ for ( const pkg of packages ) {
74+ const exists = npmViewExists ( pkg . name , betaVersion ) ;
75+ published . set ( pkg . key , exists ) ;
76+ log ( `${ pkg . name } @${ betaVersion } : ${ exists ? "already published" : "to publish" } ` ) ;
77+ }
78+ if ( packages . every ( ( pkg ) => published . get ( pkg . key ) ) ) {
79+ log ( "\nall packages already published; nothing to do." ) ;
7880 } else {
79- if ( ! corePublished ) {
80- step ( `publish ${ core . name } @${ betaVersion } (tag=${ channel } , provenance)` ) ;
81- pnpmPublish ( core , { tag : channel , provenance : true , dryRun } ) ;
82- }
83- if ( ! cliPublished ) {
84- step ( `publish ${ cli . name } @${ betaVersion } (tag=${ channel } , provenance)` ) ;
85- pnpmPublish ( cli , { tag : channel , provenance : true , dryRun } ) ;
81+ // Publish in dependency order.
82+ for ( const pkg of packages ) {
83+ if ( published . get ( pkg . key ) ) continue ;
84+ step ( `publish ${ pkg . name } @${ betaVersion } (tag=${ channel } , provenance)` ) ;
85+ pnpmPublish ( pkg , { tag : channel , provenance : true , dryRun } ) ;
8686 }
8787 }
8888
0 commit comments