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()