refactor(shared): consolidate plugin entry migration and detection utilities
This commit is contained in:
@@ -3,7 +3,8 @@ import { join } from "node:path"
|
||||
|
||||
import { parseJsoncSafe } from "../../shared/jsonc-parser"
|
||||
import { getOpenCodeConfigPaths } from "../../shared/opencode-config-dir"
|
||||
import { LEGACY_PLUGIN_NAME, PLUGIN_NAME } from "../../shared/plugin-identity"
|
||||
import { PLUGIN_NAME } from "../../shared/plugin-identity"
|
||||
import { isCanonicalEntry, isLegacyEntry, toCanonicalEntry } from "../../shared/plugin-entry-migrator"
|
||||
import { migrateLegacyPluginEntry } from "./plugin-entry-migrator"
|
||||
|
||||
export interface MigrationResult {
|
||||
@@ -17,22 +18,6 @@ interface OpenCodeConfig {
|
||||
plugin?: string[]
|
||||
}
|
||||
|
||||
function isLegacyEntry(entry: string): boolean {
|
||||
return entry === LEGACY_PLUGIN_NAME || entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)
|
||||
}
|
||||
|
||||
function isCanonicalEntry(entry: string): boolean {
|
||||
return entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)
|
||||
}
|
||||
|
||||
function toLegacyCanonical(entry: string): string {
|
||||
if (entry === LEGACY_PLUGIN_NAME) return PLUGIN_NAME
|
||||
if (entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
|
||||
return `${PLUGIN_NAME}${entry.slice(LEGACY_PLUGIN_NAME.length)}`
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
function detectOpenCodeConfigPath(overrideConfigDir?: string): string | null {
|
||||
if (overrideConfigDir) {
|
||||
const jsoncPath = join(overrideConfigDir, "opencode.jsonc")
|
||||
@@ -63,7 +48,7 @@ export function autoMigrateLegacyPluginEntry(overrideConfigDir?: string): Migrat
|
||||
|
||||
const hasCanonical = plugins.some(isCanonicalEntry)
|
||||
const from = legacyEntries[0]
|
||||
const to = toLegacyCanonical(from)
|
||||
const to = toCanonicalEntry(from)
|
||||
const migrated = migrateLegacyPluginEntry(configPath)
|
||||
if (!migrated) return { migrated: false, from: null, to: null, configPath }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user