@@ -25,13 +25,17 @@ import {
2525 */
2626export const publish = async ( options ) => {
2727 const { branchConfigs, packages, rootDir, branch, tag, ghToken } = options
28+
2829 const branchName = /** @type {string } */ ( branch ?? currentGitBranch ( ) )
30+ const isMainBranch = branchName === 'main'
31+ const npmTag = isMainBranch ? 'latest' : branchName
32+
2933 /** @type {import('./types.js').BranchConfig | undefined } */
3034 const branchConfig = branchConfigs [ branchName ]
3135
32- const isMainBranch = branchName === 'main'
33- const isPreviousRelease = branchConfig ?. previousVersion
34- const npmTag = isMainBranch ? 'latest' : branchName
36+ if ( ! branchConfig ) {
37+ throw new Error ( `No publish config found for branch: ${ branchName } ` )
38+ }
3539
3640 // Get tags
3741 /** @type {string[] } */
@@ -42,7 +46,7 @@ export const publish = async (options) => {
4246 . filter ( ( t ) => semver . valid ( t ) )
4347 . filter ( ( t ) => {
4448 // If this is an older release, filter to only include that version
45- if ( isPreviousRelease ) {
49+ if ( branchConfig . previousVersion ) {
4650 return t . startsWith ( branchName )
4751 }
4852 if ( semver . prerelease ( t ) === null ) {
@@ -310,12 +314,6 @@ export const publish = async (options) => {
310314 recommendedReleaseLevel = 0
311315 }
312316
313- if ( ! branchConfig ) {
314- console . log ( `No publish config found for branch: ${ branchName } ` )
315- console . log ( 'Exiting...' )
316- process . exit ( 0 )
317- }
318-
319317 const releaseType = branchConfig . prerelease
320318 ? 'prerelease'
321319 : /** @type {const } */ ( { 0 : 'patch' , 1 : 'minor' , 2 : 'major' } ) [
@@ -381,15 +379,14 @@ export const publish = async (options) => {
381379 }
382380
383381 console . info ( )
384- console . info ( ' Publishing all packages to npm' )
382+ console . info ( ` Publishing all packages to npm with tag " ${ npmTag } "` )
385383
386384 // Publish each package
387385 changedPackages . forEach ( ( pkg ) => {
388386 const packageDir = path . join ( rootDir , pkg . packageDir )
389- const tagParam = branchConfig . previousVersion ? '' : `--tag ${ npmTag } `
390387
391- const cmd = `cd ${ packageDir } && pnpm publish ${ tagParam } --access=public --no-git-checks`
392- console . info ( ` Publishing ${ pkg . name } @${ version } to npm " ${ tagParam } " ...` )
388+ const cmd = `cd ${ packageDir } && pnpm publish --tag ${ npmTag } --access=public --no-git-checks`
389+ console . info ( ` Publishing ${ pkg . name } @${ version } to npm...` )
393390 execSync ( cmd , {
394391 stdio : [ process . stdin , process . stdout , process . stderr ] ,
395392 } )
0 commit comments