From 66ee12ce85639890bb25e695bd4dfa15b31fd716 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 31 May 2026 00:10:29 +0900 Subject: [PATCH] fix(shared): route Bun runtime calls through shims --- .../opencode-runtime-skills/source-server.ts | 27 ++++++++++++++++++- src/shared/git-executable.ts | 7 ++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/features/opencode-runtime-skills/source-server.ts b/src/features/opencode-runtime-skills/source-server.ts index 6a5ef7e4e..867567dac 100644 --- a/src/features/opencode-runtime-skills/source-server.ts +++ b/src/features/opencode-runtime-skills/source-server.ts @@ -5,6 +5,30 @@ export type RuntimeSkillSourceServer = { readonly stop: () => void } +type BunServeServer = { + readonly url: URL + stop(closeActiveConnections?: boolean): void +} + +type BunServeRuntime = { + serve(options: { + readonly hostname: string + readonly port: number + readonly fetch: (request: Request) => Response | Promise + }): BunServeServer +} + +const runtime = globalThis as typeof globalThis & { Bun?: BunServeRuntime } + +function getBunServeRuntime(): BunServeRuntime { + const bunRuntime = runtime.Bun + if (typeof bunRuntime === "undefined") { + throw new Error("createRuntimeSkillSourceServer requires Bun runtime") + } + + return bunRuntime +} + function jsonResponse(body: unknown): Response { return Response.json(body, { headers: { @@ -25,6 +49,7 @@ function markdownResponse(markdown: string): Response { export function createRuntimeSkillSourceServer(options: { readonly skills: readonly RuntimeSkillSourceEntry[] }): RuntimeSkillSourceServer { + const bunRuntime = getBunServeRuntime() const skillMarkdownByPath = new Map( options.skills.map((skill) => [`/${skill.name}/SKILL.md`, skill.markdown]), ) @@ -35,7 +60,7 @@ export function createRuntimeSkillSourceServer(options: { })), } - const server = Bun.serve({ + const server = bunRuntime.serve({ hostname: "127.0.0.1", port: 0, fetch(request) { diff --git a/src/shared/git-executable.ts b/src/shared/git-executable.ts index f5ad478f4..08daed8a5 100644 --- a/src/shared/git-executable.ts +++ b/src/shared/git-executable.ts @@ -1,4 +1,5 @@ import { existsSync } from "node:fs" +import { bunWhich } from "./bun-which-shim" const GIT_EXECUTABLE_CANDIDATES = [ "/usr/bin/git", @@ -13,9 +14,5 @@ export function resolveGitExecutable(): string { } } - if (typeof Bun !== "undefined") { - return Bun.which("git") ?? "git" - } - - return "git" + return bunWhich("git") ?? "git" }