fix(shared): route Bun runtime calls through shims

This commit is contained in:
YeonGyu-Kim
2026-05-31 00:10:29 +09:00
parent db8a35d2cf
commit 66ee12ce85
2 changed files with 28 additions and 6 deletions
@@ -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<Response>
}): 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) {
+2 -5
View File
@@ -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"
}