@@ -5,12 +5,7 @@ import { parseArgs } from "util";
55import { runCheck } from "./check.mjs" ;
66import { headSha7 , utcDateStamp } from "./lib/git.mjs" ;
77import { npmViewExists , pnpmPublish } from "./lib/npm.mjs" ;
8- import {
9- findPackage ,
10- packageJsonPath ,
11- readPackageJson ,
12- writePackageJson ,
13- } from "./lib/packages.mjs" ;
8+ import { PACKAGES , packageJsonPath , readPackageJson , writePackageJson } from "./lib/packages.mjs" ;
149import { assertChannel } from "./lib/validate.mjs" ;
1510
1611function log ( msg = "" ) {
@@ -37,16 +32,15 @@ if (!dryRun && !process.env.CI) {
3732 process . exit ( 1 ) ;
3833}
3934
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" ) ;
35+ // Snapshot every package.json so the temporary version bump is reverted in
36+ // `finally`, even when the release fails midway.
37+ const originals = PACKAGES . map ( ( pkg ) => {
38+ const path = packageJsonPath ( pkg ) ;
39+ return { pkg , path , content : readFileSync ( path , "utf-8" ) } ;
40+ } ) ;
4641
4742function restoreOriginals ( ) {
48- writeFileSync ( corePath , coreOriginal ) ;
49- writeFileSync ( cliPath , cliOriginal ) ;
43+ for ( const { path, content } of originals ) writeFileSync ( path , content ) ;
5044}
5145
5246try {
@@ -57,32 +51,31 @@ try {
5751 log ( `channel=${ channel } version=${ betaVersion } ` ) ;
5852
5953 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.
54+ for ( const pkg of PACKAGES ) {
55+ const json = readPackageJson ( pkg ) ;
56+ json . version = betaVersion ;
57+ writePackageJson ( pkg , json ) ;
58+ }
59+ // pnpm pack resolves `workspace:*` to the in-tree version, so each tarball
60+ // will depend on its siblings at <betaVersion> after this bump.
6861
6962 await runCheck ( { channel : true } ) ;
7063
7164 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." ) ;
65+ const published = new Map ( ) ;
66+ for ( const pkg of PACKAGES ) {
67+ const exists = npmViewExists ( pkg . name , betaVersion ) ;
68+ published . set ( pkg . key , exists ) ;
69+ log ( `${ pkg . name } @${ betaVersion } : ${ exists ? "already published" : "to publish" } ` ) ;
70+ }
71+ if ( PACKAGES . every ( ( pkg ) => published . get ( pkg . key ) ) ) {
72+ log ( "\nall packages already published; nothing to do." ) ;
7873 } 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 } ) ;
74+ // Publish in dependency order (core → runtime → commands → cli).
75+ for ( const pkg of PACKAGES ) {
76+ if ( published . get ( pkg . key ) ) continue ;
77+ step ( `publish ${ pkg . name } @${ betaVersion } (tag=${ channel } , provenance)` ) ;
78+ pnpmPublish ( pkg , { tag : channel , provenance : true , dryRun } ) ;
8679 }
8780 }
8881
0 commit comments