@@ -10,8 +10,8 @@ import log from 'git-log-parser'
1010import streamToArray from 'stream-to-array'
1111import axios from 'axios'
1212import { DateTime } from 'luxon'
13- import { branchConfigs , latestBranch , packages , rootDir } from './config'
14- import type { BranchConfig , Commit , Package } from './types'
13+ import { branchConfigs , packages , rootDir } from './config'
14+ import type { BranchConfig , Commit } from './types'
1515
1616import type { PackageJson } from 'type-fest'
1717
@@ -22,8 +22,10 @@ async function run() {
2222 process . env . BRANCH ??
2323 // (process.env.PR_NUMBER ? `pr-${process.env.PR_NUMBER}` : currentGitBranch())
2424 currentGitBranch ( )
25+ const branchConfig : BranchConfig | undefined = branchConfigs [ branchName ]
2526
2627 const isMainBranch = branchName === 'main'
28+ const isPreviousRelease = branchConfig ?. previousVersion
2729 const npmTag = isMainBranch ? 'latest' : branchName
2830
2931 // Get tags
@@ -33,6 +35,10 @@ async function run() {
3335 tags = tags
3436 . filter ( ( tag ) => semver . valid ( tag ) )
3537 . filter ( ( tag ) => {
38+ // If this is an older release, filter to only include that version
39+ if ( isPreviousRelease ) {
40+ return tag . startsWith ( branchName )
41+ }
3642 if ( semver . prerelease ( tag ) === null ) {
3743 return isMainBranch
3844 } else {
@@ -286,8 +292,6 @@ async function run() {
286292 recommendedReleaseLevel = 0
287293 }
288294
289- const branchConfig : BranchConfig | undefined = branchConfigs [ branchName ]
290-
291295 if ( ! branchConfig ) {
292296 console . log ( `No publish config found for branch: ${ branchName } ` )
293297 console . log ( 'Exiting...' )
@@ -367,15 +371,14 @@ async function run() {
367371 }
368372
369373 console . info ( )
370- console . info ( `Publishing all packages to npm with tag " ${ npmTag } " ` )
374+ console . info ( `Publishing all packages to npm` )
371375
372376 // Publish each package
373377 changedPackages . forEach ( ( pkg ) => {
374378 const packageDir = path . join ( rootDir , 'packages' , pkg . packageDir )
375- const cmd = `cd ${ packageDir } && pnpm publish --tag ${ npmTag } --access=public --no-git-checks`
376- console . info (
377- ` Publishing ${ pkg . name } @${ version } to npm with tag "${ npmTag } "...` ,
378- )
379+ const tagParam = branchConfig . previousVersion ? `` : `--tag ${ npmTag } `
380+ const cmd = `cd ${ packageDir } && pnpm publish ${ tagParam } --access=public --no-git-checks`
381+ console . info ( ` Publishing ${ pkg . name } @${ version } to npm "${ tagParam } "...` )
379382 execSync ( cmd , {
380383 stdio : [ process . stdin , process . stdout , process . stderr ] ,
381384 } )
@@ -405,7 +408,7 @@ async function run() {
405408 // Stringify the markdown to excape any quotes
406409 execSync (
407410 `gh release create v${ version } ${
408- ! isMainBranch ? '--prerelease' : ''
411+ branchConfig . prerelease ? '--prerelease' : ''
409412 } --notes '${ changelogMd . replace ( / ' / g, '"' ) } '`,
410413 )
411414 console . info ( ` Github release created.` )
0 commit comments