The best way to control Claude Code, Codex and more from any computer or phone

main
mjs 49 lines 1.97 KB
Raw
1 import { fileURLToPath } from "node:url";
2 // Long-running driver for the hmr dev mode, spawned by test/hmr.test.ts:
3 // starts `next dev` (Turbopack) with proxied Cloudflare bindings via the
4 // Framework service and prints `DEV_URL <url>` when ready. Runs until
5 // SIGTERM/SIGINT, then closes the scope (stopping Next, the http server,
6 // and the binding proxy) and exits.
7 //
8 // The spec runs the server in a child process on purpose: `next dev`
9 // installs its own require hooks, which collide with playwright's in-worker
10 // transform (`Cannot read properties of undefined (reading '.js')`) — and a
11 // child process is also how the dev server runs in real life.
12 import { Text } from "@alchemy.run/cloudflare-runtime/core/bindings";
13 import { Framework } from "@alchemy.run/frontend-frameworks/core";
14 import nextjsFramework from "@alchemy.run/frontend-frameworks/nextjs";
15 import * as NodeServices from "@effect/platform-node/NodeServices";
16 import * as Exit from "effect/Exit";
17 import * as Layer from "effect/Layer";
18 import * as ManagedRuntime from "effect/ManagedRuntime";
19 import * as Scope from "effect/Scope";
20
21 const root = fileURLToPath(new URL("..", import.meta.url));
22
23 const layer = nextjsFramework({
24 root,
25 dev: { mode: "hmr" },
26 vite: {
27 compatibilityDate: "2026-05-12",
28 compatibilityFlags: ["nodejs_compat", "global_fetch_strictly_public"],
29 worker: {
30 name: "fixtures-nextjs-hmr",
31 bindings: [Text.local("TEST_TEXT", "hello-from-binding")],
32 },
33 },
34 }).pipe(Layer.provideMerge(NodeServices.layer));
35
36 const runtime = ManagedRuntime.make(layer);
37 const scope = Scope.makeUnsafe();
38 const server = await runtime.runPromise(
39 Framework.use((f) => f.dev({ root })).pipe(Scope.provide(scope)),
40 );
41 console.log(`DEV_URL ${server.url}`);
42
43 const shutdown = async () => {
44 await runtime.runPromise(Scope.close(scope, Exit.void)).catch(() => undefined);
45 await runtime.dispose().catch(() => undefined);
46 process.exit(0);
47 };
48 process.on("SIGTERM", shutdown);
49 process.on("SIGINT", shutdown);