Skip to content

Commit 2c62c04

Browse files
authoredAug 15, 2022
chore: publish under previous tag if not latest (#9658)
1 parent 73f5e12 commit 2c62c04

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎scripts/publishCI.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { args, getPackageInfo, publishPackage, step } from './releaseUtils'
1+
import semver from 'semver'
2+
import {
3+
args,
4+
getActiveVersion,
5+
getPackageInfo,
6+
publishPackage,
7+
step
8+
} from './releaseUtils'
29

310
async function main() {
411
const tag = args._[0]
@@ -21,11 +28,15 @@ async function main() {
2128
`Package version from tag "${version}" mismatches with current version "${currentVersion}"`
2229
)
2330

31+
const activeVersion = await getActiveVersion(pkgName)
32+
2433
step('Publishing package...')
2534
const releaseTag = version.includes('beta')
2635
? 'beta'
2736
: version.includes('alpha')
2837
? 'alpha'
38+
: semver.lt(currentVersion, activeVersion)
39+
? 'previous'
2940
: undefined
3041
await publishPackage(pkgDir, releaseTag)
3142
}

‎scripts/releaseUtils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ export async function getLatestTag(pkgName: string): Promise<string> {
197197
.reverse()[0]
198198
}
199199

200+
export async function getActiveVersion(pkgName: string): Promise<string> {
201+
return (await run('npm', ['info', pkgName, 'version'], { stdio: 'pipe' }))
202+
.stdout
203+
}
204+
200205
export async function logRecentCommits(pkgName: string): Promise<void> {
201206
const tag = await getLatestTag(pkgName)
202207
if (!tag) return

0 commit comments

Comments
 (0)
Please sign in to comment.