1import type { CloudflareVitePluginOptions } from "@alchemy.run/cloudflare-runtime/vite";
2import { makeWakuCloudflareTarget } from "../waku/cloudflare.ts";
3import type { VocsTarget } from "./Target.ts";
4
5export type { CloudflareVitePluginOptions } from "@alchemy.run/cloudflare-runtime/vite";
6
7/** Cloudflare configuration for the Vocs runtime. */
8export 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 */
19export 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
32export default target;