Skip to content

Commit 1390970

Browse files
committed
fix: skip publish if version already exists on registry
1 parent a72bfe5 commit 1390970

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

script/publish.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,25 @@ async function gitTagAndRelease(newVersion: string, changelog: string): Promise<
8787
await $`gh release create v${newVersion} --title "v${newVersion}" --notes ${releaseNotes}`
8888
}
8989

90+
async function checkVersionExists(version: string): Promise<boolean> {
91+
try {
92+
const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/${version}`)
93+
return res.ok
94+
} catch {
95+
return false
96+
}
97+
}
98+
9099
async function main() {
91100
const previous = await fetchPreviousVersion()
92101
const newVersion = versionOverride || (bump ? bumpVersion(previous, bump) : bumpVersion(previous, "patch"))
93102
console.log(`New version: ${newVersion}\n`)
94103

104+
if (await checkVersionExists(newVersion)) {
105+
console.log(`Version ${newVersion} already exists on npm. Skipping publish.`)
106+
process.exit(0)
107+
}
108+
95109
await updatePackageVersion(newVersion)
96110
const changelog = await generateChangelog(previous)
97111
await buildAndPublish()

0 commit comments

Comments
 (0)