| 48 | function executorApiPlugin(): Plugin { |
| 49 | let handlerPromise: Promise<{ handler: (request: Request) => Promise<Response> }> | null = null; |
| 50 | const getHandler = async () => { |
| 51 | if (!handlerPromise) { |
| 52 | // Computed specifier so Vite's Node-based config loader does NOT statically |
| 53 | // follow this into ./src/api/api (which imports @executor-js/host-mcp, whose |
| 54 | // extensionless re-exports resolve under Bun but not Node ESM). It only runs |
| 55 | // at dev-server request time, under `bunx --bun vite dev`. |
| 56 | const apiModule = new URL("./src/api/api.ts", import.meta.url).href; |
| 57 | handlerPromise = import(apiModule).then((m) => m.makeSelfHostApiHandler()); |
| 58 | } |
| 59 | return handlerPromise; |
| 60 | }; |
| 61 | |
| 62 | return { |
| 63 | name: "executor-selfhost-api", |