Files
oh-my-opencode/src/shared/migrate-legacy-config-file.ts
T
YeonGyu-Kim 6a733c9dde fix(#2823): auto-migrate legacy plugin name and warn users at startup
- logLegacyPluginStartupWarning now emits console.warn (visible to user,
  not just log file) when oh-my-opencode is detected in opencode.json
- Auto-migrates opencode.json plugin entry from oh-my-opencode to
  oh-my-openagent (with backup)
- plugin-config.ts: add console.warn when loading legacy config filename
- test: 10 tests covering migration, console output, edge cases
2026-03-27 15:40:04 +09:00

32 lines
1.0 KiB
TypeScript

import { existsSync, copyFileSync, renameSync } from "node:fs"
import { join, dirname, basename } from "node:path"
import { log } from "./logger"
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "./plugin-identity"
function buildCanonicalPath(legacyPath: string): string {
const dir = dirname(legacyPath)
const ext = basename(legacyPath).includes(".jsonc") ? ".jsonc" : ".json"
return join(dir, `${CONFIG_BASENAME}${ext}`)
}
export function migrateLegacyConfigFile(legacyPath: string): boolean {
if (!existsSync(legacyPath)) return false
if (!basename(legacyPath).startsWith(LEGACY_CONFIG_BASENAME)) return false
const canonicalPath = buildCanonicalPath(legacyPath)
if (existsSync(canonicalPath)) return false
try {
copyFileSync(legacyPath, canonicalPath)
log("[migrateLegacyConfigFile] Copied legacy config to canonical path", {
from: legacyPath,
to: canonicalPath,
})
return true
} catch (error) {
log("[migrateLegacyConfigFile] Failed to copy legacy config file", { legacyPath, error })
return false
}
}