mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Make homebrew update check use homebrew registry version info
This commit is contained in:
parent
28c802f399
commit
e2e2b7934e
2 changed files with 16 additions and 3 deletions
|
|
@ -5,7 +5,8 @@ import { Installation } from "@/installation"
|
|||
|
||||
export async function upgrade() {
|
||||
const config = await Config.global()
|
||||
const latest = await Installation.latest().catch(() => {})
|
||||
const method = await Installation.method()
|
||||
const latest = await Installation.latest(method).catch(() => {})
|
||||
if (!latest) return
|
||||
if (Installation.VERSION === latest) return
|
||||
|
||||
|
|
@ -17,7 +18,6 @@ export async function upgrade() {
|
|||
return
|
||||
}
|
||||
|
||||
const method = await Installation.method()
|
||||
if (method === "unknown") return
|
||||
await Installation.upgrade(method, latest)
|
||||
.then(() => Bus.publish(Installation.Event.Updated, { version: latest }))
|
||||
|
|
|
|||
|
|
@ -163,7 +163,20 @@ export namespace Installation {
|
|||
export const CHANNEL = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
|
||||
export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}`
|
||||
|
||||
export async function latest() {
|
||||
export async function latest(installMethod?: Method) {
|
||||
const detectedMethod = installMethod || (await method())
|
||||
if (detectedMethod === "brew") {
|
||||
const formula = await getBrewFormula()
|
||||
if (formula === "opencode") {
|
||||
return fetch("https://formulae.brew.sh/api/formula/opencode.json")
|
||||
.then((res) => {
|
||||
if (!res.ok) throw new Error(res.statusText)
|
||||
return res.json()
|
||||
})
|
||||
.then((data: any) => data.versions.stable)
|
||||
}
|
||||
}
|
||||
|
||||
const registry = await iife(async () => {
|
||||
const r = (await $`npm config get registry`.quiet().nothrow().text()).trim()
|
||||
const reg = r || "https://registry.npmjs.org"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue