Skip to content

Commit 6da636b

Browse files
lxsmnsyckatywings
andauthored
fix: server functions inclusivity + runtime exports (#2127)
Co-authored-by: Katja Lutz <mail@katjalutz.ch>
1 parent 9d5d783 commit 6da636b

12 files changed

Lines changed: 31 additions & 21 deletions

File tree

.changeset/eight-pears-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": patch
3+
---
4+
5+
The server function directives runtime is now internally accessed via package.json exports instead of relative paths, fixing inconsistencies in the file resolution. Also the server functions file inclusion/exclusion patterns can now be configured in the start plugin options via `serverFunctions`.

packages/start/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"./client/spa": "./src/client/spa/index.tsx",
2020
"./middleware": "./src/middleware/index.ts",
2121
"./http": "./src/http/index.ts",
22-
"./env": "./env.d.ts"
22+
"./env": "./env.d.ts",
23+
"./fns/server": "./src/fns/server.ts",
24+
"./fns/client": "./src/fns/client.ts"
2325
},
2426
"publishConfig": {
2527
"access": "public",
@@ -33,7 +35,9 @@
3335
"./client/spa": "./dist/client/spa/index.jsx",
3436
"./middleware": "./dist/middleware/index.js",
3537
"./http": "./dist/http/index.js",
36-
"./env": "./env.d.ts"
38+
"./env": "./env.d.ts",
39+
"./fns/server": "./dist/fns/server.js",
40+
"./fns/client": "./dist/fns/client.js"
3741
}
3842
},
3943
"dependencies": {

packages/start/src/config/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { defu } from "defu";
22
import { globSync } from "node:fs";
33
import { extname, isAbsolute, join } from "node:path";
4-
import { fileURLToPath } from "node:url";
5-
import { normalizePath, type PluginOption } from "vite";
4+
import type { PluginOption } from "vite";
65
import solid, { type Options as SolidOptions } from "vite-plugin-solid";
7-
import { serverFunctionsPlugin } from "../directives/index.ts";
6+
import { type ServerFunctionsOptions, serverFunctionsPlugin } from "../directives/index.ts";
87
import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.ts";
98
import { devServer } from "./dev-server.ts";
10-
import { type EnvPluginOptions, envPlugin } from "./env.ts";
9+
import { envPlugin, type EnvPluginOptions } from "./env.ts";
1110
import { SolidStartClientFileRouter, SolidStartServerFileRouter } from "./fs-router.ts";
1211
import { fsRoutes } from "./fs-routes/index.ts";
1312
import type { BaseFileSystemRouter } from "./fs-routes/router.ts";
@@ -33,6 +32,7 @@ export interface SolidStartOptions {
3332
mode?: "js" | "json";
3433
};
3534
env?: EnvPluginOptions;
35+
serverFunctions?: Pick<ServerFunctionsOptions, "filter">;
3636
}
3737

3838
const absolute = (path: string, root: string) =>
@@ -144,6 +144,9 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
144144
}
145145
: {}),
146146
},
147+
// Depending on the package manager and dependency structure Vite externalizes @solidjs/start
148+
// This makes sure that @solidjs/start goes through the Vite build process
149+
noExternal: ["@solidjs/start"],
147150
},
148151
define: {
149152
"import.meta.env.MANIFEST": `globalThis.MANIFEST`,
@@ -192,13 +195,10 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
192195
serverFunctionsPlugin({
193196
manifest: VIRTUAL_MODULES.serverFnManifest,
194197
runtime: {
195-
server: normalizePath(
196-
fileURLToPath(new URL("../server/server-fns-runtime.ts", import.meta.url)),
197-
),
198-
client: normalizePath(
199-
fileURLToPath(new URL("../server/server-runtime.ts", import.meta.url)),
200-
),
198+
server: '@solidjs/start/fns/server',
199+
client: '@solidjs/start/fns/client',
201200
},
201+
filter: options?.serverFunctions?.filter,
202202
}),
203203
{
204204
name: "solid-start:virtual-modules",

packages/start/src/directives/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function invalidateModules(
113113
}
114114
}
115115

116+
116117
export function serverFunctionsPlugin(options: ServerFunctionsOptions): Plugin[] {
117118
const filter = createFilter(
118119
options.filter?.include || DEFAULT_INCLUDE,

packages/start/src/server/server-runtime.ts renamed to packages/start/src/fns/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
BodyFormat,
99
extractBody,
1010
getHeadersAndBody,
11-
} from "./server-functions-shared.ts";
11+
} from "./shared.ts";
1212

1313
let INSTANCE = 0;
1414

File renamed without changes.

packages/start/src/server/server-functions-handler.ts renamed to packages/start/src/fns/handler.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { sharedConfig } from "solid-js";
44
import { renderToString } from "solid-js/web";
55
import { provideRequestEvent } from "solid-js/web/storage";
66

7-
import { getFetchEvent, mergeResponseHeaders } from "./fetchEvent.ts";
8-
import { createPageEvent } from "./handler.ts";
7+
import { getFetchEvent, mergeResponseHeaders } from "../server/fetchEvent.ts";
8+
import { createPageEvent } from "../server/handler.ts";
99
import {
1010
deserializeFromJSONString,
1111
serializeToJSONStream,
@@ -16,12 +16,12 @@ import {
1616
BodyFormat,
1717
extractBody,
1818
getHeadersAndBody,
19-
} from "./server-functions-shared.ts";
19+
} from "./shared.ts";
2020
import "solid-start:server-fn-manifest";
2121

22-
import { getServerFunction } from "./server-fns.ts";
23-
import type { FetchEvent, PageEvent } from "./types.ts";
24-
import { getExpectedRedirectStatus } from "./util.ts";
22+
import { getServerFunction } from "./registration.ts";
23+
import type { FetchEvent, PageEvent } from "../server/types.ts";
24+
import { getExpectedRedirectStatus } from "../server/util.ts";
2525

2626
export async function handleServerFunction(h3Event: H3Event) {
2727
const event = getFetchEvent(h3Event);
File renamed without changes.

packages/start/src/server/server-fns-runtime.ts renamed to packages/start/src/fns/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getRequestEvent } from "solid-js/web";
22
import { provideRequestEvent } from "solid-js/web/storage";
3-
import { registerServerFunction } from "./server-fns.ts";
3+
import { registerServerFunction } from "./registration.ts";
44

55
interface Registration<T extends any[], R> {
66
id: string;

0 commit comments

Comments
 (0)