fix(config): handle tuple-format plugin entries in opencode.json (fixes #3122)
OpenCode supports plugin entries as [string, object] tuples for passing options, but loadOpencodePlugins assumed all entries were strings. When a tuple entry hit matchesKnownPlugin, it called .toLowerCase() on an array, crashing the plugin on startup. Extract the string name from tuple entries and skip non-string values. Add regression test covering the tuple plugin format.
This commit is contained in:
@@ -5,7 +5,7 @@ import * as path from "node:path"
|
||||
import { parseJsoncSafe } from "./jsonc-parser"
|
||||
|
||||
interface OpencodeConfig {
|
||||
plugin?: string[]
|
||||
plugin?: (string | [string, ...unknown[]])[]
|
||||
}
|
||||
|
||||
function getWindowsAppdataDir(): string | null {
|
||||
@@ -44,7 +44,9 @@ export function loadOpencodePlugins(directory: string): string[] {
|
||||
const result = parseJsoncSafe<OpencodeConfig>(content)
|
||||
const plugins = result.data?.plugin ?? []
|
||||
|
||||
for (const plugin of plugins) {
|
||||
for (const rawPlugin of plugins) {
|
||||
const plugin = typeof rawPlugin === "string" ? rawPlugin : Array.isArray(rawPlugin) ? rawPlugin[0] : null
|
||||
if (typeof plugin !== "string") continue
|
||||
if (seenPluginEntries.has(plugin)) continue
|
||||
seenPluginEntries.add(plugin)
|
||||
pluginEntries.push(plugin)
|
||||
|
||||
Reference in New Issue
Block a user