@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
@@ -0,0 +1,224 @@
1
+ import { defu } from "defu";
2
+ import { globSync } from "node:fs";
3
+ import { extname, isAbsolute, join } from "node:path";
4
+ import solid from "vite-plugin-solid";
5
+ import { serverFunctionsPlugin } from "../directives/index.js";
6
+ import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.js";
7
+ import { devServer } from "./dev-server.js";
8
+ import { envPlugin } from "./env.js";
9
+ import { SolidStartClientFileRouter, SolidStartServerFileRouter } from "./fs-router.js";
10
+ import { fsRoutes } from "./fs-routes/index.js";
11
+ import lazy from "./lazy.js";
12
+ import { manifest } from "./manifest.js";
13
+ import { parseIdQuery } from "./utils.js";
14
+ const absolute = (path, root) => path ? (isAbsolute(path) ? path : join(root, path)) : path;
15
+ export function solidStart(options) {
16
+ const start = defu(options ?? {}, {
17
+ appRoot: "./src",
18
+ routeDir: "./routes",
19
+ ssr: true,
20
+ devOverlay: true,
21
+ experimental: {
22
+ islands: false,
23
+ },
24
+ solid: {},
25
+ extensions: [],
26
+ });
27
+ const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])];
28
+ const routeDir = join(start.appRoot, start.routeDir);
29
+ const root = process.cwd();
30
+ const appEntryPath = globSync(join(root, start.appRoot, "app.{j,t}sx"))[0];
31
+ if (!appEntryPath) {
32
+ throw new Error(`Could not find an app jsx/tsx entry in ${start.appRoot}.`);
33
+ }
34
+ const entryExtension = extname(appEntryPath);
35
+ const handlers = {
36
+ client: `${start.appRoot}/entry-client${entryExtension}`,
37
+ server: `${start.appRoot}/entry-server${entryExtension}`,
38
+ };
39
+ return [
40
+ // TODO (Alexis): check if the comment below is still relevant
41
+ //
42
+ // Must be placed after fsRoutes, as treeShake will remove the
43
+ // server fn exports added in by this plugin
44
+ serverFunctionsPlugin({
45
+ manifest: VIRTUAL_MODULES.serverFnManifest,
46
+ runtime: {
47
+ server: '@solidjs/start/fns/server',
48
+ client: '@solidjs/start/fns/client',
49
+ },
50
+ filter: options?.serverFunctions?.filter,
51
+ }),
52
+ {
53
+ name: "solid-start:config",
54
+ enforce: "pre",
55
+ configEnvironment(name) {
56
+ return {
57
+ resolve: {
58
+ // remove when https://github.com/solidjs/vite-plugin-solid/pull/228 is released
59
+ externalConditions: ["solid", "node"],
60
+ },
61
+ };
62
+ },
63
+ async config(_, env) {
64
+ const clientInput = [handlers.client];
65
+ if (env.command === "build") {
66
+ const clientRouter = globalThis.ROUTERS.client;
67
+ for (const route of await clientRouter.getRoutes()) {
68
+ for (const [key, value] of Object.entries(route)) {
69
+ if (value && key.startsWith("$") && !key.startsWith("$$")) {
70
+ function toRouteId(route) {
71
+ return `${route.src}?${route.pick.map((p) => `pick=${p}`).join("&")}`;
72
+ }
73
+ clientInput.push(toRouteId(value));
74
+ }
75
+ }
76
+ }
77
+ }
78
+ return {
79
+ appType: "custom",
80
+ build: { assetsDir: "_build/assets" },
81
+ optimizeDeps: {
82
+ // Suppress TS errors from Vite 7 types when configuring Vite 8's Rolldown
83
+ ...{
84
+ rolldownOptions: {
85
+ transform: {
86
+ jsx: "react",
87
+ },
88
+ },
89
+ },
90
+ },
91
+ environments: {
92
+ [VITE_ENVIRONMENTS.client]: {
93
+ consumer: "client",
94
+ build: {
95
+ write: true,
96
+ manifest: true,
97
+ outDir: "dist/client",
98
+ rollupOptions: {
99
+ input: clientInput,
100
+ treeshake: true,
101
+ preserveEntrySignatures: "exports-only",
102
+ },
103
+ },
104
+ },
105
+ [VITE_ENVIRONMENTS.server]: {
106
+ consumer: "server",
107
+ build: {
108
+ ssr: true,
109
+ write: true,
110
+ manifest: true,
111
+ copyPublicDir: false,
112
+ rollupOptions: {
113
+ input: "~/entry-server.tsx",
114
+ },
115
+ outDir: "dist/server",
116
+ commonjsOptions: {
117
+ include: [/node_modules/],
118
+ },
119
+ },
120
+ },
121
+ },
122
+ resolve: {
123
+ alias: {
124
+ "@solidjs/start/server/entry": handlers.server,
125
+ "~": join(process.cwd(), start.appRoot),
126
+ ...(!start.ssr
127
+ ? {
128
+ "@solidjs/start/server": "@solidjs/start/server/spa",
129
+ "@solidjs/start/client": "@solidjs/start/client/spa",
130
+ }
131
+ : {}),
132
+ },
133
+ // Depending on the package manager and dependency structure Vite externalizes @solidjs/start
134
+ // This makes sure that @solidjs/start goes through the Vite build process
135
+ //
136
+ // h3 and cookie-es must be bundled as well: if they stay external, the server build
137
+ // emits bare imports that nitro later re-resolves from the project root, where package
138
+ // managers like yarn may have hoisted the older major versions required by nitropack
139
+ // and unstorage (h3 v1 / cookie-es v1) instead of the versions @solidjs/start needs
140
+ // (see https://github.com/solidjs/solid-start/issues/2101
141
+ // and https://github.com/solidjs/solid-start/issues/2178)
142
+ noExternal: ["@solidjs/start", "h3", "cookie-es"],
143
+ },
144
+ define: {
145
+ "import.meta.env.MANIFEST": `globalThis.MANIFEST`,
146
+ "import.meta.env.START_SSR": JSON.stringify(start.ssr),
147
+ // Use JSON.stringify so backslashes on Windows are escaped and
148
+ // esbuild receives a valid JS string literal for the define value
149
+ "import.meta.env.START_APP_ENTRY": JSON.stringify(appEntryPath),
150
+ "import.meta.env.START_CLIENT_ENTRY": JSON.stringify(handlers.client),
151
+ "import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
152
+ "import.meta.env.SEROVAL_MODE": JSON.stringify(start.serialization?.mode || "json"),
153
+ },
154
+ builder: {
155
+ sharedPlugins: true,
156
+ async buildApp(builder) {
157
+ const client = builder.environments[VITE_ENVIRONMENTS.client];
158
+ const server = builder.environments[VITE_ENVIRONMENTS.server];
159
+ if (!client)
160
+ throw new Error("Client environment not found");
161
+ if (!server)
162
+ throw new Error("SSR environment not found");
163
+ if (!client.isBuilt)
164
+ await builder.build(client);
165
+ if (!server.isBuilt)
166
+ await builder.build(server);
167
+ },
168
+ },
169
+ };
170
+ },
171
+ },
172
+ manifest(start),
173
+ fsRoutes({
174
+ routers: {
175
+ client: new SolidStartClientFileRouter({
176
+ dir: absolute(routeDir, root),
177
+ extensions,
178
+ }),
179
+ ssr: new SolidStartServerFileRouter({
180
+ dir: absolute(routeDir, root),
181
+ extensions,
182
+ dataOnly: !start.ssr,
183
+ }),
184
+ },
185
+ }),
186
+ lazy(),
187
+ envPlugin(options?.env),
188
+ {
189
+ name: "solid-start:virtual-modules",
190
+ async resolveId(id) {
191
+ const { filename, query } = parseIdQuery(id);
192
+ let base;
193
+ if (filename === VIRTUAL_MODULES.clientEntry)
194
+ base = handlers.client;
195
+ if (filename === VIRTUAL_MODULES.serverEntry)
196
+ base = handlers.server;
197
+ if (filename === VIRTUAL_MODULES.app)
198
+ base = appEntryPath;
199
+ if (base) {
200
+ let id = (await this.resolve(base))?.id;
201
+ if (!id)
202
+ return;
203
+ if (query.size > 0)
204
+ id += `?${query.toString()}`;
205
+ return id;
206
+ }
207
+ },
208
+ },
209
+ {
210
+ name: "solid-start:capture-client-bundle",
211
+ enforce: "post",
212
+ generateBundle(options, bundle) {
213
+ globalThis.START_CLIENT_BUNDLE = bundle;
214
+ globalThis.START_CLIENT_OUT_DIR = options.dir;
215
+ },
216
+ },
217
+ devServer(),
218
+ solid({
219
+ ...start.solid,
220
+ ssr: true,
221
+ extensions: extensions.map(ext => `.${ext}`),
222
+ }),
223
+ ];
224
+ }
@@ -0,0 +1,3 @@
1
+ import type { PluginOption } from "vite";
2
+ declare const lazy: () => PluginOption;
3
+ export default lazy;
@@ -0,0 +1,114 @@
1
+ import babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ import { sep as osSep } from "node:path";
4
+ import { basename, relative, sep } from "node:path/posix";
5
+ import { VITE_ENVIRONMENTS } from "./constants.js";
6
+ const idTransform = (id) => {
7
+ return {
8
+ visitor: {
9
+ Program(path) {
10
+ path.node.body.unshift(t.exportNamedDeclaration(t.variableDeclaration("const", [
11
+ t.variableDeclarator(t.identifier("id$$"), t.stringLiteral(id)),
12
+ ])));
13
+ },
14
+ },
15
+ };
16
+ };
17
+ const importTransform = () => {
18
+ return {
19
+ visitor: {
20
+ ImportDeclaration(path) {
21
+ if (path.node.source.value !== "solid-js")
22
+ return;
23
+ path.traverse({
24
+ ImportSpecifier(subPath) {
25
+ if (subPath.node.local.name !== "lazy")
26
+ return;
27
+ subPath.remove();
28
+ path.insertAfter(t.importDeclaration([t.importSpecifier(t.identifier("lazy"), t.identifier("lazy"))], t.stringLiteral("@solidjs/start/server")));
29
+ },
30
+ });
31
+ },
32
+ },
33
+ };
34
+ };
35
+ const fileEndingRegex = /(ts|js)x(\?.*)?$/;
36
+ const lazy = () => {
37
+ const cwd = process.cwd().replaceAll(osSep, sep);
38
+ /**
39
+ * Maps module ids to their client-specific shared chunk names.
40
+ * Modules in shared chunks need to find their assets via the chunk name, instead of their module id.
41
+ *
42
+ * Vite includes assets of such modules in the manifest via the chunk name:
43
+ * https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L179
44
+ * https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L319
45
+ *
46
+ * Rollup occassionally creates shared chunks automatically,
47
+ * but they can also be manually created by the user via:
48
+ * https://rollupjs.org/configuration-options/#output-manualchunks
49
+ *
50
+ * More infos on Rollup's logic:
51
+ * https://github.com/rollup/rollup/issues/3772#issuecomment-689955168
52
+ */
53
+ const sharedChunkNames = {};
54
+ return {
55
+ name: "solid-lazy-css",
56
+ enforce: "pre",
57
+ generateBundle(_, bundle) {
58
+ if (this.environment.name !== VITE_ENVIRONMENTS.client)
59
+ return;
60
+ for (const chunk of Object.values(bundle)) {
61
+ if (chunk.type !== "chunk" || !chunk.isDynamicEntry || chunk.facadeModuleId)
62
+ continue;
63
+ // Has to follow Vites implementation:
64
+ // https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L179
65
+ const chunkName = `_${basename(chunk.fileName)}`;
66
+ for (const id of chunk.moduleIds) {
67
+ sharedChunkNames[id] = chunkName;
68
+ }
69
+ }
70
+ },
71
+ async transform(src, id) {
72
+ if (this.environment.name !== VITE_ENVIRONMENTS.server)
73
+ return;
74
+ if (!id.match(fileEndingRegex))
75
+ return;
76
+ // The transformed files either import "lazy" or css files
77
+ // Therefore we skip, if the src doesn't have any import
78
+ if (src.indexOf("import") === -1)
79
+ return;
80
+ if (id.includes("entry-server"))
81
+ return;
82
+ const plugins = [];
83
+ const hasDefaultExport = src.indexOf("export default") !== -1;
84
+ if (hasDefaultExport) {
85
+ const localId = relative(cwd, id);
86
+ const chunkName = sharedChunkNames[id];
87
+ plugins.push(idTransform(chunkName ?? localId));
88
+ }
89
+ const hasLazy = src.indexOf("lazy(") !== -1;
90
+ if (hasLazy)
91
+ plugins.push(importTransform());
92
+ if (!plugins.length) {
93
+ return;
94
+ }
95
+ const transformed = await babel.transformAsync(src, {
96
+ plugins,
97
+ parserOpts: {
98
+ plugins: ["jsx", "typescript"],
99
+ },
100
+ filename: basename(id),
101
+ ast: false,
102
+ sourceMaps: true,
103
+ configFile: false,
104
+ babelrc: false,
105
+ sourceFileName: id,
106
+ });
107
+ if (!transformed?.code)
108
+ return;
109
+ const { code, map } = transformed;
110
+ return { code, map };
111
+ },
112
+ };
113
+ };
114
+ export default lazy;
@@ -0,0 +1,3 @@
1
+ import { type PluginOption } from "vite";
2
+ import { type SolidStartOptions } from "./index.ts";
3
+ export declare function manifest(start: SolidStartOptions): PluginOption;
@@ -0,0 +1,109 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { version as viteVersion } from "vite";
4
+ import { fileURLToPath } from "node:url";
5
+ import { findStylesInModuleGraph } from "../server/collect-styles.js";
6
+ import { VIRTUAL_MODULES } from "./constants.js";
7
+ import { wrapId } from "./vite-utils.js";
8
+ export function manifest(start) {
9
+ let devServer = undefined;
10
+ return {
11
+ name: "solid-start:manifest-plugin",
12
+ enforce: "pre",
13
+ configureServer(server) {
14
+ devServer = server;
15
+ },
16
+ async resolveId(id) {
17
+ if (id === VIRTUAL_MODULES.clientViteManifest)
18
+ return `\0${VIRTUAL_MODULES.clientViteManifest}`;
19
+ if (id === VIRTUAL_MODULES.getClientManifest)
20
+ return this.resolve(fileURLToPath(new URL("../server/manifest/client-manifest", import.meta.url)));
21
+ if (id === VIRTUAL_MODULES.getManifest) {
22
+ return this.environment.config.consumer === "client"
23
+ ? this.resolve(fileURLToPath(new URL("../server/manifest/client-manifest", import.meta.url)))
24
+ : this.resolve(fileURLToPath(new URL("../server/manifest/ssr-manifest", import.meta.url)));
25
+ }
26
+ if (id === VIRTUAL_MODULES.middleware) {
27
+ if (start.middleware)
28
+ return await this.resolve(start.middleware);
29
+ return `\0${VIRTUAL_MODULES.middleware}`;
30
+ }
31
+ },
32
+ async load(id) {
33
+ if (id === `\0${VIRTUAL_MODULES.clientViteManifest}`) {
34
+ let clientViteManifest;
35
+ if (this.environment.config.command === "serve") {
36
+ clientViteManifest = {};
37
+ }
38
+ else {
39
+ const entry = Object.values(globalThis.START_CLIENT_BUNDLE).find(v => "isEntry" in v && v.isEntry);
40
+ if (!entry)
41
+ throw new Error("No client entry found");
42
+ let rawManifest;
43
+ const viteMajor = parseInt(viteVersion.split('.')[0], 10);
44
+ const manifestKey = Object.keys(globalThis.START_CLIENT_BUNDLE).find(k => k.endsWith("manifest.json"));
45
+ if (manifestKey && viteMajor < 8) {
46
+ const manifestAsset = globalThis.START_CLIENT_BUNDLE[manifestKey];
47
+ rawManifest = manifestAsset.source;
48
+ }
49
+ else {
50
+ try {
51
+ const appRoot = start.appRoot || "./src";
52
+ let outDir = ".solid-start/client";
53
+ if (devServer?.environments?.client?.config?.build?.outDir) {
54
+ outDir = devServer.environments.client.config.build.outDir;
55
+ }
56
+ else if (this.environment?.config?.build?.outDir && this.environment?.config?.consumer === "client") {
57
+ outDir = this.environment.config.build.outDir;
58
+ }
59
+ else if (globalThis.START_CLIENT_OUT_DIR) {
60
+ outDir = globalThis.START_CLIENT_OUT_DIR;
61
+ }
62
+ const manifestPath = path.resolve(appRoot, "..", outDir, ".vite/manifest.json");
63
+ rawManifest = fs.readFileSync(manifestPath, "utf-8");
64
+ }
65
+ catch (e) {
66
+ throw new Error(`Manifest asset not found in bundle and could not be read from disk. Keys: ${Object.keys(globalThis.START_CLIENT_BUNDLE).join(", ")}. Error: ${e}`);
67
+ }
68
+ }
69
+ if (!rawManifest) {
70
+ throw new Error("Failed to extract or read raw manifest.");
71
+ }
72
+ clientViteManifest = JSON.parse(rawManifest);
73
+ }
74
+ return `export const clientViteManifest = ${JSON.stringify(clientViteManifest)};`;
75
+ }
76
+ else if (id === `\0${VIRTUAL_MODULES.middleware}`)
77
+ return "export default {};";
78
+ else if (id.startsWith("/@manifest")) {
79
+ if (this.environment.mode !== "dev")
80
+ throw new Error("@manifest queries are only allowed in dev");
81
+ const [urlPath, query] = id.split("?");
82
+ const target = id.split("/")[2];
83
+ const params = new URLSearchParams(query);
84
+ if (!urlPath || !query)
85
+ return;
86
+ if (urlPath.endsWith("assets")) {
87
+ const id = params.get("id");
88
+ if (!id) {
89
+ throw new Error("Missing id to get assets.");
90
+ }
91
+ // Client env does not have css dependencies in mod.transformResult
92
+ // Aalways use ssr env instead, to prevent hydration mismatches
93
+ const env = devServer.environments["ssr"];
94
+ const styles = await findStylesInModuleGraph(env, id);
95
+ const cssAssets = Object.entries(styles).map(([key, value]) => `{
96
+ tag: "style",
97
+ attrs: {
98
+ type: "text/css",
99
+ "data-vite-dev-id": "${wrapId(key)}",
100
+ "data-vite-ref": "0",
101
+ },
102
+ children: () => import("${wrapId(value)}?inline").then(mod => mod.default),
103
+ }`);
104
+ return `export default [${cssAssets.join(",")}]`;
105
+ }
106
+ }
107
+ },
108
+ };
109
+ }
@@ -0,0 +1,4 @@
1
+ export declare function parseIdQuery(id: string): {
2
+ filename: string;
3
+ query: URLSearchParams;
4
+ };
@@ -0,0 +1,6 @@
1
+ export function parseIdQuery(id) {
2
+ if (!id.includes("?"))
3
+ return { filename: id, query: new URLSearchParams() };
4
+ const [filename, rawQuery] = id.split(`?`, 2);
5
+ return { filename, query: new URLSearchParams(rawQuery) };
6
+ }
@@ -0,0 +1,21 @@
1
+ import type { DevEnvironment, Rollup } from "vite";
2
+ export declare function cleanUrl(url: string): string;
3
+ export declare const FS_PREFIX = "/@fs/";
4
+ export declare const VALID_ID_PREFIX = "/@id/";
5
+ export declare const NULL_BYTE_PLACEHOLDER = "__x00__";
6
+ export declare function normalizeResolvedIdToUrl(environment: DevEnvironment, url: string, resolved: Rollup.PartialResolvedId): string;
7
+ /**
8
+ * Inspired by:
9
+ * https://github.com/withastro/astro/blob/fddde5fad81007795eb263c7fd0cea096b8e2cba/packages/astro/src/core/util.ts#L115
10
+ * https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/shared/utils.ts#L11
11
+ */
12
+ export declare function wrapId(id: string): string;
13
+ export declare function unwrapId(id: string): string;
14
+ export declare function normalizeViteImportAnalysisUrl(environment: DevEnvironment, id: string): string;
15
+ export declare function withTrailingSlash(path: string): string;
16
+ export declare function splitFileAndPostfix(path: string): {
17
+ file: string;
18
+ postfix: string;
19
+ };
20
+ export declare function slash(p: string): string;
21
+ export declare function injectQuery(url: string, queryToInject: string): string;
@@ -0,0 +1,85 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ const postfixRE = /[?#].*$/;
4
+ export function cleanUrl(url) {
5
+ return url.replace(postfixRE, "");
6
+ }
7
+ export const FS_PREFIX = `/@fs/`;
8
+ export const VALID_ID_PREFIX = `/@id/`;
9
+ export const NULL_BYTE_PLACEHOLDER = `__x00__`;
10
+ const NULL_BYTE_REGEX = /^\0/;
11
+ export function normalizeResolvedIdToUrl(environment, url, resolved) {
12
+ const root = environment.config.root;
13
+ const depsOptimizer = environment.depsOptimizer;
14
+ // normalize all imports into resolved URLs
15
+ // e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
16
+ if (resolved.id.startsWith(withTrailingSlash(root))) {
17
+ // in root: infer short absolute path from root
18
+ url = resolved.id.slice(root.length);
19
+ }
20
+ else if (depsOptimizer?.isOptimizedDepFile(resolved.id) ||
21
+ // vite-plugin-react isn't following the leading \0 virtual module convention.
22
+ // This is a temporary hack to avoid expensive fs checks for React apps.
23
+ // We'll remove this as soon we're able to fix the react plugins.
24
+ (resolved.id !== "/@react-refresh" &&
25
+ path.isAbsolute(resolved.id) &&
26
+ fs.existsSync(cleanUrl(resolved.id)))) {
27
+ // an optimized deps may not yet exists in the filesystem, or
28
+ // a regular file exists but is out of root: rewrite to absolute /@fs/ paths
29
+ url = path.posix.join(FS_PREFIX, resolved.id);
30
+ }
31
+ else {
32
+ url = resolved.id;
33
+ }
34
+ // if the resolved id is not a valid browser import specifier,
35
+ // prefix it to make it valid. We will strip this before feeding it
36
+ // back into the transform pipeline
37
+ if (url[0] !== "." && url[0] !== "/") {
38
+ url = wrapId(resolved.id);
39
+ }
40
+ return url;
41
+ }
42
+ /**
43
+ * Inspired by:
44
+ * https://github.com/withastro/astro/blob/fddde5fad81007795eb263c7fd0cea096b8e2cba/packages/astro/src/core/util.ts#L115
45
+ * https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/shared/utils.ts#L11
46
+ */
47
+ export function wrapId(id) {
48
+ return id.replace(NULL_BYTE_REGEX, `${VALID_ID_PREFIX}${NULL_BYTE_PLACEHOLDER}`);
49
+ }
50
+ export function unwrapId(id) {
51
+ return id.startsWith(VALID_ID_PREFIX)
52
+ ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0")
53
+ : id;
54
+ }
55
+ export function normalizeViteImportAnalysisUrl(environment, id) {
56
+ let url = normalizeResolvedIdToUrl(environment, id, { id });
57
+ // https://github.com/vitejs/vite/blob/c18ce868c4d70873406e9f7d1b2d0a03264d2168/packages/vite/src/node/plugins/importAnalysis.ts#L416
58
+ if (environment.config.consumer === "client") {
59
+ const mod = environment.moduleGraph.getModuleById(id);
60
+ if (mod && mod.lastHMRTimestamp > 0) {
61
+ url = injectQuery(url, `t=${mod.lastHMRTimestamp}`);
62
+ }
63
+ }
64
+ return url;
65
+ }
66
+ export function withTrailingSlash(path) {
67
+ if (path[path.length - 1] !== "/") {
68
+ return `${path}/`;
69
+ }
70
+ return path;
71
+ }
72
+ export function splitFileAndPostfix(path) {
73
+ const file = cleanUrl(path);
74
+ return { file, postfix: path.slice(file.length) };
75
+ }
76
+ const windowsSlashRE = /\\/g;
77
+ export function slash(p) {
78
+ return p.replace(windowsSlashRE, "/");
79
+ }
80
+ const isWindows = typeof process !== "undefined" && process.platform === "win32";
81
+ export function injectQuery(url, queryToInject) {
82
+ const { file, postfix } = splitFileAndPostfix(url);
83
+ const normalizedFile = isWindows ? slash(file) : file;
84
+ return `${normalizedFile}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : /* hash only */ postfix}`;
85
+ }
@@ -0,0 +1,3 @@
1
+ import type * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ export declare function bubbleFunctionDeclaration(path: babel.NodePath<t.FunctionDeclaration>): void;
@@ -0,0 +1,23 @@
1
+ import * as t from "@babel/types";
2
+ export function bubbleFunctionDeclaration(path) {
3
+ const decl = path.node;
4
+ // Check if declaration is FunctionDeclaration
5
+ if (decl.id) {
6
+ const block = (path.findParent(current => current.isBlockStatement()) ||
7
+ path.scope.getProgramParent().path);
8
+ if (path.parentPath.isExportNamedDeclaration()) {
9
+ path.parentPath.replaceWith(t.exportNamedDeclaration(undefined, [t.exportSpecifier(decl.id, decl.id)]));
10
+ }
11
+ else if (path.parentPath.isExportDefaultDeclaration()) {
12
+ path.replaceWith(decl.id);
13
+ }
14
+ else {
15
+ path.remove();
16
+ }
17
+ const [tmp] = block.unshiftContainer("body", t.variableDeclaration("const", [
18
+ t.variableDeclarator(decl.id, t.functionExpression(decl.id, decl.params, decl.body, decl.generator, decl.async)),
19
+ ]));
20
+ block.scope.registerDeclaration(tmp);
21
+ tmp.skip();
22
+ }
23
+ }
@@ -0,0 +1,9 @@
1
+ import * as babel from "@babel/core";
2
+ import { type StateContext } from "./plugin.ts";
3
+ export interface CompileResult {
4
+ valid: boolean;
5
+ code: string;
6
+ map: babel.BabelFileResult["map"];
7
+ }
8
+ export type CompileOptions = Omit<StateContext, "count" | "hash" | "imports" | "valid">;
9
+ export declare function compile(id: string, code: string, options: CompileOptions): Promise<CompileResult>;
@@ -0,0 +1,40 @@
1
+ import * as babel from "@babel/core";
2
+ import path from "node:path";
3
+ import { directivesPlugin } from "./plugin.js";
4
+ import xxHash32 from "./xxhash32.js";
5
+ export async function compile(id, code, options) {
6
+ const context = {
7
+ ...options,
8
+ valid: false,
9
+ hash: xxHash32(id).toString(16),
10
+ count: 0,
11
+ imports: new Map(),
12
+ };
13
+ const pluginOption = [directivesPlugin, context];
14
+ const plugins = [
15
+ "jsx",
16
+ ];
17
+ if (/\.[mc]?tsx?$/i.test(id)) {
18
+ plugins.push("typescript");
19
+ }
20
+ const result = await babel.transformAsync(code, {
21
+ plugins: [pluginOption],
22
+ parserOpts: {
23
+ plugins,
24
+ },
25
+ filename: path.basename(id),
26
+ ast: false,
27
+ sourceMaps: true,
28
+ configFile: false,
29
+ babelrc: false,
30
+ sourceFileName: id,
31
+ });
32
+ if (result) {
33
+ return {
34
+ valid: context.valid,
35
+ code: result.code || "",
36
+ map: result.map,
37
+ };
38
+ }
39
+ throw new Error("invariant");
40
+ }
@@ -0,0 +1,3 @@
1
+ import type * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ export declare function generateUniqueName(path: babel.NodePath, name: string): t.Identifier;