@solidjs/start 2.0.0-beta.1 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/client/StartClient.d.ts +7 -0
  3. package/{src/client/StartClient.tsx → dist/client/StartClient.jsx} +7 -15
  4. package/dist/client/index.jsx +2 -0
  5. package/dist/client/mount.d.ts +1 -0
  6. package/dist/client/mount.js +1 -0
  7. package/dist/client/spa/index.d.ts +4 -0
  8. package/dist/client/spa/index.jsx +5 -0
  9. package/dist/config/constants.d.ts +16 -0
  10. package/dist/config/constants.js +16 -0
  11. package/dist/config/dev-server.d.ts +2 -0
  12. package/dist/config/dev-server.js +128 -0
  13. package/dist/config/env.d.ts +19 -0
  14. package/dist/config/env.js +81 -0
  15. package/dist/config/fs-router.d.ts +37 -0
  16. package/dist/config/fs-router.js +141 -0
  17. package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
  18. package/dist/config/fs-routes/fs-watcher.js +53 -0
  19. package/dist/config/fs-routes/index.d.ts +7 -0
  20. package/dist/config/fs-routes/index.js +107 -0
  21. package/dist/config/fs-routes/router.d.ts +42 -0
  22. package/dist/config/fs-routes/router.js +148 -0
  23. package/dist/config/fs-routes/tree-shake.d.ts +2 -0
  24. package/dist/config/fs-routes/tree-shake.js +305 -0
  25. package/dist/config/index.d.ts +25 -0
  26. package/dist/config/index.js +217 -0
  27. package/dist/config/lazy.d.ts +3 -0
  28. package/dist/config/lazy.js +114 -0
  29. package/dist/config/manifest.d.ts +3 -0
  30. package/dist/config/manifest.js +109 -0
  31. package/dist/config/utils.d.ts +4 -0
  32. package/dist/config/utils.js +6 -0
  33. package/dist/config/vite-utils.d.ts +21 -0
  34. package/dist/config/vite-utils.js +85 -0
  35. package/dist/directives/bubble-function-declaration.d.ts +3 -0
  36. package/dist/directives/bubble-function-declaration.js +23 -0
  37. package/dist/directives/compile.d.ts +9 -0
  38. package/dist/directives/compile.js +40 -0
  39. package/dist/directives/generate-unique-name.d.ts +3 -0
  40. package/dist/directives/generate-unique-name.js +16 -0
  41. package/dist/directives/get-descriptive-name.d.ts +2 -0
  42. package/dist/directives/get-descriptive-name.js +37 -0
  43. package/dist/directives/get-import-identifier.d.ts +4 -0
  44. package/dist/directives/get-import-identifier.js +19 -0
  45. package/dist/directives/get-root-statement-path.d.ts +2 -0
  46. package/dist/directives/get-root-statement-path.js +12 -0
  47. package/dist/directives/index.d.ts +14 -0
  48. package/dist/directives/index.js +170 -0
  49. package/dist/directives/is-statement-top-level.d.ts +3 -0
  50. package/dist/directives/is-statement-top-level.js +9 -0
  51. package/dist/directives/paths.d.ts +9 -0
  52. package/dist/directives/paths.js +36 -0
  53. package/dist/directives/plugin.d.ts +21 -0
  54. package/dist/directives/plugin.js +302 -0
  55. package/dist/directives/remove-unused-variables.d.ts +3 -0
  56. package/dist/directives/remove-unused-variables.js +66 -0
  57. package/{src/directives/types.ts → dist/directives/types.d.ts} +5 -7
  58. package/dist/directives/types.js +1 -0
  59. package/dist/directives/xxhash32.d.ts +6 -0
  60. package/dist/directives/xxhash32.js +193 -0
  61. package/dist/fns/client.d.ts +3 -0
  62. package/dist/fns/client.js +106 -0
  63. package/dist/fns/handler.d.ts +5 -0
  64. package/dist/fns/handler.js +269 -0
  65. package/dist/fns/registration.d.ts +2 -0
  66. package/dist/fns/registration.js +12 -0
  67. package/dist/fns/serialization.d.ts +6 -0
  68. package/dist/fns/serialization.js +208 -0
  69. package/dist/fns/server.d.ts +7 -0
  70. package/dist/fns/server.js +38 -0
  71. package/dist/fns/shared.d.ts +17 -0
  72. package/dist/fns/shared.js +105 -0
  73. package/dist/http/index.d.ts +81 -0
  74. package/dist/http/index.js +129 -0
  75. package/{src/index.tsx → dist/index.d.ts} +0 -2
  76. package/dist/index.jsx +6 -0
  77. package/dist/middleware/index.d.ts +38 -0
  78. package/dist/middleware/index.js +59 -0
  79. package/dist/router.d.ts +6 -0
  80. package/dist/router.jsx +29 -0
  81. package/dist/server/StartServer.d.ts +9 -0
  82. package/dist/server/StartServer.jsx +34 -0
  83. package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
  84. package/{src/server/assets/PatchVirtualDevStyles.tsx → dist/server/assets/PatchVirtualDevStyles.jsx} +7 -10
  85. package/dist/server/assets/index.d.ts +2 -0
  86. package/dist/server/assets/index.js +52 -0
  87. package/dist/server/assets/render.d.ts +19 -0
  88. package/dist/server/assets/render.jsx +14 -0
  89. package/dist/server/collect-styles.d.ts +3 -0
  90. package/dist/server/collect-styles.js +57 -0
  91. package/dist/server/fetchEvent.d.ts +7 -0
  92. package/dist/server/fetchEvent.js +26 -0
  93. package/dist/server/handler.d.ts +64 -0
  94. package/dist/server/handler.js +222 -0
  95. package/dist/server/index.d.ts +9 -0
  96. package/{src/server/index.tsx → dist/server/index.jsx} +4 -19
  97. package/dist/server/manifest/client-manifest.d.ts +9 -0
  98. package/dist/server/manifest/client-manifest.js +6 -0
  99. package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
  100. package/dist/server/manifest/dev-client-manifest.js +24 -0
  101. package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
  102. package/dist/server/manifest/dev-ssr-manifest.js +23 -0
  103. package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
  104. package/dist/server/manifest/prod-client-manifest.js +26 -0
  105. package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
  106. package/dist/server/manifest/prod-ssr-manifest.js +85 -0
  107. package/dist/server/manifest/ssr-manifest.d.ts +4 -0
  108. package/dist/server/manifest/ssr-manifest.js +6 -0
  109. package/dist/server/routes.d.ts +23 -0
  110. package/dist/server/routes.js +74 -0
  111. package/dist/server/spa/StartServer.d.ts +9 -0
  112. package/dist/server/spa/StartServer.jsx +25 -0
  113. package/dist/server/spa/handler.d.ts +36 -0
  114. package/dist/server/spa/handler.js +20 -0
  115. package/{src/server/spa/index.tsx → dist/server/spa/index.d.ts} +0 -1
  116. package/dist/server/spa/index.jsx +5 -0
  117. package/dist/server/types.d.ts +75 -0
  118. package/dist/server/types.js +1 -0
  119. package/dist/server/util.d.ts +2 -0
  120. package/dist/server/util.js +8 -0
  121. package/dist/shared/ErrorBoundary.d.ts +3 -0
  122. package/dist/shared/ErrorBoundary.jsx +36 -0
  123. package/dist/shared/GET.d.ts +5 -0
  124. package/dist/shared/GET.js +8 -0
  125. package/dist/shared/HttpHeader.d.ts +10 -0
  126. package/dist/shared/HttpHeader.jsx +38 -0
  127. package/dist/shared/HttpStatusCode.d.ts +9 -0
  128. package/dist/shared/HttpStatusCode.js +18 -0
  129. package/dist/shared/clientOnly.d.ts +12 -0
  130. package/dist/shared/clientOnly.js +27 -0
  131. package/dist/shared/dev-overlay/CodeView.d.ts +7 -0
  132. package/dist/shared/dev-overlay/CodeView.jsx +62 -0
  133. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +9 -0
  134. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +226 -0
  135. package/dist/shared/dev-overlay/createStackFrame.d.ts +9 -0
  136. package/dist/shared/dev-overlay/createStackFrame.js +56 -0
  137. package/dist/shared/dev-overlay/download.d.ts +1 -0
  138. package/dist/shared/dev-overlay/download.js +6 -0
  139. package/dist/shared/dev-overlay/get-source-map.d.ts +2 -0
  140. package/dist/shared/dev-overlay/get-source-map.js +25 -0
  141. package/dist/shared/dev-overlay/icons.d.ts +28 -0
  142. package/dist/shared/dev-overlay/icons.jsx +150 -0
  143. package/dist/shared/dev-overlay/index.d.ts +5 -0
  144. package/dist/shared/dev-overlay/index.jsx +39 -0
  145. package/dist/shared/lazy.d.ts +3 -0
  146. package/dist/shared/lazy.js +42 -0
  147. package/dist/shared/serverFunction.d.ts +6 -0
  148. package/dist/shared/serverFunction.js +8 -0
  149. package/dist/utils/debounce.d.ts +4 -0
  150. package/dist/utils/debounce.js +10 -0
  151. package/package.json +7 -2
  152. package/scripts/build.js +0 -15
  153. package/scripts/validate-imports.js +0 -316
  154. package/src/client/mount.ts +0 -1
  155. package/src/client/spa/index.tsx +0 -9
  156. package/src/config/constants.ts +0 -19
  157. package/src/config/dev-server.ts +0 -161
  158. package/src/config/env.ts +0 -105
  159. package/src/config/fs-router.ts +0 -162
  160. package/src/config/fs-routes/fs-watcher.ts +0 -66
  161. package/src/config/fs-routes/index.ts +0 -136
  162. package/src/config/fs-routes/router.ts +0 -184
  163. package/src/config/fs-routes/tree-shake.ts +0 -324
  164. package/src/config/index.ts +0 -239
  165. package/src/config/lazy.ts +0 -132
  166. package/src/config/manifest.ts +0 -120
  167. package/src/config/utils.ts +0 -5
  168. package/src/config/vite-utils.ts +0 -113
  169. package/src/directives/bubble-function-declaration.ts +0 -33
  170. package/src/directives/compile.ts +0 -54
  171. package/src/directives/generate-unique-name.ts +0 -22
  172. package/src/directives/get-descriptive-name.ts +0 -39
  173. package/src/directives/get-import-identifier.ts +0 -34
  174. package/src/directives/get-root-statement-path.ts +0 -14
  175. package/src/directives/index.ts +0 -233
  176. package/src/directives/is-statement-top-level.ts +0 -13
  177. package/src/directives/paths.ts +0 -63
  178. package/src/directives/plugin.ts +0 -389
  179. package/src/directives/remove-unused-variables.ts +0 -70
  180. package/src/directives/xxhash32.ts +0 -214
  181. package/src/env.d.ts +0 -17
  182. package/src/fns/client.ts +0 -141
  183. package/src/fns/handler.spec.ts +0 -85
  184. package/src/fns/handler.ts +0 -287
  185. package/src/fns/registration.ts +0 -19
  186. package/src/fns/serialization.ts +0 -250
  187. package/src/fns/server.ts +0 -46
  188. package/src/fns/shared.ts +0 -116
  189. package/src/http/index.ts +0 -216
  190. package/src/internal.d.ts +0 -14
  191. package/src/middleware/index.ts +0 -92
  192. package/src/router.tsx +0 -37
  193. package/src/server/StartServer.tsx +0 -58
  194. package/src/server/assets/index.ts +0 -70
  195. package/src/server/assets/render.tsx +0 -46
  196. package/src/server/collect-styles.ts +0 -70
  197. package/src/server/fetchEvent.spec.ts +0 -85
  198. package/src/server/fetchEvent.ts +0 -36
  199. package/src/server/handler.ts +0 -261
  200. package/src/server/manifest/client-manifest.ts +0 -8
  201. package/src/server/manifest/dev-client-manifest.ts +0 -21
  202. package/src/server/manifest/dev-ssr-manifest.ts +0 -23
  203. package/src/server/manifest/prod-client-manifest.ts +0 -21
  204. package/src/server/manifest/prod-ssr-manifest.ts +0 -109
  205. package/src/server/manifest/ssr-manifest.ts +0 -10
  206. package/src/server/routes.ts +0 -126
  207. package/src/server/spa/StartServer.tsx +0 -42
  208. package/src/server/spa/handler.ts +0 -29
  209. package/src/server/types.ts +0 -82
  210. package/src/server/util.ts +0 -12
  211. package/src/shared/ErrorBoundary.tsx +0 -52
  212. package/src/shared/GET.ts +0 -8
  213. package/src/shared/HttpHeader.tsx +0 -42
  214. package/src/shared/HttpStatusCode.ts +0 -27
  215. package/src/shared/clientOnly.ts +0 -44
  216. package/src/shared/dev-overlay/CodeView.tsx +0 -90
  217. package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
  218. package/src/shared/dev-overlay/createStackFrame.ts +0 -74
  219. package/src/shared/dev-overlay/download.ts +0 -6
  220. package/src/shared/dev-overlay/env.d.ts +0 -4
  221. package/src/shared/dev-overlay/get-source-map.ts +0 -33
  222. package/src/shared/dev-overlay/icons.tsx +0 -456
  223. package/src/shared/dev-overlay/index.tsx +0 -63
  224. package/src/shared/lazy.ts +0 -52
  225. package/src/shared/serverFunction.ts +0 -10
  226. package/src/utils/debounce.ts +0 -10
  227. package/src/virtual.d.ts +0 -27
  228. package/tsconfig.json +0 -24
  229. package/vitest.config.ts +0 -9
  230. /package/{src/client/index.tsx → dist/client/index.d.ts} +0 -0
  231. /package/{src → dist}/shared/dev-overlay/styles.css +0 -0
