fix desktop plugin startup without Bun

This commit is contained in:
YeonGyu-Kim
2026-05-07 13:40:06 +09:00
parent 4bcbbdd966
commit 788fbec0d7
2 changed files with 51 additions and 1 deletions
+40
View File
@@ -1,6 +1,10 @@
/// <reference types="bun-types" />
import { describe, expect, test } from "bun:test"
import { spawnSync } from "node:child_process"
import { mkdtempSync, rmSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { TmuxConfigSchema } from "./config/schema/tmux"
import { createRuntimeTmuxConfig } from "./create-runtime-tmux-config"
@@ -14,4 +18,40 @@ describe("createRuntimeTmuxConfig", () => {
expect(runtimeTmuxConfig.isolation).toBe(schemaDefault)
})
})
describe("#given the runtime does not expose Bun", () => {
test("#when interactive bash availability is checked from a bundled module #then it returns false without crashing", async () => {
const outdir = mkdtempSync(join(tmpdir(), "omo-desktop-runtime-"))
try {
const build = await Bun.build({
entrypoints: [join(import.meta.dir, "create-runtime-tmux-config.ts")],
outdir,
target: "bun",
format: "esm",
})
expect(build.success).toBe(true)
const result = spawnSync(Bun.which("node") ?? "node", [
"--input-type=module",
"-e",
`import { pathToFileURL } from "node:url";
const mod = await import(pathToFileURL(process.env.MODULE_PATH).href);
console.log(String(mod.isInteractiveBashEnabled()));`,
], {
env: {
...process.env,
MODULE_PATH: join(outdir, "create-runtime-tmux-config.js"),
},
encoding: "utf8",
})
expect(result.stderr).toBe("")
expect(result.status).toBe(0)
expect(result.stdout.trim()).toBe("false")
} finally {
rmSync(outdir, { recursive: true, force: true })
}
})
})
})
+11 -1
View File
@@ -1,6 +1,16 @@
import type { OhMyOpenCodeConfig, TmuxConfig } from "./config"
import { TmuxConfigSchema } from "./config/schema/tmux"
type RuntimeWithBun = typeof globalThis & {
Bun?: {
which(binary: string): string | null
}
}
function defaultWhich(binary: string): string | null {
return (globalThis as RuntimeWithBun).Bun?.which(binary) ?? null
}
export function isTmuxIntegrationEnabled(
pluginConfig: { tmux?: { enabled?: boolean } | undefined },
): boolean {
@@ -8,7 +18,7 @@ export function isTmuxIntegrationEnabled(
}
export function isInteractiveBashEnabled(
which: (binary: string) => string | null = Bun.which,
which: (binary: string) => string | null = defaultWhich,
): boolean {
return which("tmux") !== null
}