Skip to content

Commit a2c28fc

Browse files
authored
fix: ensure that plugin installs use --no-cache when using http proxy to prevent random hangs (see bun issue) (anomalyco#12161)
1 parent ce87121 commit a2c28fc

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

packages/opencode/src/bun/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { NamedError } from "@opencode-ai/util/error"
77
import { readableStreamToText } from "bun"
88
import { Lock } from "../util/lock"
99
import { PackageRegistry } from "./registry"
10+
import { proxied } from "@/util/proxied"
1011

1112
export namespace BunProc {
1213
const log = Log.create({ service: "bun" })
@@ -86,20 +87,13 @@ export namespace BunProc {
8687
log.info("Cached version is outdated, proceeding with install", { pkg, cachedVersion })
8788
}
8889

89-
const proxied = !!(
90-
process.env.HTTP_PROXY ||
91-
process.env.HTTPS_PROXY ||
92-
process.env.http_proxy ||
93-
process.env.https_proxy
94-
)
95-
9690
// Build command arguments
9791
const args = [
9892
"add",
9993
"--force",
10094
"--exact",
10195
// TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936)
102-
...(proxied ? ["--no-cache"] : []),
96+
...(proxied() ? ["--no-cache"] : []),
10397
"--cwd",
10498
Global.Path.cache,
10599
pkg + "@" + version,

packages/opencode/src/config/config.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Bus } from "@/bus"
2929
import { GlobalBus } from "@/bus/global"
3030
import { Event } from "../server/event"
3131
import { PackageRegistry } from "@/bun/registry"
32+
import { proxied } from "@/util/proxied"
3233

3334
export namespace Config {
3435
const log = Log.create({ service: "config" })
@@ -247,13 +248,29 @@ export namespace Config {
247248
const hasGitIgnore = await Bun.file(gitignore).exists()
248249
if (!hasGitIgnore) await Bun.write(gitignore, ["node_modules", "package.json", "bun.lock", ".gitignore"].join("\n"))
249250

250-
await BunProc.run(["add", `@opencode-ai/plugin@${targetVersion}`, "--exact"], {
251-
cwd: dir,
252-
}).catch(() => {})
251+
await BunProc.run(
252+
[
253+
"add",
254+
`@opencode-ai/plugin@${targetVersion}`,
255+
"--exact",
256+
// TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936)
257+
...(proxied() ? ["--no-cache"] : []),
258+
],
259+
{
260+
cwd: dir,
261+
},
262+
).catch(() => {})
253263

254264
// Install any additional dependencies defined in the package.json
255265
// This allows local plugins and custom tools to use external packages
256-
await BunProc.run(["install"], { cwd: dir }).catch(() => {})
266+
await BunProc.run(
267+
[
268+
"install",
269+
// TODO: get rid of this case (see: https://github.com/oven-sh/bun/issues/19936)
270+
...(proxied() ? ["--no-cache"] : []),
271+
],
272+
{ cwd: dir },
273+
).catch(() => {})
257274
}
258275

259276
async function needsInstall(dir: string) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function proxied() {
2+
return !!(process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.http_proxy || process.env.https_proxy)
3+
}

0 commit comments

Comments
 (0)