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

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 +13 -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 +224 -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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @solidjs/start
2
2
 
3
+ ## 2.0.0-beta.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 12dc2d3: Bundle `h3` and `cookie-es` into server builds to avoid resolving incompatible hoisted versions
8
+
9
+ ## 2.0.0-beta.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 3e961e0: Require Vite 8
14
+ - 11907a2: Fix published package missing `dist/`: pnpm 11 respects `.gitignore` when packing a package without a `files` field, so `2.0.0-beta.1` was published without its build output. Add an explicit `files` field.
15
+
3
16
  ## 2.0.0-beta.1
4
17
 
5
18
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ import type { JSX } from "solid-js";
2
+ /**
3
+ *
4
+ * Read more: https://docs.solidjs.com/solid-start/reference/client/start-client
5
+ */
6
+ export declare function StartClient(): JSX.Element;
7
+ export declare function StartClientTanstack(): JSX.Element;
@@ -1,34 +1,26 @@
1
1
  // @refresh skip
2
2
  import App from "solid-start:app";
3
- import type { JSX } from "solid-js";
4
- import { ErrorBoundary } from "../shared/ErrorBoundary.tsx";
5
-
6
- function Dummy(props: { children: JSX.Element }) {
7
- return props.children;
3
+ import { ErrorBoundary } from "../shared/ErrorBoundary.jsx";
4
+ function Dummy(props) {
5
+ return props.children;
8
6
  }
9
-
10
7
  /**
11
8
  *
12
9
  * Read more: https://docs.solidjs.com/solid-start/reference/client/start-client
13
10
  */
14
11
  export function StartClient() {
15
- return (
16
- <Dummy>
12
+ return (<Dummy>
17
13
  <Dummy>
18
14
  <ErrorBoundary>
19
15
  <App />
20
16
  </ErrorBoundary>
21
17
  </Dummy>
22
- </Dummy>
23
- );
18
+ </Dummy>);
24
19
  }
25
-
26
20
  export function StartClientTanstack() {
27
- return (
28
- <Dummy>
21
+ return (<Dummy>
29
22
  <ErrorBoundary>
30
23
  <App />
31
24
  </ErrorBoundary>
32
- </Dummy>
33
- );
25
+ </Dummy>);
34
26
  }
@@ -0,0 +1,2 @@
1
+ export { mount } from "./mount.js";
2
+ export { StartClient, StartClientTanstack } from "./StartClient.jsx";
@@ -0,0 +1 @@
1
+ export { hydrate as mount } from "solid-js/web";
@@ -0,0 +1 @@
1
+ export { hydrate as mount } from "solid-js/web";
@@ -0,0 +1,4 @@
1
+ import type { JSX } from "solid-js";
2
+ import { type MountableElement } from "solid-js/web";
3
+ export declare function mount(fn: () => JSX.Element, el: MountableElement): void;
4
+ export { StartClient } from "../StartClient.tsx";
@@ -0,0 +1,5 @@
1
+ import { render } from "solid-js/web";
2
+ export function mount(fn, el) {
3
+ render(fn, el);
4
+ }
5
+ export { StartClient } from "../StartClient.jsx";
@@ -0,0 +1,16 @@
1
+ export declare const DEFAULT_EXTENSIONS: string[];
2
+ export declare const CLIENT_BASE_PATH = "_build";
3
+ export declare const VIRTUAL_MODULES: {
4
+ readonly clientViteManifest: "solid-start:client-vite-manifest";
5
+ readonly getClientManifest: "solid-start:get-client-manifest";
6
+ readonly getManifest: "solid-start:get-manifest";
7
+ readonly middleware: "solid-start:middleware";
8
+ readonly serverFnManifest: "solid-start:server-fn-manifest";
9
+ readonly clientEntry: "solid-start:client-entry";
10
+ readonly serverEntry: "solid-start:server-entry";
11
+ readonly app: "solid-start:app";
12
+ };
13
+ export declare const VITE_ENVIRONMENTS: {
14
+ client: "client";
15
+ server: "ssr";
16
+ };
@@ -0,0 +1,16 @@
1
+ export const DEFAULT_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
2
+ export const CLIENT_BASE_PATH = "_build";
3
+ export const VIRTUAL_MODULES = {
4
+ clientViteManifest: "solid-start:client-vite-manifest",
5
+ getClientManifest: "solid-start:get-client-manifest",
6
+ getManifest: "solid-start:get-manifest",
7
+ middleware: "solid-start:middleware",
8
+ serverFnManifest: "solid-start:server-fn-manifest",
9
+ clientEntry: "solid-start:client-entry",
10
+ serverEntry: "solid-start:server-entry",
11
+ app: "solid-start:app",
12
+ };
13
+ export const VITE_ENVIRONMENTS = {
14
+ client: "client",
15
+ server: "ssr",
16
+ };
@@ -0,0 +1,2 @@
1
+ import { type PluginOption } from "vite";
2
+ export declare function devServer(): Array<PluginOption>;
@@ -0,0 +1,128 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { join } from "node:path";
10
+ import { pathToFileURL } from "node:url";
11
+ import { NodeRequest, sendNodeResponse } from "srvx/node";
12
+ import { isRunnableDevEnvironment, } from "vite";
13
+ import { VITE_ENVIRONMENTS } from "./constants.js";
14
+ export function devServer() {
15
+ return [
16
+ {
17
+ name: "solid-start-dev-server",
18
+ configurePreviewServer(server) {
19
+ return () => {
20
+ server.middlewares.use(async (req, res) => {
21
+ res.setHeader("content-encoding", "identity");
22
+ const webReq = new NodeRequest({ req, res });
23
+ const def = await import(__rewriteRelativeImportExtension(pathToFileURL(join(process.cwd(), "dist/server/entry-server.js")).href, true));
24
+ sendNodeResponse(res, await def.default.fetch(webReq));
25
+ });
26
+ };
27
+ },
28
+ configureServer(viteDevServer) {
29
+ globalThis.VITE_DEV_SERVER = viteDevServer;
30
+ return async () => {
31
+ if (viteDevServer.config.server.middlewareMode)
32
+ return;
33
+ const serverEnv = viteDevServer.environments[VITE_ENVIRONMENTS.server];
34
+ if (!serverEnv)
35
+ throw new Error("Server environment not found");
36
+ if (
37
+ // do not check via `isFetchableDevEnvironment` since nitro does implement the `FetchableDevEnvironment` interface but not via inheritance (which this helper checks)
38
+ "dispatchFetch" in serverEnv)
39
+ return;
40
+ // another plugin is controlling the dev server
41
+ if (!isRunnableDevEnvironment(serverEnv)) {
42
+ return;
43
+ }
44
+ globalThis.USING_SOLID_START_DEV_SERVER = true;
45
+ removeHtmlMiddlewares(viteDevServer);
46
+ viteDevServer.middlewares.use(async (req, res) => {
47
+ if (req.originalUrl) {
48
+ req.url = req.originalUrl;
49
+ }
50
+ const webReq = new NodeRequest({ req, res });
51
+ try {
52
+ const serverEntry = await serverEnv.runner.import("./src/entry-server.tsx");
53
+ const webRes = await serverEntry.default.fetch(webReq);
54
+ return sendNodeResponse(res, webRes);
55
+ }
56
+ catch (e) {
57
+ console.error(e);
58
+ viteDevServer.ssrFixStacktrace(e);
59
+ if (webReq.headers.get("content-type")?.includes("application/json")) {
60
+ return sendNodeResponse(res, Response.json({
61
+ status: 500,
62
+ error: "Internal Server Error",
63
+ message: "An unexpected error occurred. Please try again later.",
64
+ timestamp: new Date().toISOString(),
65
+ }, {
66
+ status: 500,
67
+ headers: {
68
+ "Content-Type": "application/json",
69
+ },
70
+ }));
71
+ }
72
+ return sendNodeResponse(res, new Response(`
73
+ <!DOCTYPE html>
74
+ <html lang="en">
75
+ <head>
76
+ <meta charset="UTF-8" />
77
+ <title>Error</title>
78
+ <script type="module">
79
+ import { ErrorOverlay } from '/@vite/client'
80
+ document.body.appendChild(new ErrorOverlay(${JSON.stringify(prepareError(req, e)).replace(/</g, "\\u003c")}))
81
+ </script>
82
+ </head>
83
+ <body>
84
+ </body>
85
+ </html>
86
+ `, {
87
+ status: 500,
88
+ headers: { "Content-Type": "text/html" },
89
+ }));
90
+ }
91
+ });
92
+ };
93
+ },
94
+ },
95
+ ];
96
+ }
97
+ /**
98
+ * Removes Vite internal middleware
99
+ *
100
+ * @param server
101
+ */
102
+ function removeHtmlMiddlewares(server) {
103
+ const html_middlewares = [
104
+ "viteIndexHtmlMiddleware",
105
+ "vite404Middleware",
106
+ "viteSpaFallbackMiddleware",
107
+ ];
108
+ for (let i = server.middlewares.stack.length - 1; i > 0; i--) {
109
+ if (html_middlewares.includes(
110
+ // @ts-expect-error
111
+ server.middlewares.stack[i].handle.name)) {
112
+ server.middlewares.stack.splice(i, 1);
113
+ }
114
+ }
115
+ }
116
+ /**
117
+ * Formats error for SSR message in error overlay
118
+ * @param req
119
+ * @param error
120
+ * @returns
121
+ */
122
+ function prepareError(req, error) {
123
+ const e = error;
124
+ return {
125
+ message: `An error occured while server rendering ${req.url}:\n\n\t${typeof e === "string" ? e : e.message} `,
126
+ stack: typeof e === "string" ? "" : e.stack,
127
+ };
128
+ }
@@ -0,0 +1,19 @@
1
+ import { type Plugin } from "vite";
2
+ declare const LOADERS: {
3
+ node: string;
4
+ "cloudflare-workers": string;
5
+ "netlify-edge": string;
6
+ };
7
+ export interface EnvPluginOptions {
8
+ server?: {
9
+ runtime?: keyof typeof LOADERS | (string & {});
10
+ load?: (mode: string) => Record<string, string>;
11
+ prefix?: string;
12
+ };
13
+ client?: {
14
+ load?: (mode: string) => Record<string, string>;
15
+ prefix?: string;
16
+ };
17
+ }
18
+ export declare function envPlugin(options?: EnvPluginOptions): Plugin;
19
+ export {};
@@ -0,0 +1,81 @@
1
+ import { loadEnv } from "vite";
2
+ const LOADERS = {
3
+ node: `export default key => process.env[key];`,
4
+ "cloudflare-workers": `import { env } from 'cloudflare:workers';export default key => env[key];`,
5
+ "netlify-edge": `export default key => Netlify.env.get(key);`,
6
+ };
7
+ const SERVER_ENV = "env:server";
8
+ const CLIENT_ENV = "env:client";
9
+ const SERVER_RUNTIME_ENV = `${SERVER_ENV}/runtime`;
10
+ const SERVER_RUNTIME_LOADER = `${SERVER_RUNTIME_ENV}/loader`;
11
+ const DEFAULT_SERVER_PREFIX = "SERVER_";
12
+ const DEFAULT_CLIENT_PREFIX = "CLIENT_";
13
+ const SERVER_ONLY_MODULE = `throw new Error('Attempt to load server-only environment variables in client runtime.');`;
14
+ const SERVER_RUNTIME_CODE = `import load from '${SERVER_RUNTIME_LOADER}';
15
+
16
+ export default new Proxy({}, {
17
+ get(_, key) {
18
+ return load(key);
19
+ },
20
+ })`;
21
+ function convertObjectToModule(object) {
22
+ let result = "";
23
+ for (const key in object) {
24
+ result += `export const ${key} = ${JSON.stringify(object[key])};`;
25
+ }
26
+ return result;
27
+ }
28
+ export function envPlugin(options) {
29
+ const currentOptions = options ?? {};
30
+ let env;
31
+ const serverPrefix = currentOptions.server?.prefix ?? DEFAULT_SERVER_PREFIX;
32
+ const clientPrefix = currentOptions.client?.prefix ?? DEFAULT_CLIENT_PREFIX;
33
+ const runtime = options?.server?.runtime ?? "node";
34
+ const runtimeCode = runtime in LOADERS ? LOADERS[runtime] : runtime;
35
+ return {
36
+ name: "solid-start:env",
37
+ enforce: "pre",
38
+ configResolved(config) {
39
+ env = config.mode !== "production" ? "development" : "production";
40
+ },
41
+ resolveId(id) {
42
+ if (id === SERVER_ENV ||
43
+ id === CLIENT_ENV ||
44
+ id === SERVER_RUNTIME_ENV ||
45
+ id === SERVER_RUNTIME_LOADER) {
46
+ return id;
47
+ }
48
+ return undefined;
49
+ },
50
+ load(id, opts) {
51
+ if (id === SERVER_ENV) {
52
+ if (!opts?.ssr) {
53
+ return SERVER_ONLY_MODULE;
54
+ }
55
+ const vars = currentOptions.server?.load
56
+ ? currentOptions.server.load(env)
57
+ : loadEnv(env, '.', serverPrefix);
58
+ return convertObjectToModule(vars);
59
+ }
60
+ if (id === CLIENT_ENV) {
61
+ const vars = currentOptions.client?.load
62
+ ? currentOptions.client.load(env)
63
+ : loadEnv(env, '.', clientPrefix);
64
+ return convertObjectToModule(vars);
65
+ }
66
+ if (id === SERVER_RUNTIME_LOADER) {
67
+ if (!opts?.ssr) {
68
+ return SERVER_ONLY_MODULE;
69
+ }
70
+ return runtimeCode;
71
+ }
72
+ if (id === SERVER_RUNTIME_ENV) {
73
+ if (!opts?.ssr) {
74
+ return SERVER_ONLY_MODULE;
75
+ }
76
+ return SERVER_RUNTIME_CODE;
77
+ }
78
+ return undefined;
79
+ },
80
+ };
81
+ }
@@ -0,0 +1,37 @@
1
+ import { BaseFileSystemRouter, type FileSystemRouterConfig } from "./fs-routes/router.ts";
2
+ export declare class SolidStartClientFileRouter extends BaseFileSystemRouter {
3
+ toPath(src: string): string;
4
+ toRoute(src: string): {
5
+ page: boolean;
6
+ $component: {
7
+ src: string;
8
+ pick: string[];
9
+ };
10
+ $$route: {
11
+ src: string;
12
+ pick: string[];
13
+ } | undefined;
14
+ path: string;
15
+ } | undefined;
16
+ }
17
+ export declare class SolidStartServerFileRouter extends BaseFileSystemRouter {
18
+ config: FileSystemRouterConfig & {
19
+ dataOnly?: boolean;
20
+ };
21
+ constructor(config: FileSystemRouterConfig & {
22
+ dataOnly?: boolean;
23
+ });
24
+ toPath(src: string): string;
25
+ toRoute(src: string): {
26
+ page: boolean;
27
+ $component: {
28
+ src: string;
29
+ pick: string[];
30
+ } | undefined;
31
+ $$route: {
32
+ src: string;
33
+ pick: string[];
34
+ } | undefined;
35
+ path: string;
36
+ } | undefined;
37
+ }
@@ -0,0 +1,141 @@
1
+ import { analyzeModule, BaseFileSystemRouter, cleanPath, } from "./fs-routes/router.js";
2
+ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
3
+ toPath(src) {
4
+ const routePath = cleanPath(src, this.config)
5
+ // remove the initial slash
6
+ .slice(1)
7
+ .replace(/index$/, "")
8
+ .replace(/\[([^/]+)\]/g, (_, m) => {
9
+ if (m.length > 3 && m.startsWith("...")) {
10
+ return `*${m.slice(3)}`;
11
+ }
12
+ if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
13
+ return `:${m.slice(1, -1)}?`;
14
+ }
15
+ return `:${m}`;
16
+ });
17
+ return routePath?.length > 0 ? `/${routePath}` : "/";
18
+ }
19
+ toRoute(src) {
20
+ const path = this.toPath(src);
21
+ if (src.endsWith(".md") || src.endsWith(".mdx")) {
22
+ return {
23
+ page: true,
24
+ $component: {
25
+ src: src,
26
+ pick: ["$css"],
27
+ },
28
+ $$route: undefined,
29
+ path,
30
+ // filePath: src
31
+ };
32
+ }
33
+ const [_, exports] = analyzeModule(src);
34
+ const hasDefault = !!exports.find(e => e.n === "default");
35
+ const hasRouteConfig = !!exports.find(e => e.n === "route");
36
+ if (hasDefault) {
37
+ return {
38
+ page: true,
39
+ $component: {
40
+ src: src,
41
+ pick: [
42
+ ...exports.filter(e => e.n === e.ln && e.n !== "route").map(e => e.n),
43
+ "default",
44
+ "$css",
45
+ ],
46
+ },
47
+ $$route: hasRouteConfig
48
+ ? {
49
+ src: src,
50
+ pick: ["route"],
51
+ }
52
+ : undefined,
53
+ path,
54
+ // filePath: src
55
+ };
56
+ }
57
+ }
58
+ }
59
+ const HTTP_METHODS = ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
60
+ function createHTTPHandlers(src, exports) {
61
+ const handlers = {};
62
+ for (const exp of exports) {
63
+ if (HTTP_METHODS.includes(exp.n)) {
64
+ handlers[`$${exp.n}`] = {
65
+ src: src,
66
+ pick: [exp.n],
67
+ };
68
+ if (exp.n === "GET" && !exports.find(exp => exp.n === "HEAD")) {
69
+ handlers.$HEAD = {
70
+ src: src,
71
+ pick: [exp.n],
72
+ };
73
+ }
74
+ }
75
+ }
76
+ return handlers;
77
+ }
78
+ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
79
+ constructor(config) {
80
+ super(config);
81
+ }
82
+ toPath(src) {
83
+ const routePath = cleanPath(src, this.config)
84
+ // remove the initial slash
85
+ .slice(1)
86
+ .replace(/index$/, "")
87
+ .replace(/\[([^/]+)\]/g, (_, m) => {
88
+ if (m.length > 3 && m.startsWith("...")) {
89
+ return `*${m.slice(3)}`;
90
+ }
91
+ if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
92
+ return `:${m.slice(1, -1)}?`;
93
+ }
94
+ return `:${m}`;
95
+ });
96
+ return routePath?.length > 0 ? `/${routePath}` : "/";
97
+ }
98
+ toRoute(src) {
99
+ const path = this.toPath(src);
100
+ if (src.endsWith(".md") || src.endsWith(".mdx")) {
101
+ return {
102
+ page: true,
103
+ $component: {
104
+ src: src,
105
+ pick: ["$css"],
106
+ },
107
+ $$route: undefined,
108
+ path,
109
+ };
110
+ }
111
+ const [_, exports] = analyzeModule(src);
112
+ const hasRouteConfig = exports.find(e => e.n === "route");
113
+ const hasDefault = !!exports.find(e => e.n === "default");
114
+ const hasAPIRoutes = !!exports.find(exp => HTTP_METHODS.includes(exp.n));
115
+ if (hasDefault || hasAPIRoutes) {
116
+ return {
117
+ page: hasDefault,
118
+ $component: !this.config.dataOnly && hasDefault
119
+ ? {
120
+ src: src,
121
+ pick: [
122
+ ...exports
123
+ .filter(e => e.n === e.ln && e.n !== "route" && !HTTP_METHODS.includes(e.n))
124
+ .map(e => e.n),
125
+ "default",
126
+ "$css",
127
+ ],
128
+ }
129
+ : undefined,
130
+ $$route: hasRouteConfig
131
+ ? {
132
+ src: src,
133
+ pick: ["route"],
134
+ }
135
+ : undefined,
136
+ ...createHTTPHandlers(src, exports),
137
+ path,
138
+ };
139
+ }
140
+ }
141
+ }
@@ -0,0 +1,3 @@
1
+ import type { PluginOption } from "vite";
2
+ import type { BaseFileSystemRouter } from "./router.ts";
3
+ export declare const fileSystemWatcher: (routers: Record<"client" | "ssr", BaseFileSystemRouter>) => PluginOption;
@@ -0,0 +1,53 @@
1
+ import { debounce } from "../../utils/debounce.js";
2
+ import { VITE_ENVIRONMENTS } from "../constants.js";
3
+ import { moduleId } from "./index.js";
4
+ function setupWatcher(watcher, routes) {
5
+ watcher.on("unlink", path => routes.removeRoute(path));
6
+ watcher.on("add", path => routes.addRoute(path));
7
+ watcher.on("change", path => routes.updateRoute(path));
8
+ }
9
+ function createRoutesReloader(server, routes, environment) {
10
+ const devEnv = server.environments[environment];
11
+ if (!devEnv?.moduleGraph)
12
+ return;
13
+ /**
14
+ * Debounce catches multiple route changes in a row
15
+ * Short timeout for inexpensive invalidations
16
+ */
17
+ const invalidateModule = debounce((mod) => {
18
+ devEnv.moduleGraph.invalidateModule(mod);
19
+ }, 0);
20
+ /**
21
+ * Long debounce timeout for expensive reloads
22
+ */
23
+ const reloadModule = debounce((mod) => {
24
+ devEnv.reloadModule(mod);
25
+ }, 200);
26
+ return routes.on("reload", function handleRoutesReload(evt) {
27
+ const mod = devEnv.moduleGraph.getModuleById(moduleId);
28
+ if (!mod) {
29
+ devEnv.hot.send({ type: "full-reload" });
30
+ return;
31
+ }
32
+ if (environment === VITE_ENVIRONMENTS.client && evt.detail.type !== "update") {
33
+ // Client has to be reloaded when routes are added or removed
34
+ reloadModule(mod);
35
+ }
36
+ else {
37
+ invalidateModule(mod);
38
+ }
39
+ });
40
+ }
41
+ export const fileSystemWatcher = (routers) => {
42
+ const plugin = {
43
+ name: "fs-watcher",
44
+ async configureServer(server) {
45
+ for (const environment of [VITE_ENVIRONMENTS.server, VITE_ENVIRONMENTS.client]) {
46
+ const router = routers[environment];
47
+ setupWatcher(server.watcher, router);
48
+ createRoutesReloader(server, router, environment);
49
+ }
50
+ },
51
+ };
52
+ return plugin;
53
+ };
@@ -0,0 +1,7 @@
1
+ import { type PluginOption } from "vite";
2
+ import type { BaseFileSystemRouter } from "./router.ts";
3
+ export declare const moduleId = "solid-start:routes";
4
+ export interface FsRoutesArgs {
5
+ routers: Record<"client" | "ssr", BaseFileSystemRouter>;
6
+ }
7
+ export declare function fsRoutes({ routers }: FsRoutesArgs): Array<PluginOption>;