@@ -18,6 +18,7 @@ import {
1818 run ,
1919 writeChangelog
2020} from './utils'
21+ import { NonZeroExitError } from 'tinyexec'
2122
2223import type { Logger , PackageJson } from './utils'
2324
@@ -26,8 +27,8 @@ const isDryRun = args.dry
2627const skipBuild = args . skipBuild
2728const skipChangelog = args . skipChangelog
2829
29- const dryRun = ( bin , args , opts = { } ) =>
30- console . log ( chalk . yellow ( `[dryrun] ${ bin } ${ args . join ( ' ' ) } ` ) , opts )
30+ const dryRun = ( command : string , args : string [ ] = [ ] , opts = { } ) =>
31+ console . log ( chalk . yellow ( `[dryrun] ${ command } ${ args . join ( ' ' ) } ` ) , opts )
3132const runIfNotDry = isDryRun ? dryRun : run
3233
3334async function releasePackage ( log : Logger ) {
@@ -84,7 +85,7 @@ async function releasePackage(log: Logger) {
8485 }
8586
8687 log ( 'Generating changelog...' )
87- let changelog : string | null = null
88+ let changelog : string | undefined
8889 if ( ! skipChangelog ) {
8990 changelog = await renderChangelog ( fromTag , releaseVersion , pkgName )
9091 if ( ! isDryRun ) {
@@ -106,7 +107,7 @@ async function releasePackage(log: Logger) {
106107 }
107108
108109 log ( 'Publishing package...' )
109- await publishPackage ( targetVersion , pkgName , runIfNotDry )
110+ await publishPackage ( targetVersion , pkgName )
110111
111112 log ( 'Pushing tag to GitHub...' )
112113 await runIfNotDry ( 'git' , [ 'tag' , tag ] )
@@ -120,7 +121,7 @@ async function releasePackage(log: Logger) {
120121 tag ,
121122 releaseVersion ,
122123 changelog ,
123- isPrelease ( targetVersion )
124+ isPrerelease ( targetVersion )
124125 )
125126 } else {
126127 console . log ( `(skipped)` )
@@ -152,7 +153,7 @@ async function updateVersion(
152153 return await fs . writeFile ( pkgPath , JSON . stringify ( pkg , null , 2 ) + '\n' )
153154}
154155
155- async function publishPackage ( version : string , pkgName : string , runIfNotDry ) {
156+ async function publishPackage ( version : string , pkgName : string ) {
156157 const publicArgs = [ 'publish' , '--access' , 'public' , '--no-git-checks' ]
157158 if ( args . tag ) {
158159 publicArgs . push ( `--tag` , args . tag )
@@ -162,15 +163,18 @@ async function publishPackage(version: string, pkgName: string, runIfNotDry) {
162163 console . log ( chalk . green ( `Successfully published ${ pkgName } @${ version } ` ) )
163164 } catch ( e ) {
164165 console . error ( e )
165- if ( e . stderr . match ( / p r e v i o u s l y p u b l i s h e d / ) ) {
166+ if (
167+ e instanceof NonZeroExitError &&
168+ e . output ?. stderr . match ( / p r e v i o u s l y p u b l i s h e d / )
169+ ) {
166170 console . log ( chalk . red ( `Skipping already published: ${ pkgName } ` ) )
167171 } else {
168172 throw e
169173 }
170174 }
171175}
172176
173- function isPrelease ( version : string ) {
177+ function isPrerelease ( version : string ) {
174178 return (
175179 version . includes ( 'beta' ) ||
176180 version . includes ( 'alpha' ) ||
0 commit comments