| 1 | import type { CloudflareVitePluginOptions } from "@alchemy.run/cloudflare-runtime/vite"; |
| 2 | import { makeWakuCloudflareTarget } from "../waku/cloudflare.ts"; |
| 3 | import type { VocsTarget } from "./Target.ts"; |
| 4 | |
| 5 | export type { CloudflareVitePluginOptions } from "@alchemy.run/cloudflare-runtime/vite"; |
| 6 | |
| 7 | /** Cloudflare configuration for the Vocs runtime. */ |
| 8 | export interface VocsCloudflareConfig { |
| 9 | readonly worker?: CloudflareVitePluginOptions | undefined; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Build the Cloudflare target for Vocs. |
| 14 | * |
| 15 | * The adapter and RSC environment topology are the established Waku target; |
| 16 | * Vocs adds the stronger `nodejs_compat` requirement needed by its server |
| 17 | * bundle (`node:fs` and related guarded imports). |
| 18 | */ |
| 19 | export const target = ( |
| 20 | config: VocsCloudflareConfig = {}, |
| 21 | ): VocsTarget<CloudflareVitePluginOptions | undefined> => { |
| 22 | const worker = config.worker; |
| 23 | const flags = worker?.compatibilityFlags; |
| 24 | return makeWakuCloudflareTarget({ |
| 25 | ...worker, |
| 26 | compatibilityFlags: flags?.includes("nodejs_compat") |
| 27 | ? flags |
| 28 | : [...(flags ?? []), "nodejs_compat"], |
| 29 | }); |
| 30 | }; |
| 31 | |
| 32 | export default target; |