fix(auto-update): revert config pin on install failure to prevent version mismatch
When bun install fails after updating the config pin, the config now shows the new version but the actual package is the old one. Add revertPinnedVersion() to roll back the config entry on install failure, keeping config and installed version in sync. Ref #1472
This commit is contained in:
@@ -2,10 +2,9 @@ import * as fs from "node:fs"
|
||||
import { log } from "../../../shared/logger"
|
||||
import { PACKAGE_NAME } from "../constants"
|
||||
|
||||
export function updatePinnedVersion(configPath: string, oldEntry: string, newVersion: string): boolean {
|
||||
function replacePluginEntry(configPath: string, oldEntry: string, newEntry: string): boolean {
|
||||
try {
|
||||
const content = fs.readFileSync(configPath, "utf-8")
|
||||
const newEntry = `${PACKAGE_NAME}@${newVersion}`
|
||||
|
||||
const pluginMatch = content.match(/"plugin"\s*:\s*\[/)
|
||||
if (!pluginMatch || pluginMatch.index === undefined) {
|
||||
@@ -51,3 +50,13 @@ export function updatePinnedVersion(configPath: string, oldEntry: string, newVer
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function updatePinnedVersion(configPath: string, oldEntry: string, newVersion: string): boolean {
|
||||
const newEntry = `${PACKAGE_NAME}@${newVersion}`
|
||||
return replacePluginEntry(configPath, oldEntry, newEntry)
|
||||
}
|
||||
|
||||
export function revertPinnedVersion(configPath: string, failedVersion: string, originalEntry: string): boolean {
|
||||
const failedEntry = `${PACKAGE_NAME}@${failedVersion}`
|
||||
return replacePluginEntry(configPath, failedEntry, originalEntry)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user