fix(cli): update existing plugin entry instead of skipping
Addresses cubic review feedback: installer now replaces existing oh-my-opencode entries with the new version-aware entry, allowing users to switch between @latest, @beta, or pinned versions.
This commit is contained in:
parent
c29e6f0213
commit
1a5fdb3338
@ -237,11 +237,18 @@ export async function addPluginToOpenCodeConfig(currentVersion: string): Promise
|
|||||||
|
|
||||||
const config = parseResult.config
|
const config = parseResult.config
|
||||||
const plugins = config.plugin ?? []
|
const plugins = config.plugin ?? []
|
||||||
if (plugins.some((p) => p.startsWith(PACKAGE_NAME))) {
|
const existingIndex = plugins.findIndex((p) => p === PACKAGE_NAME || p.startsWith(`${PACKAGE_NAME}@`))
|
||||||
return { success: true, configPath: path }
|
|
||||||
|
if (existingIndex !== -1) {
|
||||||
|
if (plugins[existingIndex] === pluginEntry) {
|
||||||
|
return { success: true, configPath: path }
|
||||||
|
}
|
||||||
|
plugins[existingIndex] = pluginEntry
|
||||||
|
} else {
|
||||||
|
plugins.push(pluginEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.plugin = [...plugins, pluginEntry]
|
config.plugin = plugins
|
||||||
|
|
||||||
if (format === "jsonc") {
|
if (format === "jsonc") {
|
||||||
const content = readFileSync(path, "utf-8")
|
const content = readFileSync(path, "utf-8")
|
||||||
@ -249,11 +256,8 @@ export async function addPluginToOpenCodeConfig(currentVersion: string): Promise
|
|||||||
const match = content.match(pluginArrayRegex)
|
const match = content.match(pluginArrayRegex)
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
const arrayContent = match[1].trim()
|
const formattedPlugins = plugins.map((p) => `"${p}"`).join(",\n ")
|
||||||
const newArrayContent = arrayContent
|
const newContent = content.replace(pluginArrayRegex, `"plugin": [\n ${formattedPlugins}\n ]`)
|
||||||
? `${arrayContent},\n "${pluginEntry}"`
|
|
||||||
: `"${pluginEntry}"`
|
|
||||||
const newContent = content.replace(pluginArrayRegex, `"plugin": [\n ${newArrayContent}\n ]`)
|
|
||||||
writeFileSync(path, newContent)
|
writeFileSync(path, newContent)
|
||||||
} else {
|
} else {
|
||||||
const newContent = content.replace(/^(\s*\{)/, `$1\n "plugin": ["${pluginEntry}"],`)
|
const newContent = content.replace(/^(\s*\{)/, `$1\n "plugin": ["${pluginEntry}"],`)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user