@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, 04:45 UTC

main
ts 85 lines 3.68 KB
Raw
1 import type { AstroInlineConfig, AstroIntegration } from "astro";
2 import type * as Effect from "effect/Effect";
3 /**
4 * The Astro-specific deploy-target contract.
5 *
6 * framework-core's generic `DeployTarget` covers the platform-neutral seams
7 * (`bundle`, `build`, `finish`, `serve`, opaque `config`). Astro needs one
8 * framework-specific hook on top: the Astro *integration* (the adapter) that
9 * gets pinned into the in-memory `AstroInlineConfig` for both `dev` and
10 * `build`. Everything platform-specific — which vite plugins the adapter
11 * injects, which server entrypoint it selects, how dev SSR executes — lives
12 * inside that integration, so the framework half of this package never has to
13 * know the platform.
14 *
15 * The Cloudflare implementation ships at `@alchemy.run/frontend-frameworks/astro/cloudflare`;
16 * a future platform (AWS, ...) implements the same interface as a new subpath
17 * without any change to the framework module.
18 */
19 import {
20 isDeployTarget,
21 type BuildOutput,
22 type DeployTarget,
23 type DeployTargetBuildContext,
24 type DeployTargetError,
25 type DeployTargetInput,
26 type DeployTargetServices,
27 type ServerEntryChunk,
28 } from "../core/index.ts";
29
30 /**
31 * The context an Astro target's wholesale `build` takeover receives: the
32 * generic build context plus the inline Astro overlay the framework was
33 * constructed with (`AstroFrameworkOptions.astro`) — carried so wholesale
34 * targets that re-run the framework in a child process (the AWS target)
35 * can reconstruct it. Only JSON-serializable fields survive that process
36 * boundary.
37 */
38 export interface AstroTargetBuildContext extends DeployTargetBuildContext {
39 readonly astro?: AstroInlineConfig | undefined;
40 }
41
42 export interface AstroTarget<Config = unknown> extends DeployTarget<Config> {
43 /**
44 * Build the Astro adapter integration pinned into the inline config
45 * (`AstroInlineConfig.adapter`). Called once per `dev`/`build` operation.
46 */
47 readonly integration: () => AstroIntegration;
48 /**
49 * Optional *wholesale* build takeover (see `DeployTarget.build`), with
50 * the Astro-specific {@link AstroTargetBuildContext}.
51 */
52 readonly build?:
53 | ((
54 context: AstroTargetBuildContext,
55 ) => Effect.Effect<BuildOutput, DeployTargetError, DeployTargetServices>)
56 | undefined;
57 /**
58 * Optional entry-chunk pin for the build-output collector: astro's page
59 * modules are rolldown inputs of the `ssr` environment, so it emits many
60 * entry chunks. A target whose adapter entry is not otherwise
61 * identifiable (e.g. the AWS target's `serverEntrypoint`, which astro
62 * renames to `config.build.serverEntry`) selects the chunk that becomes
63 * `serverModules[0]` here. The Cloudflare target does not need it — its
64 * vite plugin wraps the worker entry with a recognizable facade.
65 */
66 readonly selectServerEntry?: ((chunk: ServerEntryChunk) => boolean) | undefined;
67 }
68
69 /**
70 * How a target reaches the Astro framework module: a target value, a
71 * `(config) => AstroTarget` factory, or a module specifier resolved from the
72 * *project's* `node_modules` (whose `default` — or named `target` — export is
73 * the value or factory).
74 */
75 export type AstroTargetInput<Config = unknown> = DeployTargetInput<AstroTarget<Config>, Config>;
76
77 /**
78 * The default target module: the Cloudflare implementation shipped by this
79 * package, resolved from the project's own dependency tree.
80 */
81 export const DEFAULT_TARGET_SPECIFIER = "@alchemy.run/frontend-frameworks/astro/cloudflare";
82
83 /** Structural guard: a `DeployTarget` carrying the Astro `integration` hook. */
84 export const isAstroTarget = (value: unknown): value is AstroTarget =>
85 isDeployTarget(value) && typeof (value as { integration?: unknown }).integration === "function";