@@ -53,14 +53,14 @@ export function assertPublishEnvironment(
5353}
5454
5555export function inferDistTag ( version : string ) : string | undefined {
56- const prerelease = version . match ( / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + - ( [ 0 - 9 A - Z a - z - ] + ) (?: \. | $ ) / ) ;
56+ const prerelease = version . match ( / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + - ( [ 0 - 9 A - Z a - z ] + ) (?: [ . - ] | $ ) / ) ;
5757 return prerelease ?. [ 1 ] ;
5858}
5959
60- export function publishCommand ( dryRun : boolean , version : string ) : string [ ] {
60+ export function publishCommand ( dryRun : boolean , version : string , distTag ?: string ) : string [ ] {
6161 if ( dryRun ) return [ "npm" , "pack" , "--dry-run" ] ;
6262 const command = [ "npm" , "publish" , "--access" , "public" , "--provenance" ] ;
63- const publishTag = inferDistTag ( version ) ;
63+ const publishTag = distTag ?? inferDistTag ( version ) ;
6464 if ( publishTag ) command . push ( "--tag" , publishTag ) ;
6565 return command ;
6666}
@@ -149,6 +149,11 @@ function trackedFileContents(path: string): string | undefined {
149149function main ( ) : number {
150150 const args = process . argv . slice ( 2 ) ;
151151 const dryRun = args . includes ( "--dry-run" ) ;
152+ const tagIndex = args . indexOf ( "--tag" ) ;
153+ const distTag = tagIndex === - 1 ? undefined : args [ tagIndex + 1 ] ;
154+ if ( tagIndex !== - 1 && ( ! distTag || ! / ^ [ a - z ] [ a - z 0 - 9 - ] * $ / . test ( distTag ) ) ) {
155+ throw new Error ( "--tag must be a lowercase npm dist-tag" ) ;
156+ }
152157 assertPublishEnvironment ( dryRun ) ;
153158
154159 console . log ( `Publishing packages${ dryRun ? " (dry-run)" : "" } ...\n` ) ;
@@ -166,7 +171,7 @@ function main(): number {
166171 continue ;
167172 }
168173
169- const cmd = publishCommand ( dryRun , manifest . version ) ;
174+ const cmd = publishCommand ( dryRun , manifest . version , distTag ) ;
170175
171176 console . log ( `\n--- Publishing ${ manifest . name } ---` ) ;
172177 let originalLicense : string | undefined ;
0 commit comments