fix: skip publish if version already exists on registry

This commit is contained in:
YeonGyu-Kim
2025-12-05 09:28:51 +09:00
parent a72bfe5c02
commit 1390970973

View File

@@ -87,11 +87,25 @@ async function gitTagAndRelease(newVersion: string, changelog: string): Promise<
await $`gh release create v${newVersion} --title "v${newVersion}" --notes ${releaseNotes}`
}
async function checkVersionExists(version: string): Promise<boolean> {
try {
const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/${version}`)
return res.ok
} catch {
return false
}
}
async function main() {
const previous = await fetchPreviousVersion()
const newVersion = versionOverride || (bump ? bumpVersion(previous, bump) : bumpVersion(previous, "patch"))
console.log(`New version: ${newVersion}\n`)
if (await checkVersionExists(newVersion)) {
console.log(`Version ${newVersion} already exists on npm. Skipping publish.`)
process.exit(0)
}
await updatePackageVersion(newVersion)
const changelog = await generateChangelog(previous)
await buildAndPublish()