1/**
2 * A REAL user-owned Vite config, exactly like a normal SvelteKit v3 project:
3 * `sveltekit()` is registered here by the user (kit v3 has no
4 * `svelte.config.js` — all kit options live in this call), alongside a user
5 * Vite plugin. `@alchemy.run/frontend-frameworks/sveltekit` must load this file natively and
6 * inject its deploy-target adapter into THIS `sveltekit(...)` instance rather
7 * than constructing a second one.
8 *
9 * The suite proves the file is honored end-to-end (`/api/user-config`, live
10 * and dev):
11 *
12 * - `alias: { $fixture: ... }` — a user kit option that only works if the
13 * user's `sveltekit()` call is the one that runs.
14 * - `fixtureMarkerPlugin` — a user Vite plugin whose virtual module is
15 * observable in the build output.
16 * - `adapter: userDeclaredAdapter` — a user-declared adapter that THROWS if
17 * it ever runs: the integration must replace it (with a warning) with the
18 * deploy target's adapter, so a green build is proof of the override.
19 */
20import type { Adapter } from "@sveltejs/kit";
21import { sveltekit } from "@sveltejs/kit/vite";
22import type { Plugin } from "vite";
23import { defineConfig } from "vite";
24
25const VIRTUAL_ID = "virtual:fixture-marker";
26const RESOLVED_ID = `\0${VIRTUAL_ID}`;
27
28const fixtureMarkerPlugin = (): Plugin => ({
29 name: "fixture-user-vite-plugin",
30 resolveId(id) {
31 if (id === VIRTUAL_ID) {
32 return RESOLVED_ID;
33 }
34 },
35 load(id) {
36 if (id === RESOLVED_ID) {
37 return `export const marker = "user-vite-plugin-active";`;
38 }
39 },
40});
41
42const userDeclaredAdapter: Adapter = {
43 name: "fixture-user-adapter",
44 adapt() {
45 throw new Error(
46 "fixture-user-adapter ran — the integration failed to inject the deploy target's adapter",
47 );
48 },
49};
50
51export default defineConfig({
52 plugins: [
53 fixtureMarkerPlugin(),
54 sveltekit({
55 adapter: userDeclaredAdapter,
56 alias: { $fixture: "src/fixture" },
57 }),
58 ],
59});