| 1 | // Minimal manual runner for the hmr dev mode: invokes the Framework service |
| 2 | // directly (no playwright), starts `next dev` with proxied bindings, probes |
| 3 | // three routes, and exits. Useful for debugging test/hmr.test.ts failures. |
| 4 | // Run with: node scripts/hmr-repro.mjs |
| 5 | import { Text } from "@alchemy.run/cloudflare-runtime/core/bindings"; |
| 6 | import { Framework } from "@alchemy.run/frontend-frameworks/core"; |
| 7 | import nextjsFramework from "@alchemy.run/frontend-frameworks/nextjs"; |
| 8 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 9 | import * as Exit from "effect/Exit"; |
| 10 | import * as Layer from "effect/Layer"; |
| 11 | import * as ManagedRuntime from "effect/ManagedRuntime"; |
| 12 | import * as Scope from "effect/Scope"; |
| 13 | import { fileURLToPath } from "node:url"; |
| 14 | |
| 15 | const root = fileURLToPath(new URL("..", import.meta.url)); |
| 16 | |
| 17 | const layer = nextjsFramework({ |
| 18 | root, |
| 19 | dev: { mode: "hmr" }, |
| 20 | vite: { |
| 21 | compatibilityDate: "2026-05-12", |
| 22 | compatibilityFlags: ["nodejs_compat", "global_fetch_strictly_public"], |
| 23 | worker: { |
| 24 | name: "fixtures-nextjs-hmr", |
| 25 | bindings: [Text.local("TEST_TEXT", "hello-from-binding")], |
| 26 | }, |
| 27 | }, |
| 28 | }).pipe(Layer.provideMerge(NodeServices.layer)); |
| 29 | |
| 30 | const runtime = ManagedRuntime.make(layer); |
| 31 | const scope = Scope.makeUnsafe(); |
| 32 | const server = await runtime.runPromise( |
| 33 | Framework.use((f) => f.dev({ root })).pipe(Scope.provide(scope)), |
| 34 | ); |
| 35 | console.log("dev server:", server.url); |
| 36 | for (const path of ["/", "/hmr-probe", "/api/binding"]) { |
| 37 | const res = await fetch(new URL(path, server.url)); |
| 38 | const body = await res.text(); |
| 39 | console.log(path, res.status, body.slice(0, 300).replace(/\n/g, " ")); |
| 40 | } |
| 41 | await runtime.runPromise(Scope.close(scope, Exit.void)); |
| 42 | await runtime.dispose(); |
| 43 | process.exit(0); |