@@ -1,261 +0,0 @@
1
- import middleware from "solid-start:middleware";
2
- import { defineHandler, getCookie, H3, type H3Event, redirect, setCookie } from "h3/generic";
3
- import { join } from "pathe";
4
- import type { JSX } from "solid-js";
5
- import { sharedConfig } from "solid-js";
6
- import { getRequestEvent, renderToStream, renderToString } from "solid-js/web";
7
-
8
- import { createRoutes } from "../router.tsx";
9
- import { decorateHandler, decorateMiddleware } from "./fetchEvent.ts";
10
- import { getSsrManifest } from "./manifest/ssr-manifest.ts";
11
- import { matchAPIRoute } from "./routes.ts";
12
- import { handleServerFunction } from "../fns/handler.ts";
13
- import type { APIEvent, FetchEvent, HandlerOptions, PageEvent } from "./types.ts";
14
- import { getExpectedRedirectStatus } from "./util.ts";
15
-
16
- const SERVER_FN_BASE = "/_server";
17
-
18
- export function createBaseHandler(
19
- createPageEvent: (e: FetchEvent) => Promise<PageEvent>,
20
- fn: (context: PageEvent) => JSX.Element,
21
- options: HandlerOptions | ((context: PageEvent) => HandlerOptions | Promise<HandlerOptions>) = {},
22
- ) {
23
- const handler = defineHandler({
24
- middleware: middleware.length ? middleware.map(decorateMiddleware) : undefined,
25
- handler: decorateHandler(async (e: H3Event) => {
26
- const event = getRequestEvent()!;
27
- const url = new URL(event.request.url);
28
- const pathname = stripBaseUrl(url.pathname);
29
-
30
- if (pathname.startsWith(SERVER_FN_BASE)) {
31
- const serverFnResponse = await handleServerFunction(e);
32
-
33
- if (serverFnResponse instanceof Response)
34
- return produceResponseWithEventHeaders(serverFnResponse);
35
-
36
- return new Response(serverFnResponse as any, {
37
- headers: e.res.headers,
38
- });
39
- }
40
-
41
- const match = matchAPIRoute(pathname, event.request.method);
42
- if (match) {
43
- const mod = await match.handler.import();
44
- const fn =
45
- event.request.method === "HEAD" ? mod["HEAD"] || mod["GET"] : mod[event.request.method];
46
- if (typeof fn === "function") {
47
- (event as APIEvent).params = match.params || {};
48
- // @ts-expect-error
49
- sharedConfig.context = { event };
50
- const res = await fn(event);
51
- if (res !== undefined) {
52
- if (res instanceof Response) return produceResponseWithEventHeaders(res);
53
-
54
- return res;
55
- }
56
- if (event.request.method !== "GET") {
57
- throw new Error(
58
- `API handler for ${event.request.method} "${event.request.url}" did not return a response.`,
59
- );
60
- }
61
- if (!match.isPage) return;
62
- }
63
- }
64
-
65
- const context = await createPageEvent(event);
66
-
67
- const resolvedOptions =
68
- typeof options === "function" ? await options(context) : { ...options };
69
- const mode = resolvedOptions.mode || "stream";
70
- if (resolvedOptions.nonce) context.nonce = resolvedOptions.nonce;
71
-
72
- if (mode === "sync" || !import.meta.env.START_SSR) {
73
- const html = renderToString(() => {
74
- (sharedConfig.context as any).event = context;
75
- return fn(context);
76
- }, resolvedOptions);
77
- context.complete = true;
78
-
79
- if (context.response && context.response.headers.get("Location")) {
80
- const status = getExpectedRedirectStatus(context.response);
81
- return redirect(context.response.headers.get("Location")!, status);
82
- }
83
-
84
- event.response.headers.set("content-type", "text/html");
85
-
86
- return html;
87
- }
88
-
89
- if (resolvedOptions.onCompleteAll) {
90
- const og = resolvedOptions.onCompleteAll;
91
- resolvedOptions.onCompleteAll = options => {
92
- handleStreamCompleteRedirect(context)(options);
93
- og(options);
94
- };
95
- } else resolvedOptions.onCompleteAll = handleStreamCompleteRedirect(context);
96
- if (resolvedOptions.onCompleteShell) {
97
- const og = resolvedOptions.onCompleteShell;
98
- resolvedOptions.onCompleteShell = options => {
99
- handleShellCompleteRedirect(context, e)();
100
- og(options);
101
- };
102
- } else resolvedOptions.onCompleteShell = handleShellCompleteRedirect(context, e);
103
-
104
- const _stream = renderToStream(() => {
105
- (sharedConfig.context as any).event = context;
106
- return fn(context);
107
- }, resolvedOptions);
108
- const stream = _stream as typeof _stream & PromiseLike<string>; // stream has a hidden 'then' method
109
-
110
- if (context.response && context.response.headers.get("Location")) {
111
- const status = getExpectedRedirectStatus(context.response);
112
- return redirect(context.response.headers.get("Location")!, status);
113
- }
114
-
115
- if (mode === "async") return await stream;
116
-
117
- delete (stream as any).then;
118
-
119
- // using TransformStream in dev can cause solid-start-dev-server to crash
120
- // when stream is cancelled
121
- if (globalThis.USING_SOLID_START_DEV_SERVER) return stream;
122
-
123
- // returning stream directly breaks cloudflare workers
124
- const { writable, readable } = new TransformStream();
125
- stream.pipeTo(writable);
126
- return readable;
127
- }),
128
- });
129
-
130
- const app = new H3();
131
-
132
- app.use(handler);
133
-
134
- return app;
135
- }
136
-
137
- export function createHandler(
138
- fn: (context: PageEvent) => JSX.Element,
139
- options: HandlerOptions | ((context: PageEvent) => HandlerOptions | Promise<HandlerOptions>) = {},
140
- ) {
141
- return createBaseHandler(createPageEvent, fn, options);
142
- }
143
-
144
- export async function createPageEvent(ctx: FetchEvent) {
145
- ctx.response.headers.set("Content-Type", "text/html");
146
- // const prevPath = ctx.request.headers.get("x-solid-referrer");
147
- // const mutation = ctx.request.headers.get("x-solid-mutation") === "true";
148
- const manifest = getSsrManifest(import.meta.env.SSR && import.meta.env.DEV ? "ssr" : "client");
149
-
150
- // Handle Vite build.cssCodeSplit
151
- // When build.cssCodeSplit is false, a single CSS file is generated with the key style.css
152
- const mergedCSS = import.meta.env.PROD ? await manifest.getAssets("style.css") : [];
153
-
154
- const assets = [
155
- ...mergedCSS,
156
- ...(await manifest.getAssets(import.meta.env.START_CLIENT_ENTRY)),
157
- ...(await manifest.getAssets(import.meta.env.START_APP_ENTRY)),
158
- // ...(import.meta.env.START_ISLANDS
159
- // ? (await serverManifest.inputs[serverManifest.handler]!.assets()).filter(
160
- // s => (s as any).attrs.rel !== "modulepreload"
161
- // )
162
- // : [])
163
- ];
164
- const pageEvent: PageEvent = Object.assign(ctx, {
165
- assets,
166
- router: {
167
- submission: initFromFlash(ctx) as any,
168
- },
169
- routes: createRoutes(),
170
- // prevUrl: prevPath || "",
171
- // mutation: mutation,
172
- // $type: FETCH_EVENT,
173
- complete: false,
174
- $islands: new Set<string>(),
175
- });
176
-
177
- return pageEvent;
178
- }
179
-
180
- function initFromFlash(ctx: FetchEvent) {
181
- const flash = getCookie(ctx.nativeEvent, "flash");
182
- if (!flash) return;
183
- try {
184
- const param = JSON.parse(flash);
185
- if (!param || !param.result) return;
186
- const input = [...param.input.slice(0, -1), new Map(param.input[param.input.length - 1])];
187
- const result = param.error ? new Error(param.result) : param.result;
188
- return {
189
- input,
190
- url: param.url,
191
- pending: false,
192
- result: param.thrown ? undefined : result,
193
- error: param.thrown ? result : undefined,
194
- };
195
- } catch (e) {
196
- console.error(e);
197
- } finally {
198
- setCookie(ctx.nativeEvent, "flash", "", { maxAge: 0 });
199
- }
200
- }
201
-
202
- function handleShellCompleteRedirect(context: PageEvent, e: H3Event) {
203
- return () => {
204
- if (context.response && context.response.headers.get("Location")) {
205
- const status = getExpectedRedirectStatus(context.response);
206
- e.res.status = status;
207
- e.res.headers.set("Location", context.response.headers.get("Location")!);
208
- }
209
- };
210
- }
211
-
212
- function handleStreamCompleteRedirect(context: PageEvent) {
213
- return ({ write }: { write: (html: string) => void }) => {
214
- context.complete = true;
215
- const to = context.response && context.response.headers.get("Location");
216
- to && write(`<script>window.location=${JSON.stringify(to).replace(/</g, "\\u003c")}</script>`);
217
- };
218
- }
219
-
220
- function produceResponseWithEventHeaders(res: Response) {
221
- const event = getRequestEvent()!;
222
-
223
- let ret = res;
224
-
225
- // Response.redirect returns an immutable value, so we clone on any redirect just in case
226
- if (300 <= res.status && res.status < 400) {
227
- const cookies = res.headers.getSetCookie?.() ?? [];
228
- const headers = new Headers();
229
- res.headers.forEach((value, key) => {
230
- if (key.toLowerCase() !== "set-cookie") {
231
- headers.set(key, value);
232
- }
233
- });
234
- for (const cookie of cookies) {
235
- headers.append("Set-Cookie", cookie);
236
- }
237
- ret = new Response(res.body, {
238
- status: res.status,
239
- statusText: res.statusText,
240
- headers,
241
- });
242
- }
243
-
244
- const eventCookies = event.response.headers.getSetCookie?.() ?? [];
245
- for (const cookie of eventCookies) {
246
- ret.headers.append("Set-Cookie", cookie);
247
- }
248
-
249
- for (const [name, value] of event.response.headers) {
250
- if (name.toLowerCase() !== "set-cookie") {
251
- ret.headers.set(name, value);
252
- }
253
- }
254
-
255
- return ret;
256
- }
257
-
258
- function stripBaseUrl(path: string) {
259
- if (import.meta.env.BASE_URL === "/" || import.meta.env.BASE_URL === "") return path;
260
- return path.slice(import.meta.env.BASE_URL.length);
261
- }
@@ -1,8 +0,0 @@
1
- import { getClientDevManifest } from "./dev-client-manifest.ts";
2
- import { getClientProdManifest } from "./prod-client-manifest.ts";
3
-
4
- export function getClientManifest() {
5
- return import.meta.env.DEV ? getClientDevManifest() : getClientProdManifest();
6
- }
7
-
8
- export { getClientManifest as getManifest };
@@ -1,21 +0,0 @@
1
- import { join } from "pathe";
2
-
3
- export function getClientDevManifest() {
4
- return {
5
- import(id) {
6
- return import(/* @vite-ignore */ join("/", id));
7
- },
8
- async getAssets(id) {
9
- const assetsPath = `/@manifest/client/${Date.now()}/assets?id=${id}`;
10
-
11
- const assets = (await import(/* @vite-ignore */ assetsPath)).default;
12
-
13
- return await Promise.all(
14
- assets.map(async (v: any) => ({
15
- ...v,
16
- children: await v.children(),
17
- })),
18
- );
19
- },
20
- } satisfies StartManifest & { import(id: string): Promise<any> };
21
- }
@@ -1,23 +0,0 @@
1
- import { join, normalize } from "pathe";
2
-
3
- export function getSsrDevManifest(environment: "client" | "ssr") {
4
- return {
5
- path: (id: string) => normalize(join(import.meta.env.BASE_URL, id)),
6
- async getAssets(id) {
7
- const assetsPath = `/@manifest/${environment}/${Date.now()}/assets?id=${id}`;
8
-
9
- const assets = (await import(/* @vite-ignore */ assetsPath)).default;
10
-
11
- return await Promise.all(
12
- assets.map(async (v: any) => ({
13
- ...v,
14
- children: await v.children(),
15
- })),
16
- );
17
- },
18
- } satisfies StartManifest & {
19
- path(id: string): string;
20
- };
21
- }
22
-
23
- export { getSsrDevManifest as getSsrManifest };
@@ -1,21 +0,0 @@
1
- export function getClientProdManifest() {
2
- return {
3
- import(id) {
4
- // @ts-ignore
5
- return import(/* @vite-ignore */ window.manifest[id].output);
6
- },
7
- async getAssets(id) {
8
- if (id.startsWith("./")) id = id.slice(2);
9
-
10
- // @ts-ignore
11
- return window.manifest[id]?.assets ?? [];
12
- },
13
- async json() {
14
- // @ts-ignore
15
- return window.manifest;
16
- },
17
- } satisfies StartManifest & {
18
- json(): Promise<Record<string, any>>;
19
- import(id: string): Promise<any>;
20
- };
21
- }
@@ -1,109 +0,0 @@
1
- import { clientViteManifest } from "solid-start:client-vite-manifest";
2
- import { join } from "pathe";
3
- import { Manifest } from "vite";
4
- import type { Asset } from "../assets/render.tsx";
5
-
6
- // Only reads from client manifest atm, might need server support for islands
7
- export function getSsrProdManifest() {
8
- const viteManifest = clientViteManifest;
9
- return {
10
- path(id: string) {
11
- if (id.startsWith("./")) id = id.slice(2);
12
-
13
- const viteManifestEntry = clientViteManifest[id /*import.meta.env.START_CLIENT_ENTRY*/];
14
- if (!viteManifestEntry) throw new Error(`No entry found in vite manifest for '${id}'`);
15
-
16
- return join("/", viteManifestEntry.file);
17
- },
18
- async getAssets(id) {
19
- if (id.startsWith("./")) id = id.slice(2);
20
-
21
- return createHtmlTagsForAssets(findAssetsInViteManifest(clientViteManifest, id));
22
- },
23
- async json() {
24
- const json: Record<string, any> = {};
25
-
26
- const entryKeys = Object.keys(viteManifest)
27
- .filter(id => viteManifest[id]?.isEntry || viteManifest[id]?.isDynamicEntry)
28
- .map(id => id);
29
-
30
- for (const entryKey of entryKeys) {
31
- json[entryKey] = {
32
- output: join("/", viteManifest[entryKey]!.file),
33
- assets: await this.getAssets(entryKey),
34
- };
35
- }
36
-
37
- return json;
38
- },
39
- } satisfies StartManifest & {
40
- json(): Promise<Record<string, any>>;
41
- path(id: string): string;
42
- };
43
- }
44
-
45
- function createHtmlTagsForAssets(assets: string[]) {
46
- return assets
47
- .filter(
48
- asset =>
49
- asset.endsWith(".css") ||
50
- asset.endsWith(".js") ||
51
- asset.endsWith(".ts") ||
52
- asset.endsWith(".mjs"),
53
- )
54
- .map<Asset>(asset => ({
55
- tag: "link",
56
- attrs: {
57
- href: "/" + asset,
58
- key: asset,
59
- ...(asset.endsWith(".css") ? { rel: "stylesheet" } : { rel: "modulepreload" }),
60
- },
61
- }));
62
- }
63
-
64
- const entryId = import.meta.env.START_CLIENT_ENTRY.slice(2);
65
- let entryImports: string[] | undefined = undefined;
66
-
67
- function findAssetsInViteManifest(
68
- manifest: Manifest,
69
- id: string,
70
- assetMap = new Map(),
71
- stack: string[] = [],
72
- ) {
73
- if (stack.includes(id)) {
74
- return [];
75
- }
76
-
77
- const cached = assetMap.get(id);
78
- if (cached) {
79
- return cached;
80
- }
81
- const chunk = manifest[id];
82
- if (!chunk) {
83
- return [];
84
- }
85
-
86
- if (!entryImports) {
87
- entryImports = [entryId, ...(manifest[entryId]?.imports ?? [])];
88
- }
89
-
90
- // Only include entry imports, if we are specifically crawling the entry
91
- // Chunks (e.g. routes) that import something from entry, should not render entry css redundantly
92
- const excludeEntryImports = id !== entryId;
93
-
94
- const assets = chunk.css?.filter(Boolean) || [];
95
- if (chunk.imports) {
96
- stack.push(id);
97
- for (let i = 0, l = chunk.imports.length; i < l; i++) {
98
- const importId = chunk.imports[i];
99
- if (!importId || (excludeEntryImports && entryImports.includes(importId))) continue;
100
- assets.push(...findAssetsInViteManifest(manifest, importId, assetMap, stack));
101
- }
102
- stack.pop();
103
- }
104
- assets.push(chunk.file);
105
- const all = Array.from(new Set(assets));
106
- assetMap.set(id, all);
107
-
108
- return all;
109
- }
@@ -1,10 +0,0 @@
1
- import { getSsrDevManifest } from "./dev-ssr-manifest.ts";
2
- import { getSsrProdManifest } from "./prod-ssr-manifest.ts";
3
-
4
- export function getSsrManifest(
5
- target: "client" | "ssr",
6
- ): ReturnType<typeof getSsrDevManifest> | ReturnType<typeof getSsrProdManifest> {
7
- return import.meta.env.DEV ? getSsrDevManifest(target) : getSsrProdManifest();
8
- }
9
-
10
- export { getSsrManifest as getManifest };
@@ -1,126 +0,0 @@
1
- // @ts-expect-error
2
- import fileRoutes from "solid-start:routes";
3
- import { createRouter } from "radix3";
4
-
5
- import type { FetchEvent } from "./types.ts";
6
-
7
- interface Route {
8
- path: string;
9
- id: string;
10
- children?: Route[];
11
- page?: boolean;
12
- $component?: any;
13
- $HEAD?: any;
14
- $GET?: any;
15
- $POST?: any;
16
- $PUT?: any;
17
- $PATCH?: any;
18
- $DELETE?: any;
19
- }
20
-
21
- export const pageRoutes = defineRoutes((fileRoutes as unknown as Route[]).filter(o => o.page));
22
-
23
- function defineRoutes(fileRoutes: Route[]) {
24
- function processRoute(routes: Route[], route: Route, id: string, full: string) {
25
- const parentRoute = Object.values(routes).find(o => {
26
- return id.startsWith(o.id + "/");
27
- });
28
-
29
- if (!parentRoute) {
30
- routes.push({
31
- ...route,
32
- id,
33
- path: id.replace(/\([^)/]+\)/g, "").replace(/\/+/g, "/"),
34
- });
35
- return routes;
36
- }
37
- processRoute(
38
- parentRoute.children || (parentRoute.children = []),
39
- route,
40
- id.slice(parentRoute.id.length),
41
- full,
42
- );
43
-
44
- return routes;
45
- }
46
-
47
- return fileRoutes
48
- .sort((a, b) => a.path.length - b.path.length)
49
- .reduce((prevRoutes: Route[], route) => {
50
- return processRoute(prevRoutes, route, route.path, route.path);
51
- }, []);
52
- }
53
-
54
- const router = createRouter({
55
- routes: (fileRoutes as unknown as Route[]).reduce(
56
- (memo, route) => {
57
- if (!containsHTTP(route)) return memo;
58
- const path = route.path
59
- .replace(/\([^)/]+\)/g, "")
60
- .replace(/\/+/g, "/")
61
- .replace(/\*([^/]*)/g, (_, m) => `**:${m}`)
62
- .split("/")
63
- .map(s => (s.startsWith(":") || s.startsWith("*") ? s : encodeURIComponent(s)))
64
- .join("/");
65
- if (/:[^/]*\?/g.test(path)) {
66
- throw new Error(`Optional parameters are not supported in API routes: ${path}`);
67
- }
68
- if (memo[path]) {
69
- throw new Error(
70
- `Duplicate API routes for "${path}" found at "${memo[path]!.route.path}" and "${
71
- route.path
72
- }"`,
73
- );
74
- }
75
- memo[path] = { route };
76
- return memo;
77
- },
78
- {} as Record<string, { route: Route }>,
79
- ),
80
- });
81
-
82
- function containsHTTP(route: Route) {
83
- return (
84
- route["$HEAD"] ||
85
- route["$GET"] ||
86
- route["$POST"] ||
87
- route["$PUT"] ||
88
- route["$PATCH"] ||
89
- route["$DELETE"]
90
- );
91
- }
92
-
93
- export function matchAPIRoute(
94
- path: string,
95
- method: string,
96
- ):
97
- | {
98
- params?: Record<string, any>;
99
- handler: {
100
- import: () => Promise<Record<string, (e: FetchEvent) => Promise<any>>>;
101
- };
102
- isPage: boolean;
103
- }
104
- | undefined {
105
- const match = router.lookup(path);
106
- if (match && match.route) {
107
- const route = match.route;
108
-
109
- // Find the appropriate handler for the HTTP method
110
- const handler = method === "HEAD" ? route.$HEAD || route.$GET : route[`$${method}`];
111
-
112
- if (handler === undefined) return;
113
-
114
- // Check if this is a page route
115
- const isPage = route.page === true && route.$component !== undefined;
116
-
117
- // Return comprehensive route information
118
- return {
119
- handler,
120
- params: match.params,
121
- isPage,
122
- };
123
- }
124
-
125
- return undefined;
126
- }
@@ -1,42 +0,0 @@
1
- // @refresh skip
2
- // @ts-ignore
3
- import type { Component } from "solid-js";
4
- import { NoHydration, getRequestEvent, ssr } from "solid-js/web";
5
- import { getSsrManifest } from "../manifest/ssr-manifest.ts";
6
-
7
- import { TopErrorBoundary } from "../../shared/ErrorBoundary.tsx";
8
- import { useAssets } from "../assets/index.ts";
9
- import PatchVirtualDevStyles from "../assets/PatchVirtualDevStyles.tsx";
10
- import type { DocumentComponentProps, PageEvent } from "../types.ts";
11
-
12
- const docType = ssr("<!DOCTYPE html>");
13
-
14
- /**
15
- *
16
- * Read more: https://docs.solidjs.com/solid-start/reference/server/start-server
17
- */
18
- export function StartServer(props: { document: Component<DocumentComponentProps> }) {
19
- const context = getRequestEvent() as PageEvent;
20
- // @ts-ignore
21
- const nonce = context.nonce;
22
- useAssets(context.assets, nonce);
23
-
24
- return (
25
- <NoHydration>
26
- {docType as unknown as any}
27
- <TopErrorBoundary>
28
- <props.document
29
- scripts={
30
- <>
31
- <PatchVirtualDevStyles nonce={nonce} />
32
- <script
33
- type="module"
34
- src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY)}
35
- />
36
- </>
37
- }
38
- />
39
- </TopErrorBoundary>
40
- </NoHydration>
41
- );
42
- }
@@ -1,29 +0,0 @@
1
- import type { JSX } from "solid-js";
2
-
3
- import { createBaseHandler } from "../handler.ts";
4
- import { getSsrManifest } from "../manifest/ssr-manifest.ts";
5
- import type { FetchEvent, HandlerOptions, PageEvent } from "../types.ts";
6
-
7
- /**
8
- *
9
- * Read more: https://docs.solidjs.com/solid-start/reference/server/create-handler
10
- */
11
- export function createHandler(
12
- fn: (context: PageEvent) => JSX.Element,
13
- options?: HandlerOptions | ((context: PageEvent) => HandlerOptions),
14
- ) {
15
- return createBaseHandler(createPageEvent, fn, options);
16
- }
17
-
18
- async function createPageEvent(ctx: FetchEvent) {
19
- const manifest = getSsrManifest("ssr");
20
- const pageEvent: PageEvent = Object.assign(ctx, {
21
- manifest: "json" in manifest ? await manifest.json() : {},
22
- assets: await manifest.getAssets(import.meta.env.START_CLIENT_ENTRY),
23
- routes: [],
24
- complete: false,
25
- $islands: new Set<string>(),
26
- });
27
-
28
- return pageEvent;
29
- }