fix: detect opencode-desktop binary in installer (#313)

This commit is contained in:
Sisyphus
2025-12-29 10:34:11 +09:00
committed by GitHub
parent c01b21d0f8
commit 3a08dcaeb1

View File

@@ -10,6 +10,8 @@ const OPENCODE_JSONC = join(OPENCODE_CONFIG_DIR, "opencode.jsonc")
const OPENCODE_PACKAGE_JSON = join(OPENCODE_CONFIG_DIR, "package.json") const OPENCODE_PACKAGE_JSON = join(OPENCODE_CONFIG_DIR, "package.json")
const OMO_CONFIG = join(OPENCODE_CONFIG_DIR, "oh-my-opencode.json") const OMO_CONFIG = join(OPENCODE_CONFIG_DIR, "oh-my-opencode.json")
const OPENCODE_BINARIES = ["opencode", "opencode-desktop"] as const
const CHATGPT_HOTFIX_REPO = "code-yeongyu/opencode-openai-codex-auth#fix/orphaned-function-call-output-with-tools" const CHATGPT_HOTFIX_REPO = "code-yeongyu/opencode-openai-codex-auth#fix/orphaned-function-call-output-with-tools"
export async function fetchLatestVersion(packageName: string): Promise<string | null> { export async function fetchLatestVersion(packageName: string): Promise<string | null> {
@@ -204,31 +206,38 @@ export function writeOmoConfig(installConfig: InstallConfig): ConfigMergeResult
} }
} }
export async function isOpenCodeInstalled(): Promise<boolean> { interface OpenCodeBinaryResult {
try { binary: string
const proc = Bun.spawn(["opencode", "--version"], { version: string
stdout: "pipe",
stderr: "pipe",
})
await proc.exited
return proc.exitCode === 0
} catch {
return false
}
} }
export async function getOpenCodeVersion(): Promise<string | null> { async function findOpenCodeBinaryWithVersion(): Promise<OpenCodeBinaryResult | null> {
for (const binary of OPENCODE_BINARIES) {
try { try {
const proc = Bun.spawn(["opencode", "--version"], { const proc = Bun.spawn([binary, "--version"], {
stdout: "pipe", stdout: "pipe",
stderr: "pipe", stderr: "pipe",
}) })
const output = await new Response(proc.stdout).text() const output = await new Response(proc.stdout).text()
await proc.exited await proc.exited
return proc.exitCode === 0 ? output.trim() : null if (proc.exitCode === 0) {
return { binary, version: output.trim() }
}
} catch { } catch {
continue
}
}
return null return null
} }
export async function isOpenCodeInstalled(): Promise<boolean> {
const result = await findOpenCodeBinaryWithVersion()
return result !== null
}
export async function getOpenCodeVersion(): Promise<string | null> {
const result = await findOpenCodeBinaryWithVersion()
return result?.version ?? null
} }
export async function addAuthPlugins(config: InstallConfig): Promise<ConfigMergeResult> { export async function addAuthPlugins(config: InstallConfig): Promise<ConfigMergeResult> {