@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 61 lines 2.22 KB
Raw
1 /**
2 * Cloudflare Workers deploy target for Octane.
3 *
4 * Alchemy preserves the native Octane compiler and client hooks, builds the
5 * server for Workers, and generates `dist/server/worker.js`. No adapter is
6 * required in `octane.config.ts`; existing Cloudflare adapters remain valid.
7 *
8 * Static assets are served first. Keep `notFoundHandling` unset so missing
9 * assets reach server-rendered routes. Cloudflare bindings are available in
10 * production and preview; native Octane HMR does not supply context.platform.
11 */
12 import * as Effect from "effect/Effect";
13 import { DeployTargetError, makeDeployTarget } from "../core/index.ts";
14 import { buildCloudflare } from "./CloudflareBuild.ts";
15 import type { OctaneTarget, OctaneTargetConfig } from "./Octane.ts";
16
17 /** The `adapter.name` Octane's Cloudflare adapter declares. */
18 export const ADAPTER_NAME = "cloudflare";
19
20 /** The npm package providing Octane's Cloudflare adapter. */
21 export const ADAPTER_PACKAGE = "@octanejs/adapter-cloudflare";
22
23 /** The Worker entry the adapter emits into the server output directory. */
24 export const SERVER_ENTRY_FILE_NAME = "worker.js";
25
26 /**
27 * Create the Cloudflare Workers {@link OctaneTarget}. See the module doc for
28 * the seams. The config's `compatibilityDate`/`compatibilityFlags` are
29 * carried for serve/deploy consumers; the build reuses Octane's native tooling.
30 */
31 export const makeCloudflareTarget = (config: OctaneTargetConfig = {}): OctaneTarget =>
32 makeDeployTarget({
33 platform: "cloudflare",
34 config,
35 bundle: {
36 conditions: ["workerd", "worker", "module", "browser"],
37 external: ["cloudflare:"],
38 },
39 adapterName: ADAPTER_NAME,
40 adapterPackage: ADAPTER_PACKAGE,
41 serverEntryFileName: SERVER_ENTRY_FILE_NAME,
42 build: (context) =>
43 buildCloudflare(context.root).pipe(
44 Effect.mapError(
45 (cause) =>
46 new DeployTargetError({
47 platform: "cloudflare",
48 message: cause.message,
49 cause,
50 }),
51 ),
52 ),
53 });
54
55 /**
56 * The deploy-target module contract (`resolveDeployTarget` accepts the
57 * default export — or the named `target` export — as a value or factory).
58 */
59 export const target = makeCloudflareTarget;
60
61 export default makeCloudflareTarget;