@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 109 lines 3.92 KB
Raw
1 /**
2 * `@alchemy.run/frontend-frameworks/solidstart/node` — the Node container
3 * deploy target for the SolidStart integration.
4 *
5 * SolidStart's Node story is nitro's `node` (node-listener) preset:
6 * `.output/server` is a self-contained Node ESM bundle whose entry exports
7 * a Node `(req, res)` `handler`, and `.output/public` holds the static
8 * assets. The finishing pass writes a Node HTTP program that serves
9 * `clientDirectory` first, then falls through to that handler on `PORT`
10 * (default 3000), and answers `GET /health`.
11 *
12 * - **`nitroPreset`** — `"node"`, enforced as the last word on the
13 * resolved nitro config. A user `nitro.preset` mismatch fails the build.
14 * - **`bundle`** — Node resolve conditions (no `workerd`, no `@aws-sdk/`).
15 *
16 * Do not use the `aws-lambda` preset: that emits a Lambda `handler`, not a
17 * Node listener.
18 */
19 import * as Effect from "effect/Effect";
20 import * as Path from "effect/Path";
21 import { runBuildChild } from "../core/BuildChild.ts";
22 import { DeployTargetError, makeDeployTarget } from "../core/index.ts";
23 import {
24 NODE_BUNDLE_CONDITIONS,
25 NODE_SERVE_ENTRY_FILE_NAME,
26 relativeClientDirExpression,
27 writeNodeServeEntry,
28 } from "../core/NodeServe.ts";
29 import { make, type SolidStartTarget, type SolidStartTargetConfig } from "./SolidStart.ts";
30
31 /** The nitro deployment preset this target builds with. */
32 export const NITRO_PRESET = "node";
33
34 /**
35 * The importable specifier of nitro's node-listener runtime handler — the
36 * module a USER entry re-exports to wrap the framework's handler.
37 */
38 export const NITRO_HANDLER_SPECIFIER = "nitropack/presets/node/runtime/node-listener";
39
40 export interface SolidStartNodeTargetConfig extends SolidStartTargetConfig {}
41
42 const fail = (message: string, cause?: unknown) =>
43 new DeployTargetError({ platform: "node", message, cause });
44
45 const makeNodeAdapterTarget = (config: SolidStartNodeTargetConfig = {}): SolidStartTarget =>
46 makeDeployTarget({
47 platform: "node",
48 config,
49 bundle: {
50 conditions: [...NODE_BUNDLE_CONDITIONS],
51 },
52 nitroPreset: NITRO_PRESET,
53 finish: (output) =>
54 Effect.gen(function* () {
55 const path = yield* Path.Path;
56 if (output.distDirectory === undefined || output.clientDirectory === undefined) {
57 return yield* fail(
58 "The SolidStart build produced no .output directories for the Node serve entry",
59 );
60 }
61 const servePath = path.join(output.distDirectory, "server", NODE_SERVE_ENTRY_FILE_NAME);
62 return yield* writeNodeServeEntry({
63 output,
64 servePath,
65 serveModuleName: path.join("server", NODE_SERVE_ENTRY_FILE_NAME).replaceAll("\\", "/"),
66 clientDirExpression: relativeClientDirExpression(servePath, output.clientDirectory),
67 handler: {
68 kind: "node",
69 imports: `import { handler } from "./index.mjs";`,
70 expr: "handler",
71 },
72 platform: "node",
73 });
74 }),
75 });
76
77 export interface SolidStartNodeBuildChildConfig {
78 readonly rootDir: string;
79 readonly config: SolidStartNodeTargetConfig;
80 }
81
82 export const buildInChild = (config: SolidStartNodeBuildChildConfig) =>
83 Effect.gen(function* () {
84 const framework = yield* make({
85 root: config.rootDir,
86 target: makeNodeAdapterTarget(config.config),
87 nitro: config.config.nitro,
88 });
89 return yield* framework.build({ root: config.rootDir });
90 });
91
92 export const makeNodeTarget = (config: SolidStartNodeTargetConfig = {}): SolidStartTarget => ({
93 ...makeNodeAdapterTarget(config),
94 build: (context) =>
95 runBuildChild({
96 module: import.meta.url,
97 rootDir: context.root,
98 env: context.env,
99 framework: "solidstart",
100 config: {
101 rootDir: context.root,
102 config,
103 } satisfies SolidStartNodeBuildChildConfig,
104 }).pipe(Effect.mapError((error) => fail(error.message, error.cause))),
105 });
106
107 export const target = makeNodeTarget;
108
109 export default makeNodeTarget;