update brew handling

This commit is contained in:
Aiden Cline
2025-11-04 00:52:15 -06:00
parent d49b1b25d1
commit d341d26e37
4 changed files with 46 additions and 30 deletions

View File

@@ -73,7 +73,7 @@ export namespace Installation {
},
{
name: "brew" as const,
command: () => $`brew list --formula opencode-ai`.throws(false).text(),
command: () => $`brew list --formula opencode`.throws(false).text(),
},
]
@@ -87,7 +87,7 @@ export namespace Installation {
for (const check of checks) {
const output = await check.command()
if (output.includes("opencode-ai")) {
if (output.includes(check.name === "brew" ? "opencode" : "opencode-ai")) {
return check.name
}
}
@@ -102,28 +102,42 @@ export namespace Installation {
}),
)
async function getBrewFormula() {
const tapFormula = await $`brew list --formula sst/tap/opencode`.throws(false).text()
if (tapFormula.includes("opencode")) return "sst/tap/opencode"
const coreFormula = await $`brew list --formula opencode`.throws(false).text()
if (coreFormula.includes("opencode")) return "opencode"
return "opencode"
}
export async function upgrade(method: Method, target: string) {
const cmd = (() => {
switch (method) {
case "curl":
return $`curl -fsSL https://opencode.ai/install | bash`.env({
...process.env,
VERSION: target,
})
case "npm":
return $`npm install -g opencode-ai@${target}`
case "pnpm":
return $`pnpm install -g opencode-ai@${target}`
case "bun":
return $`bun install -g opencode-ai@${target}`
case "brew":
return $`brew install sst/tap/opencode`.env({
HOMEBREW_NO_AUTO_UPDATE: "1",
})
default:
throw new Error(`Unknown method: ${method}`)
let cmd
switch (method) {
case "curl":
cmd = $`curl -fsSL https://opencode.ai/install | bash`.env({
...process.env,
VERSION: target,
})
break
case "npm":
cmd = $`npm install -g opencode-ai@${target}`
break
case "pnpm":
cmd = $`pnpm install -g opencode-ai@${target}`
break
case "bun":
cmd = $`bun install -g opencode-ai@${target}`
break
case "brew": {
const formula = await getBrewFormula()
cmd = $`brew install ${formula}`.env({
HOMEBREW_NO_AUTO_UPDATE: "1",
})
break
}
})()
default:
throw new Error(`Unknown method: ${method}`)
}
const result = await cmd.quiet().throws(false)
log.info("upgraded", {
method,