From 1390970973dc5546a548528fdca0d04a652bfe3a Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 5 Dec 2025 09:28:51 +0900 Subject: [PATCH] fix: skip publish if version already exists on registry --- script/publish.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/script/publish.ts b/script/publish.ts index 8843e37..9ace01d 100644 --- a/script/publish.ts +++ b/script/publish.ts @@ -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 { + 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()