1import * as Namespace from "../../Namespace.ts";
2import { makeFrameworkSite, type FrameworkSiteProps } from "./FrameworkSite.ts";
3
4/** The framework-integration package that drives the SvelteKit build. */
5export const SVELTEKIT_FRAMEWORK_SPECIFIER =
6 "@alchemy.run/frontend-frameworks/sveltekit";
7
8/** The Node container deploy target for the SvelteKit build. */
9export const SVELTEKIT_NODE_TARGET_SPECIFIER =
10 "@alchemy.run/frontend-frameworks/sveltekit/node";
11
12export interface SvelteKitProps extends FrameworkSiteProps {
13 /**
14 * SvelteKit configuration passed to the `sveltekit(config)` Vite plugin
15 * (kit v3 takes its config in memory — a `svelte.config.js` on disk is an
16 * upstream error). The `adapter` field is injected by the Node deploy
17 * target and may not be set here. Must be JSON-serializable (it persists
18 * in state).
19 */
20 kit?: Record<string, unknown>;
21}
22
23/**
24 * Deploy a SvelteKit application to Railway: kit's SSR server plus
25 * prerendered assets on one `Railway.Service`. The Node deploy target
26 * injects an in-memory kit adapter; do not set `adapter` in `kit`.
27 *
28 * During `alchemy dev` the site is SvelteKit's own dev server and no cloud
29 * resources are created. `Alchemy.remote()` opts back into the live
30 * Service path.
31 *
32 * ### Creating SvelteKit Sites
33 * **Example:** Basic SvelteKit App
34 * ```typescript
35 * const site = yield* Railway.Website.SvelteKit("Web", {
36 * rootDir: "./app",
37 * });
38 * ```
39 *
40 * ### Server Configuration
41 * **Example:** Process Environment
42 * ```typescript
43 * const site = yield* Railway.Website.SvelteKit("Web", {
44 * rootDir: "./app",
45 * env: {
46 * API_BASE: "https://api.example.com",
47 * },
48 * });
49 * ```
50 *
51 * @resource
52 * @product Website
53 */
54export const SvelteKit = (id: string, props: SvelteKitProps = {}) =>
55 makeFrameworkSite(id, props, {
56 name: "SvelteKit",
57 framework: SVELTEKIT_FRAMEWORK_SPECIFIER,
58 target: SVELTEKIT_NODE_TARGET_SPECIFIER,
59 options: props.kit ? { kit: props.kit } : undefined,
60 }).pipe(Namespace.push(id));