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
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user