@@ -22,9 +22,14 @@ const validTypes = [
2222 'prepatch' ,
2323 'prerelease' ,
2424]
25- const validPreIds = [ 'alpha' , 'beta' , 'rc' ]
2625
26+ const distTagOverrideFlag = '--dist-tag='
2727const includeChoresFlag = '--chores'
28+
29+ const validDistTags = [ 'canary' , 'latest' , 'lts' , 'next' ]
30+ const validFlags = [ distTagOverrideFlag , includeChoresFlag ]
31+ const validPreIds = [ 'alpha' , 'beta' , 'rc' ]
32+
2833const isNextBranch = branch => / ^ n e x t \/ v \d + \. ( \d + \. ) ? x $ / . test ( branch )
2934const isSupportBranch = branch => / ^ v \d + \. x $ / . test ( branch )
3035
@@ -105,7 +110,7 @@ const assertTokenIsValid = async (email, token) => {
105110/**
106111 * Validate script arguments
107112 */
108- const assertValidArgs = ( type , preId ) => {
113+ const assertValidArgs = ( type , preId , flags ) => {
109114 console . info ( 'Validating arguments' )
110115
111116 if ( ! validTypes . includes ( type ) ) {
@@ -115,12 +120,38 @@ const assertValidArgs = (type, preId) => {
115120 process . exit ( 1 )
116121 }
117122
118- if ( type . startsWith ( 'pre' ) && ! validPreIds . includes ( preId ) ) {
123+ if (
124+ type . startsWith ( 'pre' ) &&
125+ type !== 'prerelease' &&
126+ ! validPreIds . includes ( preId )
127+ ) {
119128 console . error (
120129 `Expected second argument to be one of "${ validPreIds . join ( '", "' ) } "`
121130 )
122131 process . exit ( 1 )
123132 }
133+
134+ const invalidFlag = flags . find (
135+ flag => ! validFlags . some ( validFlag => flag . startsWith ( validFlag ) )
136+ )
137+
138+ if ( invalidFlag ) {
139+ console . error ( `Invalid flag "${ invalidFlag } " found` )
140+ process . exit ( 1 )
141+ }
142+
143+ const distTagOverride = flags
144+ . find ( flag => flag . startsWith ( distTagOverrideFlag ) )
145+ ?. slice ( distTagOverrideFlag . length )
146+
147+ if ( distTagOverride && ! validDistTags . includes ( distTagOverride ) ) {
148+ console . error (
149+ `Expected dist-tag override to be one of "${ validDistTags . join (
150+ '", "'
151+ ) } ". Received: "${ distTagOverride } "`
152+ )
153+ process . exit ( 1 )
154+ }
124155}
125156
126157/**
@@ -275,15 +306,20 @@ const generateChangelog = async (type, tagName, includeChores) => {
275306 features . push ( item )
276307 } else if ( / ^ f i x [ ( ! : ] / . test ( message ) ) {
277308 fixes . push ( item )
278- } else if ( ( includeChores ? / ^ c h o r e [ ( ! : ] / : / ^ c h o r e ( \( .+ ?\) ) ? ! : / ) . test ( message ) ) {
309+ } else if (
310+ ( includeChores ? / ^ c h o r e [ ( ! : ] / : / ^ c h o r e ( \( .+ ?\) ) ? ! : / ) . test ( message )
311+ ) {
279312 // only include breaking chores if !includeChores
280313 chores . push ( item )
281314 }
282315 } )
283316
284317 await Promise . all ( promises )
285318
286- if ( hasBreakingChanges && ! [ 'major' , 'premajor' , 'prerelease' ] . includes ( type ) ) {
319+ if (
320+ hasBreakingChanges &&
321+ ! [ 'major' , 'premajor' , 'prerelease' ] . includes ( type )
322+ ) {
287323 await confirm (
288324 'Breaking changes detected. A major version or a premajor is recommended. Proceed anyway?' ,
289325 false
@@ -539,17 +575,22 @@ const makePullRequest = async (email, token, branch, tagName) => {
539575 * Publish each package to npm. Report any failures and wait for them to be
540576 * fixed manually before proceeding with the release.
541577 */
542- const npmPublish = async ( branch , packages , isPrerelease ) => {
578+ const npmPublish = async ( branch , packages , isPrerelease , distTagOverride ) => {
543579 let proceed = true
544- const tagStr = isNextBranch ( branch )
545- ? ` --tag canary`
546- : isSupportBranch ( branch )
547- ? ` --tag lts`
548- : isPrerelease
549- ? ' --tag next'
550- : ''
551580
552- console . info ( 'Publishing packages with npm dist-tag:' , tagStr . slice ( 7 ) )
581+ const distTag =
582+ distTagOverride ||
583+ ( isNextBranch ( branch )
584+ ? 'canary'
585+ : isSupportBranch ( branch )
586+ ? 'lts'
587+ : isPrerelease
588+ ? 'next'
589+ : '' )
590+
591+ console . info ( 'Publishing packages with npm dist-tag:' , distTag )
592+
593+ const tagStr = distTag ? ` --tag ${ distTag } ` : ''
553594
554595 // publish packages one-by-one (there seemed to be some Nx race condition)
555596 for ( const dir of packages ) {
@@ -633,7 +674,7 @@ const returnToBranch = async (branch, tagName) => {
633674 * 'rc'
634675 */
635676const run = async ( [ type , preId ] , flags ) => {
636- assertValidArgs ( type , preId )
677+ assertValidArgs ( type , preId , flags )
637678
638679 const isPrerelease = type . startsWith ( 'pre' )
639680
@@ -659,7 +700,11 @@ const run = async ([type, preId], flags) => {
659700
660701 // start modifying things
661702 const tagName = await incrementVersion ( packages , type , preId )
662- const changelogBody = await generateChangelog ( type , tagName , flags . includes ( includeChoresFlag ) )
703+ const changelogBody = await generateChangelog (
704+ type ,
705+ tagName ,
706+ flags . includes ( includeChoresFlag )
707+ )
663708
664709 await commitChanges ( tagName )
665710
@@ -668,17 +713,27 @@ const run = async ([type, preId], flags) => {
668713 await makePullRequest ( email , token , branch , tagName )
669714 await returnToBranch ( branch , tagName )
670715
671- await npmPublish ( branch , packages , isPrerelease )
716+ await npmPublish (
717+ branch ,
718+ packages ,
719+ isPrerelease ,
720+ flags
721+ . find ( flag => flag . startsWith ( distTagOverrideFlag ) )
722+ ?. slice ( distTagOverrideFlag . length )
723+ )
672724 await createRelease ( email , token , tagName , changelogBody , isPrerelease )
673725
674726 logPackageLinks ( packages )
675727}
676728
677- const { args, flags } = process . argv . slice ( 2 ) . reduce ( ( buckets , argOrFlag ) => {
678- const bucket = argOrFlag . startsWith ( '-' ) ? buckets . flags : buckets . args
679- bucket . push ( argOrFlag )
729+ const { args, flags } = process . argv . slice ( 2 ) . reduce (
730+ ( buckets , argOrFlag ) => {
731+ const bucket = argOrFlag . startsWith ( '-' ) ? buckets . flags : buckets . args
732+ bucket . push ( argOrFlag )
680733
681- return buckets
682- } , { args : [ ] , flags : [ ] } )
734+ return buckets
735+ } ,
736+ { args : [ ] , flags : [ ] }
737+ )
683738
684739run ( args , flags )
0 commit comments