98da8b675b
The same output.trim() bug fixed in PR #3909 for doctor exists in the installer's opencode-binary.ts. Without this fix, `bunx oh-my-opencode install` would store polluted Electron stdout (e.g., `00:24:25.202 > app starting { version: '1.14.33', packaged: true }`) as the OpenCode version in config, breaking downstream version-dependent logic. - Extract extractSemverFromOutput to src/shared/extract-semver.ts (precedent: spawn-with-windows-hide is in shared because used by both doctor and installer) - src/cli/doctor/checks/system-binary.ts now imports from shared and re-exports for backward compat - src/cli/config-manager/opencode-binary.ts uses the shared helper with `?? output.trim()` fallback to preserve legacy behavior on non-semver-shaped successful outputs (e.g., custom builds) - Add 4 installer regression tests covering: clean semver, polluted Electron stdout (regression for #3765 installer caller), fallback for non-semver, null when no binary on PATH Refs #3765
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { extractSemverFromOutput } from "../../shared/extract-semver"
|
|
import type { OpenCodeBinaryType } from "../../shared/opencode-config-dir-types"
|
|
import { spawnWithWindowsHide } from "../../shared/spawn-with-windows-hide"
|
|
import { initConfigContext } from "./config-context"
|
|
|
|
const OPENCODE_BINARIES = ["opencode", "opencode-desktop"] as const
|
|
|
|
interface OpenCodeBinaryResult {
|
|
binary: OpenCodeBinaryType
|
|
version: string
|
|
}
|
|
|
|
async function findOpenCodeBinaryWithVersion(): Promise<OpenCodeBinaryResult | null> {
|
|
for (const binary of OPENCODE_BINARIES) {
|
|
try {
|
|
const proc = spawnWithWindowsHide([binary, "--version"], {
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
})
|
|
const output = await new Response(proc.stdout).text()
|
|
await proc.exited
|
|
if (proc.exitCode === 0) {
|
|
const version = extractSemverFromOutput(output) ?? output.trim()
|
|
initConfigContext(binary, version)
|
|
return { binary, version }
|
|
}
|
|
} catch {
|
|
continue
|
|
}
|
|
}
|
|
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
|
|
}
|