Browse Source

fix: respect npm registry (#4958)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
opencode-agent[bot] 2 months ago
parent
commit
8e248ae045
1 changed files with 7 additions and 1 deletions
  1. 7 1
      packages/opencode/src/installation/index.ts

+ 7 - 1
packages/opencode/src/installation/index.ts

@@ -4,6 +4,7 @@ import z from "zod"
 import { NamedError } from "@opencode-ai/util/error"
 import { NamedError } from "@opencode-ai/util/error"
 import { Bus } from "../bus"
 import { Bus } from "../bus"
 import { Log } from "../util/log"
 import { Log } from "../util/log"
+import { iife } from "@/util/iife"
 
 
 declare global {
 declare global {
   const OPENCODE_VERSION: string
   const OPENCODE_VERSION: string
@@ -163,9 +164,14 @@ export namespace Installation {
   export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}`
   export const USER_AGENT = `opencode/${CHANNEL}/${VERSION}`
 
 
   export async function latest() {
   export async function latest() {
+    const registry = await iife(async () => {
+      const r = (await $`npm config get registry`.throws(false).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 [major] = VERSION.split(".").map((x) => Number(x))
     const channel = CHANNEL === "latest" ? `latest-${major}` : CHANNEL
     const channel = CHANNEL === "latest" ? `latest-${major}` : CHANNEL
-    return fetch(`https://registry.npmjs.org/opencode-ai/${channel}`)
+    return fetch(`${registry}/opencode-ai/${channel}`)
       .then((res) => {
       .then((res) => {
         if (!res.ok) throw new Error(res.statusText)
         if (!res.ok) throw new Error(res.statusText)
         return res.json()
         return res.json()