| 1 | import type { |
| 2 | DurableObjectNamespace, |
| 3 | HyperdriveOrigin, |
| 4 | QueueConsumer, |
| 5 | RuntimeWorker, |
| 6 | Workflow, |
| 7 | } from "@alchemy.run/cloudflare-runtime/core"; |
| 8 | import type { BundleOutput } from "../../Bundle/Bundle.ts"; |
| 9 | import type { WorkerBinding } from "./WorkerBinding.ts"; |
| 10 | import type { WorkerAssetsConfig, WorkerSourceDescriptor } from "./Worker.ts"; |
| 11 | |
| 12 | /** |
| 13 | * Default first port of the local dev-server range. Vite and |
| 14 | * cloudflare-runtime advance to the next available port when it is taken, |
| 15 | * unless `strictPort` is set. |
| 16 | */ |
| 17 | export const DEFAULT_DEV_PORT = 1337; |
| 18 | |
| 19 | /** Plain-data configuration transferred from the provider to a Vite child. */ |
| 20 | export interface ViteChildConfig { |
| 21 | rootDir: string; |
| 22 | publicUrl: string; |
| 23 | accountId: string; |
| 24 | storageDirectory: string; |
| 25 | stack: { name: string; stage: string }; |
| 26 | env: Record<string, unknown>; |
| 27 | source?: { |
| 28 | descriptor: WorkerSourceDescriptor; |
| 29 | id: string; |
| 30 | fqn: string; |
| 31 | assets: WorkerAssetsConfig | undefined; |
| 32 | }; |
| 33 | worker: { |
| 34 | name: string; |
| 35 | compatibility: { date: string; flags: string[] }; |
| 36 | main: string | undefined; |
| 37 | viteEnvironments: { entry?: string; children?: string[] } | undefined; |
| 38 | hasAssets: boolean; |
| 39 | bindingDescriptors: WorkerBinding[]; |
| 40 | /** Binding name → opt-out of local emulation (`Alchemy.remote()`). */ |
| 41 | devRemote: Record<string, boolean>; |
| 42 | /** Simulated Cloudflare Access config (`dev: { access: ... }`). */ |
| 43 | devAccess?: { aud?: string; identity?: Record<string, unknown> }; |
| 44 | durableObjectNamespaces: (DurableObjectNamespace & { |
| 45 | uniqueKey: string; |
| 46 | })[]; |
| 47 | workflows: Workflow[]; |
| 48 | hyperdrives: Record<string, Required<HyperdriveOrigin>>; |
| 49 | queueConsumers: QueueConsumer[]; |
| 50 | crons: RuntimeWorker["crons"]; |
| 51 | assets: RuntimeWorker["assets"]; |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | export const VITE_CHILD_READY_PREFIX = "<ALCHEMY_VITE_ADDRESS>"; |
| 56 | export const VITE_CHILD_READY_SUFFIX = "</ALCHEMY_VITE_ADDRESS>"; |
| 57 | |
| 58 | /** |
| 59 | * Plain-data configuration transferred from the provider to a one-shot |
| 60 | * Vite *build* child (`ViteBuildChildRunner.ts`). Deliberately much |
| 61 | * smaller than {@link ViteChildConfig}: a production build needs no |
| 62 | * workerd runtime, credentials, or binding materialization. |
| 63 | */ |
| 64 | export interface ViteBuildChildConfig { |
| 65 | /** Absolute project root; also the child process's working directory. */ |
| 66 | rootDir: string; |
| 67 | /** |
| 68 | * `VITE_`-prefixed env entries — the only ones the build consumes |
| 69 | * (inlined as `import.meta.env.*` defines). |
| 70 | */ |
| 71 | env: Record<string, unknown>; |
| 72 | main: string | undefined; |
| 73 | compatibilityDate: string | undefined; |
| 74 | compatibilityFlags: string[] | undefined; |
| 75 | viteEnvironments: { entry?: string; children?: string[] } | undefined; |
| 76 | /** Absolute path the child writes the V8-serialized result to. */ |
| 77 | outputPath: string; |
| 78 | } |
| 79 | |
| 80 | /** Result the build child writes to `outputPath` (V8-serialized). */ |
| 81 | export interface ViteBuildChildResult { |
| 82 | clientDirectory: string | undefined; |
| 83 | base: string | undefined; |
| 84 | serverBundle: BundleOutput | undefined; |
| 85 | externalWorkspaces: string[]; |
| 86 | } |