1import * as Effect from "effect/Effect";
2
3// Start the import at module evaluation (legal since workerd's 2025-03
4// importable-env change) so the isolate-lifetime layer build that awaits it
5// only ever sees an already-settled promise. This keeps the first event's
6// build free of I/O-backed awaits: everything after this is pure layer
7// assembly plus scheduler microtasks. Outside workerd (deploy/plan in Node,
8// vitest) the import rejects and the fallback stub is used; the `.catch` is
9// attached immediately so the rejection is always handled.
10// Type the import before chaining to avoid expanding the full module namespace
11// while TypeScript infers the catch result.
12const moduleImport: Promise<typeof import("cloudflare:workers")> =
13 import("cloudflare:workers");
14const modulePromise: Promise<typeof import("cloudflare:workers")> =
15 moduleImport.catch(
16 () =>
17 ({
18 env: {},
19 DurableObject: class {},
20 WorkflowEntrypoint: class {
21 async run() {}
22 },
23 }) as any,
24 );
25
26const cloudflare_workers: Effect.Effect<typeof import("cloudflare:workers")> =
27 Effect.promise(() => modulePromise);
28
29export default cloudflare_workers;