Просмотр исходного кода

fix: adjust upgrade command to use gh releases page if not npm/bun/pnpm install method

Aiden Cline 1 месяц назад
Родитель
Сommit
4abaa052db
1 измененных файлов с 21 добавлено и 10 удалено
  1. 21 10
      packages/opencode/src/installation/index.ts

+ 21 - 10
packages/opencode/src/installation/index.ts

@@ -166,6 +166,8 @@ export namespace Installation {
 
   export async function latest(installMethod?: Method) {
     const detectedMethod = installMethod || (await method())
+
+    // Use brew formula API for homebrew core formula
     if (detectedMethod === "brew") {
       const formula = await getBrewFormula()
       if (formula === "opencode") {
@@ -178,19 +180,28 @@ export namespace Installation {
       }
     }
 
-    const registry = await iife(async () => {
-      const r = (await $`npm config get registry`.quiet().nothrow().text()).trim()
-      const reg = r || "https://registry.npmjs.org"
-      return reg.endsWith("/") ? reg.slice(0, -1) : reg
-    })
-    const [major] = VERSION.split(".").map((x) => Number(x))
-    // const channel = CHANNEL === "latest" ? `latest-${major}` : CHANNEL
-    const channel = CHANNEL
-    return fetch(`${registry}/opencode-ai/${channel}`)
+    // Use npm registry for npm/bun/pnpm
+    if (detectedMethod === "npm" || detectedMethod === "bun" || detectedMethod === "pnpm") {
+      const registry = await iife(async () => {
+        const r = (await $`npm config get registry`.quiet().nothrow().text()).trim()
+        const reg = r || "https://registry.npmjs.org"
+        return reg.endsWith("/") ? reg.slice(0, -1) : reg
+      })
+      const channel = CHANNEL
+      return fetch(`${registry}/opencode-ai/${channel}`)
+        .then((res) => {
+          if (!res.ok) throw new Error(res.statusText)
+          return res.json()
+        })
+        .then((data: any) => data.version)
+    }
+
+    // Use GitHub releases for everything else (curl, yarn, brew tap, unknown)
+    return fetch("https://api.github.com/repos/sst/opencode/releases/latest")
       .then((res) => {
         if (!res.ok) throw new Error(res.statusText)
         return res.json()
       })
-      .then((data: any) => data.version)
+      .then((data: any) => data.tag_name.replace(/^v/, ""))
   }
 }