fix: prevent auto-update from downgrading prerelease/dist-tag versions (#615)
* fix: prevent auto-update from downgrading prerelease/dist-tag versions The auto-update checker was incorrectly updating pinned prerelease versions (e.g., 3.0.0-beta.1) and dist-tags (e.g., @beta) to the stable latest version from npm, effectively downgrading users who opted into beta. Added isPrereleaseOrDistTag() check that skips auto-update when: - Version contains '-' (prerelease like 3.0.0-beta.1) - Version is a dist-tag (non-semver like beta, next, canary) Fixes #613 * refactor: export version helpers and import in tests Address review feedback: export isPrereleaseVersion, isDistTag, and isPrereleaseOrDistTag from index.ts and import them in tests instead of duplicating the logic.
This commit is contained in:
@@ -9,6 +9,20 @@ import type { AutoUpdateCheckerOptions } from "./types"
|
||||
|
||||
const SISYPHUS_SPINNER = ["·", "•", "●", "○", "◌", "◦", " "]
|
||||
|
||||
export function isPrereleaseVersion(version: string): boolean {
|
||||
return version.includes("-")
|
||||
}
|
||||
|
||||
export function isDistTag(version: string): boolean {
|
||||
const startsWithDigit = /^\d/.test(version)
|
||||
return !startsWithDigit
|
||||
}
|
||||
|
||||
export function isPrereleaseOrDistTag(pinnedVersion: string | null): boolean {
|
||||
if (!pinnedVersion) return false
|
||||
return isPrereleaseVersion(pinnedVersion) || isDistTag(pinnedVersion)
|
||||
}
|
||||
|
||||
export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdateCheckerOptions = {}) {
|
||||
const { showStartupToast = true, isSisyphusEnabled = false, autoUpdate = true } = options
|
||||
|
||||
@@ -63,7 +77,7 @@ export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdat
|
||||
}
|
||||
|
||||
async function runBackgroundUpdateCheck(
|
||||
ctx: PluginInput,
|
||||
ctx: PluginInput,
|
||||
autoUpdate: boolean,
|
||||
getToastMessage: (isUpdate: boolean, latestVersion?: string) => string
|
||||
): Promise<void> {
|
||||
@@ -100,6 +114,11 @@ async function runBackgroundUpdateCheck(
|
||||
}
|
||||
|
||||
if (pluginInfo.isPinned) {
|
||||
if (isPrereleaseOrDistTag(pluginInfo.pinnedVersion)) {
|
||||
log(`[auto-update-checker] Skipping auto-update for prerelease/dist-tag: ${pluginInfo.pinnedVersion}`)
|
||||
return
|
||||
}
|
||||
|
||||
const updated = updatePinnedVersion(pluginInfo.configPath, pluginInfo.entry, latestVersion)
|
||||
if (!updated) {
|
||||
await showUpdateAvailableToast(ctx, latestVersion, getToastMessage)
|
||||
@@ -112,7 +131,7 @@ async function runBackgroundUpdateCheck(
|
||||
invalidatePackage(PACKAGE_NAME)
|
||||
|
||||
const installSuccess = await runBunInstallSafe()
|
||||
|
||||
|
||||
if (installSuccess) {
|
||||
await showAutoUpdatedToast(ctx, currentVersion, latestVersion)
|
||||
log(`[auto-update-checker] Update installed: ${currentVersion} → ${latestVersion}`)
|
||||
@@ -180,7 +199,7 @@ async function showSpinnerToast(ctx: PluginInput, version: string, message: stri
|
||||
}
|
||||
|
||||
async function showUpdateAvailableToast(
|
||||
ctx: PluginInput,
|
||||
ctx: PluginInput,
|
||||
latestVersion: string,
|
||||
getToastMessage: (isUpdate: boolean, latestVersion?: string) => string
|
||||
): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user