The open source coding agent.
TypeScript
fix: ensure that plugin installs use --no-cache when using http proxy to prevent random hangs (see bun issue) (#12161)
Aiden Clinea2c28fc8d733
diff --git a/packages/opencode/src/bun/index.ts b/packages/opencode/src/bun/index.tsindex 19edb6eec4b..bdb7cff78e2 100644--- a/packages/opencode/src/bun/index.ts+++ b/packages/opencode/src/bun/index.ts@@ -7,6 +7,7 @@ import { NamedError } from "@opencode-ai/util/error"import { readableStreamToText } from "bun"import { Lock } from "../util/lock"import { PackageRegistry } from "./registry"+import { proxied } from "@/util/proxied"export namespace BunProc {const log = Log.create({ service: "bun" })@@ -86,20 +87,13 @@ export namespace BunProc {log.info("Cached version is outdated, proceeding with install", { pkg, cachedVersion })}- const proxied = !!(- process.env.HTTP_PROXY ||- process.env.HTTPS_PROXY ||- process.env.http_proxy ||- process.env.https_proxy- )-// Build command argumentsconst args = ["add","--force","--exact",// TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936)- ...(proxied ? ["--no-cache"] : []),+ ...(proxied() ? ["--no-cache"] : []),"--cwd",Global.Path.cache,pkg + "@" + version,diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.tsindex 91816a00fcc..5fde2aed87d 100644--- a/packages/opencode/src/config/config.ts+++ b/packages/opencode/src/config/config.ts@@ -29,6 +29,7 @@ import { Bus } from "@/bus"import { GlobalBus } from "@/bus/global"import { Event } from "../server/event"import { PackageRegistry } from "@/bun/registry"+import { proxied } from "@/util/proxied"export namespace Config {const log = Log.create({ service: "config" })@@ -247,13 +248,29 @@ export namespace Config {const hasGitIgnore = await Bun.file(gitignore).exists()if (!hasGitIgnore) await Bun.write(gitignore, ["node_modules", "package.json", "bun.lock", ".gitignore"].join("\n"))- await BunProc.run(["add", `@opencode-ai/plugin@${targetVersion}`, "--exact"], {- cwd: dir,- }).catch(() => {})+ await BunProc.run(+ [+ "add",+ `@opencode-ai/plugin@${targetVersion}`,+ "--exact",+ // TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936)+ ...(proxied() ? ["--no-cache"] : []),+ ],+ {+ cwd: dir,+ },+ ).catch(() => {})// Install any additional dependencies defined in the package.json// This allows local plugins and custom tools to use external packages- await BunProc.run(["install"], { cwd: dir }).catch(() => {})+ await BunProc.run(+ [+ "install",+ // TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936)+ ...(proxied() ? ["--no-cache"] : []),+ ],+ { cwd: dir },+ ).catch(() => {})}async function needsInstall(dir: string) {diff --git a/packages/opencode/src/util/proxied.ts b/packages/opencode/src/util/proxied.tsnew file mode 100644index 00000000000..440a9cccedb--- /dev/null+++ b/packages/opencode/src/util/proxied.ts@@ -0,0 +1,3 @@+export function proxied() {+ return !!(process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.http_proxy || process.env.https_proxy)+}