Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/shared/migration/config-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function migrateConfigFile(
rawConfig: Record<string, unknown>
): boolean {
const copy = structuredClone(rawConfig)
const originalSnapshot = JSON.stringify(rawConfig)
let needsWrite = false

// Load previously applied migrations from BOTH the legacy in-config
Expand Down Expand Up @@ -142,6 +143,22 @@ export function migrateConfigFile(
}

if (needsWrite) {
// Verify the config body actually changed before creating a backup and
// rewriting. Several migration paths set needsWrite=true without
// altering the config body (e.g. stripping an already-absent
// _migrations field, or recording sidecar-only state). Without this
// guard the plugin creates a new .bak.<timestamp> file on every
// startup even when the config is already up-to-date (#3222).
if (JSON.stringify(copy) === originalSnapshot) {
// Config body is identical after all migrations ran. Apply in-memory
// mutations (e.g. stripped _migrations) without touching the filesystem.
for (const key of Object.keys(rawConfig)) {
delete rawConfig[key]
}
Object.assign(rawConfig, copy)
return false
}

const timestamp = new Date().toISOString().replace(/[:.]/g, "-")
const backupPath = `${configPath}.bak.${timestamp}`
let backupSucceeded = false
Expand Down
Loading