fix(shared): route Bun runtime calls through shims
This commit is contained in:
@@ -5,6 +5,30 @@ export type RuntimeSkillSourceServer = {
|
|||||||
readonly stop: () => void
|
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 {
|
function jsonResponse(body: unknown): Response {
|
||||||
return Response.json(body, {
|
return Response.json(body, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -25,6 +49,7 @@ function markdownResponse(markdown: string): Response {
|
|||||||
export function createRuntimeSkillSourceServer(options: {
|
export function createRuntimeSkillSourceServer(options: {
|
||||||
readonly skills: readonly RuntimeSkillSourceEntry[]
|
readonly skills: readonly RuntimeSkillSourceEntry[]
|
||||||
}): RuntimeSkillSourceServer {
|
}): RuntimeSkillSourceServer {
|
||||||
|
const bunRuntime = getBunServeRuntime()
|
||||||
const skillMarkdownByPath = new Map(
|
const skillMarkdownByPath = new Map(
|
||||||
options.skills.map((skill) => [`/${skill.name}/SKILL.md`, skill.markdown]),
|
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",
|
hostname: "127.0.0.1",
|
||||||
port: 0,
|
port: 0,
|
||||||
fetch(request) {
|
fetch(request) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { existsSync } from "node:fs"
|
import { existsSync } from "node:fs"
|
||||||
|
import { bunWhich } from "./bun-which-shim"
|
||||||
|
|
||||||
const GIT_EXECUTABLE_CANDIDATES = [
|
const GIT_EXECUTABLE_CANDIDATES = [
|
||||||
"/usr/bin/git",
|
"/usr/bin/git",
|
||||||
@@ -13,9 +14,5 @@ export function resolveGitExecutable(): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof Bun !== "undefined") {
|
return bunWhich("git") ?? "git"
|
||||||
return Bun.which("git") ?? "git"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "git"
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user