@@ -21,8 +21,11 @@ async function run() {
2121 const branchName = /** @type {string } */ (
2222 process . env . BRANCH ?? currentGitBranch ( )
2323 )
24+ /** @type {import('./types.js').BranchConfig | undefined } */
25+ const branchConfig = branchConfigs [ branchName ]
2426
2527 const isMainBranch = branchName === 'main'
28+ const isPreviousRelease = branchConfig ?. previousVersion
2629 const npmTag = isMainBranch ? 'latest' : branchName
2730
2831 // Get tags
@@ -33,6 +36,10 @@ async function run() {
3336 tags = tags
3437 . filter ( ( tag ) => semver . valid ( tag ) )
3538 . filter ( ( tag ) => {
39+ // If this is an older release, filter to only include that version
40+ if ( isPreviousRelease ) {
41+ return tag . startsWith ( branchName )
42+ }
3643 if ( semver . prerelease ( tag ) === null ) {
3744 return isMainBranch
3845 } else {
@@ -300,9 +307,6 @@ async function run() {
300307 recommendedReleaseLevel = 0
301308 }
302309
303- /** @type {import('./types.js').BranchConfig | undefined } */
304- const branchConfig = branchConfigs [ branchName ]
305-
306310 if ( ! branchConfig ) {
307311 console . log ( `No publish config found for branch: ${ branchName } ` )
308312 console . log ( 'Exiting...' )
@@ -374,15 +378,15 @@ async function run() {
374378 }
375379
376380 console . info ( )
377- console . info ( `Publishing all packages to npm with tag " ${ npmTag } " ` )
381+ console . info ( `Publishing all packages to npm` )
378382
379383 // Publish each package
380384 changedPackages . forEach ( ( pkg ) => {
381385 const packageDir = path . join ( rootDir , pkg . packageDir )
382- const cmd = `cd ${ packageDir } && pnpm publish --tag ${ npmTag } --access=public --no-git-checks `
383- console . info (
384- ` Publishing ${ pkg . name } @ ${ version } to npm with tag " ${ npmTag } "...` ,
385- )
386+ const tagParam = branchConfig . previousVersion ? `` : ` --tag ${ npmTag } `
387+
388+ const cmd = `cd ${ packageDir } && pnpm publish ${ tagParam } --access=public --no-git-checks`
389+ console . info ( ` Publishing ${ pkg . name } @ ${ version } to npm " ${ tagParam } "...` )
386390 execSync ( cmd , {
387391 stdio : [ process . stdin , process . stdout , process . stderr ] ,
388392 } )
@@ -412,7 +416,7 @@ async function run() {
412416 // Stringify the markdown to excape any quotes
413417 execSync (
414418 `gh release create v${ version } ${
415- ! isMainBranch ? '--prerelease' : ''
419+ branchConfig . prerelease ? '--prerelease' : ''
416420 } --notes '${ changelogMd . replace ( / ' / g, '"' ) } '`,
417421 )
418422 console . info ( ` Github release created.` )
0 commit comments