@@ -18,6 +18,7 @@ import {
18
18
run ,
19
19
writeChangelog
20
20
} from './utils'
21
+ import { NonZeroExitError } from 'tinyexec'
21
22
22
23
import type { Logger , PackageJson } from './utils'
23
24
@@ -26,8 +27,8 @@ const isDryRun = args.dry
26
27
const skipBuild = args . skipBuild
27
28
const skipChangelog = args . skipChangelog
28
29
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 )
31
32
const runIfNotDry = isDryRun ? dryRun : run
32
33
33
34
async function releasePackage ( log : Logger ) {
@@ -84,7 +85,7 @@ async function releasePackage(log: Logger) {
84
85
}
85
86
86
87
log ( 'Generating changelog...' )
87
- let changelog : string | null = null
88
+ let changelog : string | undefined
88
89
if ( ! skipChangelog ) {
89
90
changelog = await renderChangelog ( fromTag , releaseVersion , pkgName )
90
91
if ( ! isDryRun ) {
@@ -106,7 +107,7 @@ async function releasePackage(log: Logger) {
106
107
}
107
108
108
109
log ( 'Publishing package...' )
109
- await publishPackage ( targetVersion , pkgName , runIfNotDry )
110
+ await publishPackage ( targetVersion , pkgName )
110
111
111
112
log ( 'Pushing tag to GitHub...' )
112
113
await runIfNotDry ( 'git' , [ 'tag' , tag ] )
@@ -120,7 +121,7 @@ async function releasePackage(log: Logger) {
120
121
tag ,
121
122
releaseVersion ,
122
123
changelog ,
123
- isPrelease ( targetVersion )
124
+ isPrerelease ( targetVersion )
124
125
)
125
126
} else {
126
127
console . log ( `(skipped)` )
@@ -152,7 +153,7 @@ async function updateVersion(
152
153
return await fs . writeFile ( pkgPath , JSON . stringify ( pkg , null , 2 ) + '\n' )
153
154
}
154
155
155
- async function publishPackage ( version : string , pkgName : string , runIfNotDry ) {
156
+ async function publishPackage ( version : string , pkgName : string ) {
156
157
const publicArgs = [ 'publish' , '--access' , 'public' , '--no-git-checks' ]
157
158
if ( args . tag ) {
158
159
publicArgs . push ( `--tag` , args . tag )
@@ -162,15 +163,18 @@ async function publishPackage(version: string, pkgName: string, runIfNotDry) {
162
163
console . log ( chalk . green ( `Successfully published ${ pkgName } @${ version } ` ) )
163
164
} catch ( e ) {
164
165
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
+ ) {
166
170
console . log ( chalk . red ( `Skipping already published: ${ pkgName } ` ) )
167
171
} else {
168
172
throw e
169
173
}
170
174
}
171
175
}
172
176
173
- function isPrelease ( version : string ) {
177
+ function isPrerelease ( version : string ) {
174
178
return (
175
179
version . includes ( 'beta' ) ||
176
180
version . includes ( 'alpha' ) ||
0 commit comments