fix(plugin): restore user lockfile after upgrading

This commit is contained in:
saberzero1 2026-03-16 12:20:27 +01:00
parent b2971bde6b
commit 0f67327a6c
No known key found for this signature in database

View File

@ -36,6 +36,7 @@ import {
writePluginsJson, writePluginsJson,
extractPluginName, extractPluginName,
updateGlobalConfig, updateGlobalConfig,
LOCKFILE_PATH,
} from "./plugin-data.js" } from "./plugin-data.js"
import { import {
UPSTREAM_NAME, UPSTREAM_NAME,
@ -583,16 +584,50 @@ export async function handleUpgrade(argv) {
console.log("Backing up your content") console.log("Backing up your content")
execSync(`git remote show upstream || git remote add upstream ${QUARTZ_SOURCE_REPO}`) execSync(`git remote show upstream || git remote add upstream ${QUARTZ_SOURCE_REPO}`)
await stashContentFolder(contentFolder) await stashContentFolder(contentFolder)
const lockfileBackup = LOCKFILE_PATH + ".bak"
const hasLockfile = fs.existsSync(LOCKFILE_PATH)
if (hasLockfile) {
fs.copyFileSync(LOCKFILE_PATH, lockfileBackup)
}
console.log( console.log(
"Pulling updates... you may need to resolve some `git` conflicts if you've made changes to components or plugins.", "Pulling updates... you may need to resolve some `git` conflicts if you've made changes to components or plugins.",
) )
let pullOk = false
try { try {
gitPull(UPSTREAM_NAME, QUARTZ_SOURCE_BRANCH) gitPull(UPSTREAM_NAME, QUARTZ_SOURCE_BRANCH)
pullOk = true
} catch { } catch {
console.log(styleText("red", "An error occurred above while pulling updates.")) if (hasLockfile) {
await popContentFolder(contentFolder) try {
return fs.copyFileSync(lockfileBackup, LOCKFILE_PATH)
execSync(`git add ${LOCKFILE_PATH}`)
const remaining = execSync("git diff --name-only --diff-filter=U", {
encoding: "utf-8",
}).trim()
if (remaining.length === 0) {
execSync("git commit --no-edit")
pullOk = true
console.log(styleText("cyan", "Resolved quartz.lock.json merge conflict automatically."))
}
} catch {
// Could not auto-resolve, fall through to manual resolution
}
}
if (!pullOk) {
console.log(styleText("red", "An error occurred above while pulling updates."))
await popContentFolder(contentFolder)
if (fs.existsSync(lockfileBackup)) fs.unlinkSync(lockfileBackup)
return
}
}
if (hasLockfile && fs.existsSync(lockfileBackup)) {
fs.copyFileSync(lockfileBackup, LOCKFILE_PATH)
fs.unlinkSync(lockfileBackup)
} }
await popContentFolder(contentFolder) await popContentFolder(contentFolder)