Showing the changes to apps/cli/src (1 of 2 files). Show all
Unified · Split
| @@ -18,7 +18,6 @@ if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) { · 17 unmodified lines | |||
| 18 | setQuickJSModule(mod); | 18 | setQuickJSModule(mod); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | import { spawn } from "node:child_process"; | ||
| 22 | import { resolve } from "node:path"; | 21 | import { resolve } from "node:path"; |
| 23 | import { Command, Options, Args } from "@effect/cli"; | 22 | import { Command, Options, Args } from "@effect/cli"; |
| 24 | import { BunRuntime } from "@effect/platform-bun"; | 23 | import { BunRuntime } from "@effect/platform-bun"; |
| @@ -74,33 +73,16 @@ const script = process.argv[1]; · 49 unmodified lines | |||
| 74 | const isDevMode = script?.endsWith(".ts") || script?.endsWith(".js"); | 73 | const isDevMode = script?.endsWith(".ts") || script?.endsWith(".js"); |
| 75 | const cliPrefix = isDevMode ? `bun run ${script}` : "executor"; | 74 | const cliPrefix = isDevMode ? `bun run ${script}` : "executor"; |
| 76 | 75 | ||
| 77 | const startBackgroundServer = (port: number): void => { | ||
| 78 | const args = isDevMode | ||
| 79 | ? ["run", script, "web", "--port", String(port)] | ||
| 80 | : ["web", "--port", String(port)]; | ||
| 81 | const child = spawn(process.execPath, args, { | ||
| 82 | detached: true, | ||
| 83 | stdio: "ignore", | ||
| 84 | }); | ||
| 85 | child.unref(); | ||
| 86 | }; | ||
| 87 | |||
| 88 | const ensureServer = (baseUrl: string) => | 76 | const ensureServer = (baseUrl: string) => |
| 89 | Effect.gen(function* () { | 77 | Effect.gen(function* () { |
| 90 | if (yield* Effect.promise(() => isServerReachable(baseUrl))) return; | 78 | if (yield* Effect.promise(() => isServerReachable(baseUrl))) return; |
| 91 | 79 | ||
| 80 | // Start server in-process instead of spawning a background child. | ||
| 81 | // This is more reliable across environments (containers, sandboxes, etc.) | ||
| 92 | const url = new URL(baseUrl); | 82 | const url = new URL(baseUrl); |
| 93 | const port = Number(url.port) || DEFAULT_PORT; | 83 | const port = Number(url.port) || DEFAULT_PORT; |
| 94 | console.error(`Starting background server on port ${port}...`); | 84 | console.error(`Starting server on port ${port}...`); |
| 95 | startBackgroundServer(port); | 85 | yield* Effect.promise(() => startServer({ port, embeddedWebUI })); |
| 96 | |||
| 97 | const deadline = Date.now() + 30_000; | ||
| 98 | while (Date.now() < deadline) { | ||
| 99 | yield* Effect.promise(() => new Promise((r) => setTimeout(r, 200))); | ||
| 100 | if (yield* Effect.promise(() => isServerReachable(baseUrl))) return; | ||
| 101 | } | ||
| 102 | |||
| 103 | return yield* Effect.fail(new Error(`Server failed to start within 30s at ${baseUrl}`)); | ||
| 104 | }); | 86 | }); |
| 105 | 87 | ||
| 106 | // --------------------------------------------------------------------------- | 88 | // --------------------------------------------------------------------------- |
| @@ -302,6 +284,11 @@ const runCli = Command.run(root, { · 195 unmodified lines | |||
| 302 | executable: CLI_NAME, | 284 | executable: CLI_NAME, |
| 303 | }); | 285 | }); |
| 304 | 286 | ||
| 287 | if (process.argv.includes("-v")) { | ||
| 288 | console.log(CLI_VERSION); | ||
| 289 | process.exit(0); | ||
| 290 | } | ||
| 291 | |||
| 305 | const program = runCli(process.argv).pipe( | 292 | const program = runCli(process.argv).pipe( |
| 306 | Effect.catchAllCause((cause) => | 293 | Effect.catchAllCause((cause) => |
| 307 | Effect.sync(() => { | 294 | Effect.sync(() => { |