Skip to content

Commit 211f29d

Browse files
committed
Fix runtime paths
1 parent f7bf24e commit 211f29d

2 files changed

Lines changed: 46 additions & 42 deletions

File tree

packages/start/src/config/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { defu } from "defu";
22
import { globSync } from "node:fs";
33
import { extname, isAbsolute, join } from "node:path";
4-
import { type PluginOption } from "vite";
4+
import { fileURLToPath } from "node:url";
5+
import { normalizePath, type PluginOption } from "vite";
56
import solid, { type Options as SolidOptions } from "vite-plugin-solid";
67
import { serverFunctionsPlugin } from "../directives/index.ts";
78
import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.ts";
@@ -180,6 +181,14 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
180181
// server fn exports added in by this plugin
181182
serverFunctionsPlugin({
182183
manifest: VIRTUAL_MODULES.serverFnManifest,
184+
runtime: {
185+
server: normalizePath(
186+
fileURLToPath(new URL("../server/server-fns-runtime.ts", import.meta.url)),
187+
),
188+
client: normalizePath(
189+
fileURLToPath(new URL("../server/server-runtime.ts", import.meta.url)),
190+
),
191+
},
183192
}),
184193
{
185194
name: "solid-start:virtual-modules",

packages/start/src/directives/index.ts

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { fileURLToPath } from "node:url";
21
import {
32
createFilter,
43
type EnvironmentModuleGraph,
54
type FilterPattern,
6-
normalizePath,
75
type Plugin,
86
type ViteDevServer,
97
} from "vite";
@@ -16,51 +14,17 @@ export interface ServerFunctionsFilter {
1614

1715
export interface ServerFunctionsOptions {
1816
manifest: string;
17+
runtime: {
18+
server: string;
19+
client: string;
20+
};
1921
filter?: ServerFunctionsFilter;
2022
}
2123

22-
const CLIENT_PATH = normalizePath(
23-
fileURLToPath(new URL("../server/server-runtime.ts", import.meta.url)),
24-
);
25-
const SERVER_PATH = normalizePath(
26-
fileURLToPath(new URL("../server/server-fns-runtime.ts", import.meta.url)),
27-
);
28-
2924
const DEFAULT_INCLUDE = "src/**/*.{jsx,tsx,ts,js,mjs,cjs}";
3025
const DEFAULT_EXCLUDE = "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}";
3126
const DIRECTIVE = "use server";
3227

33-
const CLIENT_OPTIONS: Pick<CompileOptions, "directive" | "definitions"> = {
34-
directive: DIRECTIVE,
35-
definitions: {
36-
register: {
37-
kind: "named",
38-
name: "createServerReference",
39-
source: CLIENT_PATH,
40-
},
41-
clone: {
42-
kind: "named",
43-
name: "cloneServerReference",
44-
source: CLIENT_PATH,
45-
},
46-
},
47-
};
48-
const SERVER_OPTIONS: Pick<CompileOptions, "directive" | "definitions"> = {
49-
directive: DIRECTIVE,
50-
definitions: {
51-
register: {
52-
kind: "named",
53-
name: "createServerReference",
54-
source: SERVER_PATH,
55-
},
56-
clone: {
57-
kind: "named",
58-
name: "cloneServerReference",
59-
source: SERVER_PATH,
60-
},
61-
},
62-
};
63-
6428
type Manifest = Record<CompileOptions["mode"], Set<string>>;
6529

6630
function createManifest(): Manifest {
@@ -165,6 +129,37 @@ export function serverFunctionsPlugin(options: ServerFunctionsOptions): Plugin[]
165129
};
166130
let currentServer: ViteDevServer;
167131

132+
const clientOptions: Pick<CompileOptions, "directive" | "definitions"> = {
133+
directive: DIRECTIVE,
134+
definitions: {
135+
register: {
136+
kind: "named",
137+
name: "createServerReference",
138+
source: options.runtime.client,
139+
},
140+
clone: {
141+
kind: "named",
142+
name: "cloneServerReference",
143+
source: options.runtime.client,
144+
},
145+
},
146+
};
147+
const serverOptions: Pick<CompileOptions, "directive" | "definitions"> = {
148+
directive: DIRECTIVE,
149+
definitions: {
150+
register: {
151+
kind: "named",
152+
name: "createServerReference",
153+
source: options.runtime.server,
154+
},
155+
clone: {
156+
kind: "named",
157+
name: "cloneServerReference",
158+
source: options.runtime.server,
159+
},
160+
},
161+
};
162+
168163
return [
169164
{
170165
name: "solid-start:server-functions/setup",
@@ -208,7 +203,7 @@ export function serverFunctionsPlugin(options: ServerFunctionsOptions): Plugin[]
208203
}
209204

210205
const result = await compile(id!, code, {
211-
...(mode === "server" ? SERVER_OPTIONS : CLIENT_OPTIONS),
206+
...(mode === "server" ? serverOptions : clientOptions),
212207
mode,
213208
env,
214209
});

0 commit comments

Comments
 (0)