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

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 (238) hide show
  1. package/CHANGELOG.md +64 -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/boundary-modules.d.ts +14 -0
  10. package/dist/config/boundary-modules.js +41 -0
  11. package/dist/config/constants.d.ts +16 -0
  12. package/dist/config/constants.js +16 -0
  13. package/dist/config/dev-server.d.ts +4 -0
  14. package/dist/config/dev-server.js +146 -0
  15. package/dist/config/env.d.ts +19 -0
  16. package/dist/config/env.js +85 -0
  17. package/dist/config/fs-router.d.ts +37 -0
  18. package/dist/config/fs-router.js +148 -0
  19. package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
  20. package/dist/config/fs-routes/fs-watcher.js +53 -0
  21. package/dist/config/fs-routes/index.d.ts +7 -0
  22. package/dist/config/fs-routes/index.js +107 -0
  23. package/dist/config/fs-routes/router.d.ts +43 -0
  24. package/dist/config/fs-routes/router.js +146 -0
  25. package/dist/config/fs-routes/tree-shake.d.ts +2 -0
  26. package/dist/config/fs-routes/tree-shake.js +305 -0
  27. package/dist/config/index.d.ts +25 -0
  28. package/dist/config/index.js +252 -0
  29. package/dist/config/lazy.d.ts +3 -0
  30. package/dist/config/lazy.js +114 -0
  31. package/dist/config/manifest.d.ts +3 -0
  32. package/dist/config/manifest.js +109 -0
  33. package/dist/config/utils.d.ts +4 -0
  34. package/dist/config/utils.js +6 -0
  35. package/dist/config/vite-utils.d.ts +21 -0
  36. package/dist/config/vite-utils.js +85 -0
  37. package/dist/directives/bubble-function-declaration.d.ts +3 -0
  38. package/dist/directives/bubble-function-declaration.js +23 -0
  39. package/dist/directives/compile.d.ts +9 -0
  40. package/dist/directives/compile.js +40 -0
  41. package/dist/directives/generate-unique-name.d.ts +3 -0
  42. package/dist/directives/generate-unique-name.js +16 -0
  43. package/dist/directives/get-descriptive-name.d.ts +2 -0
  44. package/dist/directives/get-descriptive-name.js +37 -0
  45. package/dist/directives/get-import-identifier.d.ts +4 -0
  46. package/dist/directives/get-import-identifier.js +19 -0
  47. package/dist/directives/get-root-statement-path.d.ts +2 -0
  48. package/dist/directives/get-root-statement-path.js +12 -0
  49. package/dist/directives/index.d.ts +14 -0
  50. package/dist/directives/index.js +202 -0
  51. package/dist/directives/is-statement-top-level.d.ts +3 -0
  52. package/dist/directives/is-statement-top-level.js +9 -0
  53. package/dist/directives/paths.d.ts +9 -0
  54. package/dist/directives/paths.js +36 -0
  55. package/dist/directives/plugin.d.ts +21 -0
  56. package/dist/directives/plugin.js +302 -0
  57. package/dist/directives/remove-unused-variables.d.ts +3 -0
  58. package/dist/directives/remove-unused-variables.js +66 -0
  59. package/{src/directives/types.ts → dist/directives/types.d.ts} +5 -7
  60. package/dist/directives/types.js +1 -0
  61. package/dist/directives/xxhash32.d.ts +6 -0
  62. package/dist/directives/xxhash32.js +193 -0
  63. package/dist/fns/client.d.ts +3 -0
  64. package/dist/fns/client.js +106 -0
  65. package/dist/fns/handler.d.ts +5 -0
  66. package/dist/fns/handler.js +305 -0
  67. package/dist/fns/registration.d.ts +3 -0
  68. package/dist/fns/registration.js +15 -0
  69. package/dist/fns/serialization.d.ts +6 -0
  70. package/dist/fns/serialization.js +208 -0
  71. package/dist/fns/server.d.ts +7 -0
  72. package/dist/fns/server.js +38 -0
  73. package/dist/fns/shared.d.ts +17 -0
  74. package/dist/fns/shared.js +105 -0
  75. package/dist/http/http.d.ts +81 -0
  76. package/dist/http/http.js +129 -0
  77. package/dist/http/index.d.ts +2 -0
  78. package/dist/http/index.js +6 -0
  79. package/{src/index.tsx → dist/index.d.ts} +0 -2
  80. package/dist/index.jsx +6 -0
  81. package/dist/middleware/index.d.ts +39 -0
  82. package/dist/middleware/index.js +60 -0
  83. package/dist/router.d.ts +6 -0
  84. package/dist/router.jsx +29 -0
  85. package/dist/server/StartServer.d.ts +9 -0
  86. package/dist/server/StartServer.jsx +34 -0
  87. package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
  88. package/{src/server/assets/PatchVirtualDevStyles.tsx → dist/server/assets/PatchVirtualDevStyles.jsx} +7 -10
  89. package/dist/server/assets/index.d.ts +2 -0
  90. package/dist/server/assets/index.js +52 -0
  91. package/dist/server/assets/render.d.ts +19 -0
  92. package/dist/server/assets/render.jsx +14 -0
  93. package/dist/server/collect-styles.d.ts +3 -0
  94. package/dist/server/collect-styles.js +57 -0
  95. package/dist/server/fetchEvent.d.ts +7 -0
  96. package/dist/server/fetchEvent.js +26 -0
  97. package/dist/server/handler.d.ts +6 -0
  98. package/dist/server/handler.js +218 -0
  99. package/dist/server/index.d.ts +9 -0
  100. package/{src/server/index.tsx → dist/server/index.jsx} +4 -19
  101. package/dist/server/manifest/client-manifest.d.ts +9 -0
  102. package/dist/server/manifest/client-manifest.js +6 -0
  103. package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
  104. package/dist/server/manifest/dev-client-manifest.js +24 -0
  105. package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
  106. package/dist/server/manifest/dev-ssr-manifest.js +23 -0
  107. package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
  108. package/dist/server/manifest/prod-client-manifest.js +26 -0
  109. package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
  110. package/dist/server/manifest/prod-ssr-manifest.js +85 -0
  111. package/dist/server/manifest/ssr-manifest.d.ts +4 -0
  112. package/dist/server/manifest/ssr-manifest.js +6 -0
  113. package/dist/server/routes.d.ts +23 -0
  114. package/dist/server/routes.js +74 -0
  115. package/dist/server/spa/StartServer.d.ts +9 -0
  116. package/dist/server/spa/StartServer.jsx +25 -0
  117. package/dist/server/spa/handler.d.ts +8 -0
  118. package/dist/server/spa/handler.js +20 -0
  119. package/{src/server/spa/index.tsx → dist/server/spa/index.d.ts} +0 -1
  120. package/dist/server/spa/index.jsx +5 -0
  121. package/dist/server/types.d.ts +75 -0
  122. package/dist/server/types.js +1 -0
  123. package/dist/server/util.d.ts +2 -0
  124. package/dist/server/util.js +8 -0
  125. package/dist/server/web-stream.d.ts +9 -0
  126. package/dist/server/web-stream.js +26 -0
  127. package/dist/shared/ErrorBoundary.d.ts +3 -0
  128. package/dist/shared/ErrorBoundary.jsx +36 -0
  129. package/dist/shared/GET.d.ts +5 -0
  130. package/dist/shared/GET.js +8 -0
  131. package/dist/shared/HttpHeader.d.ts +10 -0
  132. package/dist/shared/HttpHeader.jsx +38 -0
  133. package/dist/shared/HttpStatusCode.d.ts +9 -0
  134. package/dist/shared/HttpStatusCode.js +18 -0
  135. package/dist/shared/clientOnly.d.ts +12 -0
  136. package/dist/shared/clientOnly.js +27 -0
  137. package/dist/shared/dev-overlay/CodeView.d.ts +7 -0
  138. package/dist/shared/dev-overlay/CodeView.jsx +62 -0
  139. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +9 -0
  140. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +226 -0
  141. package/dist/shared/dev-overlay/createStackFrame.d.ts +9 -0
  142. package/dist/shared/dev-overlay/createStackFrame.js +56 -0
  143. package/dist/shared/dev-overlay/download.d.ts +1 -0
  144. package/dist/shared/dev-overlay/download.js +6 -0
  145. package/dist/shared/dev-overlay/get-source-map.d.ts +2 -0
  146. package/dist/shared/dev-overlay/get-source-map.js +25 -0
  147. package/dist/shared/dev-overlay/icons.d.ts +28 -0
  148. package/dist/shared/dev-overlay/icons.jsx +150 -0
  149. package/dist/shared/dev-overlay/index.d.ts +5 -0
  150. package/dist/shared/dev-overlay/index.jsx +39 -0
  151. package/dist/shared/lazy.d.ts +3 -0
  152. package/dist/shared/lazy.js +42 -0
  153. package/dist/shared/serverFunction.d.ts +6 -0
  154. package/dist/shared/serverFunction.js +8 -0
  155. package/dist/utils/debounce.d.ts +4 -0
  156. package/dist/utils/debounce.js +10 -0
  157. package/env.d.ts +12 -0
  158. package/package.json +10 -5
  159. package/scripts/build.js +0 -15
  160. package/scripts/validate-imports.js +0 -316
  161. package/src/client/mount.ts +0 -1
  162. package/src/client/spa/index.tsx +0 -9
  163. package/src/config/constants.ts +0 -19
  164. package/src/config/dev-server.ts +0 -161
  165. package/src/config/env.ts +0 -105
  166. package/src/config/fs-router.ts +0 -162
  167. package/src/config/fs-routes/fs-watcher.ts +0 -66
  168. package/src/config/fs-routes/index.ts +0 -136
  169. package/src/config/fs-routes/router.ts +0 -184
  170. package/src/config/fs-routes/tree-shake.ts +0 -324
  171. package/src/config/index.ts +0 -239
  172. package/src/config/lazy.ts +0 -132
  173. package/src/config/manifest.ts +0 -120
  174. package/src/config/utils.ts +0 -5
  175. package/src/config/vite-utils.ts +0 -113
  176. package/src/directives/bubble-function-declaration.ts +0 -33
  177. package/src/directives/compile.ts +0 -54
  178. package/src/directives/generate-unique-name.ts +0 -22
  179. package/src/directives/get-descriptive-name.ts +0 -39
  180. package/src/directives/get-import-identifier.ts +0 -34
  181. package/src/directives/get-root-statement-path.ts +0 -14
  182. package/src/directives/index.ts +0 -233
  183. package/src/directives/is-statement-top-level.ts +0 -13
  184. package/src/directives/paths.ts +0 -63
  185. package/src/directives/plugin.ts +0 -389
  186. package/src/directives/remove-unused-variables.ts +0 -70
  187. package/src/directives/xxhash32.ts +0 -214
  188. package/src/env.d.ts +0 -17
  189. package/src/fns/client.ts +0 -141
  190. package/src/fns/handler.spec.ts +0 -85
  191. package/src/fns/handler.ts +0 -287
  192. package/src/fns/registration.ts +0 -19
  193. package/src/fns/serialization.ts +0 -250
  194. package/src/fns/server.ts +0 -46
  195. package/src/fns/shared.ts +0 -116
  196. package/src/http/index.ts +0 -216
  197. package/src/internal.d.ts +0 -14
  198. package/src/middleware/index.ts +0 -92
  199. package/src/router.tsx +0 -37
  200. package/src/server/StartServer.tsx +0 -58
  201. package/src/server/assets/index.ts +0 -70
  202. package/src/server/assets/render.tsx +0 -46
  203. package/src/server/collect-styles.ts +0 -70
  204. package/src/server/fetchEvent.spec.ts +0 -85
  205. package/src/server/fetchEvent.ts +0 -36
  206. package/src/server/handler.ts +0 -261
  207. package/src/server/manifest/client-manifest.ts +0 -8
  208. package/src/server/manifest/dev-client-manifest.ts +0 -21
  209. package/src/server/manifest/dev-ssr-manifest.ts +0 -23
  210. package/src/server/manifest/prod-client-manifest.ts +0 -21
  211. package/src/server/manifest/prod-ssr-manifest.ts +0 -109
  212. package/src/server/manifest/ssr-manifest.ts +0 -10
  213. package/src/server/routes.ts +0 -126
  214. package/src/server/spa/StartServer.tsx +0 -42
  215. package/src/server/spa/handler.ts +0 -29
  216. package/src/server/types.ts +0 -82
  217. package/src/server/util.ts +0 -12
  218. package/src/shared/ErrorBoundary.tsx +0 -52
  219. package/src/shared/GET.ts +0 -8
  220. package/src/shared/HttpHeader.tsx +0 -42
  221. package/src/shared/HttpStatusCode.ts +0 -27
  222. package/src/shared/clientOnly.ts +0 -44
  223. package/src/shared/dev-overlay/CodeView.tsx +0 -90
  224. package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
  225. package/src/shared/dev-overlay/createStackFrame.ts +0 -74
  226. package/src/shared/dev-overlay/download.ts +0 -6
  227. package/src/shared/dev-overlay/env.d.ts +0 -4
  228. package/src/shared/dev-overlay/get-source-map.ts +0 -33
  229. package/src/shared/dev-overlay/icons.tsx +0 -456
  230. package/src/shared/dev-overlay/index.tsx +0 -63
  231. package/src/shared/lazy.ts +0 -52
  232. package/src/shared/serverFunction.ts +0 -10
  233. package/src/utils/debounce.ts +0 -10
  234. package/src/virtual.d.ts +0 -27
  235. package/tsconfig.json +0 -24
  236. package/vitest.config.ts +0 -9
  237. /package/{src/client/index.tsx → dist/client/index.d.ts} +0 -0
  238. /package/{src → dist}/shared/dev-overlay/styles.css +0 -0
@@ -0,0 +1,305 @@
1
+ // All credit for this work goes to the amazing Next.js team.
2
+ // https://github.com/vercel/next.js/blob/canary/packages/next/build/babel/plugins/next-ssg-transform.ts
3
+ // This is adapted to work with routeData functions. It can be run in two modes, one which preserves the routeData and the Component in the same file, and one which creates a
4
+ import { basename } from "pathe";
5
+ function treeShakeTransform({ types: t }) {
6
+ function getIdentifier(path) {
7
+ const parentPath = path.parentPath;
8
+ if (parentPath.type === "VariableDeclarator") {
9
+ const pp = parentPath;
10
+ const name = pp.get("id");
11
+ return name.node.type === "Identifier" ? name : null;
12
+ }
13
+ if (parentPath.type === "AssignmentExpression") {
14
+ const pp = parentPath;
15
+ const name = pp.get("left");
16
+ return name.node.type === "Identifier" ? name : null;
17
+ }
18
+ if (path.node.type === "ArrowFunctionExpression") {
19
+ return null;
20
+ }
21
+ return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
22
+ }
23
+ function isIdentifierReferenced(ident) {
24
+ const b = ident.scope.getBinding(ident.node.name);
25
+ if (b?.referenced) {
26
+ if (b.path.type === "FunctionDeclaration") {
27
+ return !b.constantViolations
28
+ .concat(b.referencePaths)
29
+ .every(ref => ref.findParent(p => p === b.path));
30
+ }
31
+ return true;
32
+ }
33
+ return false;
34
+ }
35
+ function markFunction(path, state) {
36
+ const ident = getIdentifier(path);
37
+ if (ident && ident.node && isIdentifierReferenced(ident)) {
38
+ state.refs.add(ident);
39
+ }
40
+ }
41
+ function markImport(path, state) {
42
+ const local = path.get("local");
43
+ if (isIdentifierReferenced(local)) {
44
+ state.refs.add(local);
45
+ }
46
+ }
47
+ return {
48
+ visitor: {
49
+ Program: {
50
+ enter(path, state) {
51
+ state.refs = new Set();
52
+ state.done = false;
53
+ path.traverse({
54
+ VariableDeclarator(variablePath, variableState) {
55
+ if (variablePath.node.id.type === "Identifier") {
56
+ const local = variablePath.get("id");
57
+ if (isIdentifierReferenced(local)) {
58
+ variableState.refs.add(local);
59
+ }
60
+ }
61
+ else if (variablePath.node.id.type === "ObjectPattern") {
62
+ const pattern = variablePath.get("id");
63
+ const properties = pattern.get("properties");
64
+ properties.forEach(p => {
65
+ const local = p.get(p.node.type === "ObjectProperty"
66
+ ? "value"
67
+ : p.node.type === "RestElement"
68
+ ? "argument"
69
+ : (() => {
70
+ throw new Error("invariant");
71
+ })());
72
+ if (isIdentifierReferenced(local)) {
73
+ variableState.refs.add(local);
74
+ }
75
+ });
76
+ }
77
+ else if (variablePath.node.id.type === "ArrayPattern") {
78
+ const pattern = variablePath.get("id");
79
+ const elements = pattern.get("elements");
80
+ elements.forEach(e => {
81
+ let local;
82
+ if (e.node && e.node.type === "Identifier") {
83
+ local = e;
84
+ }
85
+ else if (e.node && e.node.type === "RestElement") {
86
+ local = e.get("argument");
87
+ }
88
+ else {
89
+ return;
90
+ }
91
+ if (isIdentifierReferenced(local)) {
92
+ variableState.refs.add(local);
93
+ }
94
+ });
95
+ }
96
+ },
97
+ ExportDefaultDeclaration(exportNamedPath) {
98
+ // if opts.keep is true, we don't remove the routeData export
99
+ if (state.opts.pick && !state.opts.pick.includes("default")) {
100
+ exportNamedPath.remove();
101
+ }
102
+ },
103
+ ExportNamedDeclaration(exportNamedPath) {
104
+ // if opts.keep is false, we don't remove the routeData export
105
+ if (!state.opts.pick) {
106
+ return;
107
+ }
108
+ const specifiers = exportNamedPath.get("specifiers");
109
+ if (specifiers.length) {
110
+ specifiers.forEach(s => {
111
+ if (t.isIdentifier(s.node.exported)
112
+ ? s.node.exported.name
113
+ : state.opts.pick.includes(s.node.exported.value)) {
114
+ s.remove();
115
+ }
116
+ });
117
+ if (exportNamedPath.node.specifiers.length < 1) {
118
+ exportNamedPath.remove();
119
+ }
120
+ return;
121
+ }
122
+ const decl = exportNamedPath.get("declaration");
123
+ if (decl == null || decl.node == null) {
124
+ return;
125
+ }
126
+ switch (decl.node.type) {
127
+ case "FunctionDeclaration": {
128
+ const name = decl.node.id?.name;
129
+ if (name && state.opts.pick && !state.opts.pick.includes(name)) {
130
+ exportNamedPath.remove();
131
+ }
132
+ break;
133
+ }
134
+ case "VariableDeclaration": {
135
+ const inner = decl.get("declarations");
136
+ inner.forEach(d => {
137
+ if (d.node.id.type !== "Identifier") {
138
+ return;
139
+ }
140
+ const name = d.node.id.name;
141
+ if (state.opts.pick && !state.opts.pick.includes(name)) {
142
+ d.remove();
143
+ }
144
+ });
145
+ break;
146
+ }
147
+ default: {
148
+ break;
149
+ }
150
+ }
151
+ },
152
+ FunctionDeclaration: markFunction,
153
+ FunctionExpression: markFunction,
154
+ ArrowFunctionExpression: markFunction,
155
+ ImportSpecifier: markImport,
156
+ ImportDefaultSpecifier: markImport,
157
+ ImportNamespaceSpecifier: markImport,
158
+ ImportDeclaration: (path, state) => {
159
+ if (path.node.source.value.endsWith(".css") &&
160
+ state.opts.pick &&
161
+ !state.opts.pick.includes("$css")) {
162
+ path.remove();
163
+ }
164
+ },
165
+ }, state);
166
+ const refs = state.refs;
167
+ let count = 0;
168
+ const sweepFunction = (sweepPath) => {
169
+ const ident = getIdentifier(sweepPath);
170
+ if (ident && ident.node && refs.has(ident) && !isIdentifierReferenced(ident)) {
171
+ ++count;
172
+ if (t.isAssignmentExpression(sweepPath.parentPath) ||
173
+ t.isVariableDeclarator(sweepPath.parentPath)) {
174
+ sweepPath.parentPath.remove();
175
+ }
176
+ else {
177
+ sweepPath.remove();
178
+ }
179
+ }
180
+ };
181
+ function sweepImport(sweepPath) {
182
+ const local = sweepPath.get("local");
183
+ if (refs.has(local) && !isIdentifierReferenced(local)) {
184
+ ++count;
185
+ sweepPath.remove();
186
+ if (sweepPath.parent.specifiers.length === 0) {
187
+ sweepPath.parentPath.remove();
188
+ }
189
+ }
190
+ }
191
+ do {
192
+ path.scope.crawl();
193
+ count = 0;
194
+ path.traverse({
195
+ VariableDeclarator(variablePath) {
196
+ if (variablePath.node.id.type === "Identifier") {
197
+ const local = variablePath.get("id");
198
+ if (refs.has(local) && !isIdentifierReferenced(local)) {
199
+ ++count;
200
+ variablePath.remove();
201
+ }
202
+ }
203
+ else if (variablePath.node.id.type === "ObjectPattern") {
204
+ const pattern = variablePath.get("id");
205
+ const beforeCount = count;
206
+ const properties = pattern.get("properties");
207
+ properties.forEach(p => {
208
+ const local = p.get(p.node.type === "ObjectProperty"
209
+ ? "value"
210
+ : p.node.type === "RestElement"
211
+ ? "argument"
212
+ : (() => {
213
+ throw new Error("invariant");
214
+ })());
215
+ if (refs.has(local) && !isIdentifierReferenced(local)) {
216
+ ++count;
217
+ p.remove();
218
+ }
219
+ });
220
+ if (beforeCount !== count && pattern.get("properties").length < 1) {
221
+ variablePath.remove();
222
+ }
223
+ }
224
+ else if (variablePath.node.id.type === "ArrayPattern") {
225
+ const pattern = variablePath.get("id");
226
+ const beforeCount = count;
227
+ const elements = pattern.get("elements");
228
+ elements.forEach(e => {
229
+ let local;
230
+ if (e.node && e.node.type === "Identifier") {
231
+ local = e;
232
+ }
233
+ else if (e.node && e.node.type === "RestElement") {
234
+ local = e.get("argument");
235
+ }
236
+ else {
237
+ return;
238
+ }
239
+ if (refs.has(local) && !isIdentifierReferenced(local)) {
240
+ ++count;
241
+ e.remove();
242
+ }
243
+ });
244
+ if (beforeCount !== count && pattern.get("elements").length < 1) {
245
+ variablePath.remove();
246
+ }
247
+ }
248
+ },
249
+ FunctionDeclaration: sweepFunction,
250
+ FunctionExpression: sweepFunction,
251
+ ArrowFunctionExpression: sweepFunction,
252
+ ImportSpecifier: sweepImport,
253
+ ImportDefaultSpecifier: sweepImport,
254
+ ImportNamespaceSpecifier: sweepImport,
255
+ });
256
+ } while (count);
257
+ },
258
+ },
259
+ },
260
+ };
261
+ }
262
+ export function treeShake() {
263
+ async function transform(id, code) {
264
+ const [path, queryString] = id.split("?");
265
+ const query = new URLSearchParams(queryString);
266
+ if (query.has("pick")) {
267
+ const babel = await import("@babel/core");
268
+ const transformed = await babel.transformAsync(code, {
269
+ plugins: [[treeShakeTransform, { pick: query.getAll("pick") }]],
270
+ parserOpts: {
271
+ plugins: ["jsx", "typescript"],
272
+ },
273
+ filename: basename(id),
274
+ ast: false,
275
+ sourceMaps: true,
276
+ configFile: false,
277
+ babelrc: false,
278
+ sourceFileName: id,
279
+ });
280
+ return transformed;
281
+ }
282
+ }
283
+ return {
284
+ name: "tree-shake",
285
+ enforce: "pre",
286
+ async transform(code, id) {
287
+ const [path, queryString] = id.split("?");
288
+ if (!path)
289
+ return;
290
+ const query = new URLSearchParams(queryString);
291
+ const ext = path.split(".").pop();
292
+ if (!ext)
293
+ return;
294
+ if (query.has("pick") && ["js", "jsx", "ts", "tsx"].includes(ext)) {
295
+ const transformed = await transform(id, code);
296
+ if (!transformed?.code)
297
+ return;
298
+ return {
299
+ code: transformed.code,
300
+ map: transformed.map,
301
+ };
302
+ }
303
+ },
304
+ };
305
+ }
@@ -0,0 +1,25 @@
1
+ import type { PluginOption } from "vite";
2
+ import { type Options as SolidOptions } from "vite-plugin-solid";
3
+ import { type ServerFunctionsOptions } from "../directives/index.ts";
4
+ import { type EnvPluginOptions } from "./env.ts";
5
+ export interface SolidStartOptions {
6
+ solid?: Partial<SolidOptions>;
7
+ ssr?: boolean;
8
+ routeDir?: string;
9
+ extensions?: string[];
10
+ middleware?: string;
11
+ serialization?: {
12
+ /**
13
+ * The serialization mode to use for server functions/actions.
14
+ * The "js" mode uses a custom binary format that is more efficient than JSON, but requires a custom deserializer (with `eval()`) on the client.
15
+ * A strong CSP should block `eval()` executions, which would prevent the "js" mode from working.
16
+ * The "json" mode uses JSON for serialization, which is less efficient but can be deserialized with `JSON.parse` on the client.
17
+ *
18
+ * @default "json"
19
+ */
20
+ mode?: "js" | "json";
21
+ };
22
+ env?: EnvPluginOptions;
23
+ serverFunctions?: Pick<ServerFunctionsOptions, "filter">;
24
+ }
25
+ export declare function solidStart(options?: SolidStartOptions): Array<PluginOption>;
@@ -0,0 +1,252 @@
1
+ import { defu } from "defu";
2
+ import { globSync } from "node:fs";
3
+ import { basename, extname, isAbsolute, join } from "node:path";
4
+ import solid from "vite-plugin-solid";
5
+ import { serverFunctionsPlugin } from "../directives/index.js";
6
+ import { boundaryModules } from "./boundary-modules.js";
7
+ import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.js";
8
+ import { devServer } from "./dev-server.js";
9
+ import { envPlugin } from "./env.js";
10
+ import { SolidStartClientFileRouter, SolidStartServerFileRouter } from "./fs-router.js";
11
+ import { fsRoutes } from "./fs-routes/index.js";
12
+ import lazy from "./lazy.js";
13
+ import { manifest } from "./manifest.js";
14
+ import { parseIdQuery } from "./utils.js";
15
+ const absolute = (path, root) => path ? (isAbsolute(path) ? path : join(root, path)) : path;
16
+ export function solidStart(options) {
17
+ const start = defu(options ?? {}, {
18
+ appRoot: "./src",
19
+ routeDir: "./routes",
20
+ ssr: true,
21
+ devOverlay: true,
22
+ experimental: {
23
+ islands: false,
24
+ },
25
+ solid: {},
26
+ extensions: [],
27
+ });
28
+ const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])];
29
+ const routeDir = join(start.appRoot, start.routeDir);
30
+ const root = process.cwd();
31
+ const appEntryPath = globSync(join(root, start.appRoot, "app.{j,t}sx"))[0];
32
+ if (!appEntryPath) {
33
+ throw new Error(`Could not find an app jsx/tsx entry in ${start.appRoot}.`);
34
+ }
35
+ const entryExtension = extname(appEntryPath);
36
+ const handlers = {
37
+ client: `${start.appRoot}/entry-client${entryExtension}`,
38
+ server: `${start.appRoot}/entry-server${entryExtension}`,
39
+ };
40
+ return [
41
+ // TODO (Alexis): check if the comment below is still relevant
42
+ //
43
+ // Must be placed after fsRoutes, as treeShake will remove the
44
+ // server fn exports added in by this plugin
45
+ serverFunctionsPlugin({
46
+ manifest: VIRTUAL_MODULES.serverFnManifest,
47
+ runtime: {
48
+ server: "@solidjs/start/fns/server",
49
+ client: "@solidjs/start/fns/client",
50
+ },
51
+ filter: options?.serverFunctions?.filter,
52
+ }),
53
+ {
54
+ name: "solid-start:config",
55
+ enforce: "pre",
56
+ configEnvironment(name) {
57
+ return {
58
+ resolve: {
59
+ // remove when https://github.com/solidjs/vite-plugin-solid/pull/228 is released
60
+ externalConditions: ["solid", "node"],
61
+ },
62
+ };
63
+ },
64
+ async config(config, env) {
65
+ const clientInput = [handlers.client];
66
+ const clientEntryUrl = env.command === "serve" && config.experimental?.bundledDev
67
+ ? `assets/${basename(handlers.client, entryExtension)}.js`
68
+ : handlers.client;
69
+ if (env.command === "build") {
70
+ const clientRouter = globalThis.ROUTERS.client;
71
+ for (const route of await clientRouter.getRoutes()) {
72
+ for (const [key, value] of Object.entries(route)) {
73
+ if (value && key.startsWith("$") && !key.startsWith("$$")) {
74
+ function toRouteId(route) {
75
+ return `${route.src}?${route.pick.map((p) => `pick=${p}`).join("&")}`;
76
+ }
77
+ clientInput.push(toRouteId(value));
78
+ }
79
+ }
80
+ }
81
+ }
82
+ return {
83
+ appType: "custom",
84
+ build: { assetsDir: "_build/assets" },
85
+ optimizeDeps: {
86
+ // Suppress TS errors from Vite 7 types when configuring Vite 8's Rolldown
87
+ ...{
88
+ rolldownOptions: {
89
+ transform: {
90
+ jsx: "react",
91
+ },
92
+ },
93
+ },
94
+ },
95
+ environments: {
96
+ [VITE_ENVIRONMENTS.client]: {
97
+ consumer: "client",
98
+ build: {
99
+ write: true,
100
+ manifest: true,
101
+ outDir: "dist/client",
102
+ rollupOptions: {
103
+ input: clientInput,
104
+ treeshake: true,
105
+ preserveEntrySignatures: "exports-only",
106
+ },
107
+ },
108
+ },
109
+ [VITE_ENVIRONMENTS.server]: {
110
+ consumer: "server",
111
+ build: {
112
+ ssr: true,
113
+ write: true,
114
+ manifest: true,
115
+ copyPublicDir: false,
116
+ rollupOptions: {
117
+ input: handlers.server,
118
+ },
119
+ outDir: "dist/server",
120
+ commonjsOptions: {
121
+ include: [/node_modules/],
122
+ },
123
+ },
124
+ },
125
+ },
126
+ resolve: {
127
+ alias: {
128
+ "@solidjs/start/server/entry": handlers.server,
129
+ "~": join(process.cwd(), start.appRoot),
130
+ ...(!start.ssr
131
+ ? {
132
+ "@solidjs/start/server": "@solidjs/start/server/spa",
133
+ "@solidjs/start/client": "@solidjs/start/client/spa",
134
+ }
135
+ : {}),
136
+ },
137
+ // Depending on the package manager and dependency structure Vite externalizes @solidjs/start
138
+ // This makes sure that @solidjs/start goes through the Vite build process
139
+ //
140
+ // h3 and cookie-es must be bundled as well: if they stay external, the server build
141
+ // emits bare imports that nitro later re-resolves from the project root, where package
142
+ // managers like yarn may have hoisted the older major versions required by nitropack
143
+ // and unstorage (h3 v1 / cookie-es v1) instead of the versions @solidjs/start needs
144
+ // (see https://github.com/solidjs/solid-start/issues/2101
145
+ // and https://github.com/solidjs/solid-start/issues/2178)
146
+ noExternal: ["@solidjs/start", "h3", "cookie-es"],
147
+ },
148
+ define: {
149
+ "import.meta.env.MANIFEST": `globalThis.MANIFEST`,
150
+ "import.meta.env.START_SSR": JSON.stringify(start.ssr),
151
+ // Use JSON.stringify so backslashes on Windows are escaped and
152
+ // esbuild receives a valid JS string literal for the define value
153
+ "import.meta.env.START_APP_ENTRY": JSON.stringify(appEntryPath),
154
+ "import.meta.env.START_CLIENT_ENTRY": JSON.stringify(handlers.client),
155
+ "import.meta.env.START_CLIENT_ENTRY_URL": JSON.stringify(clientEntryUrl),
156
+ "import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
157
+ "import.meta.env.SEROVAL_MODE": JSON.stringify(start.serialization?.mode || "json"),
158
+ },
159
+ builder: {
160
+ sharedPlugins: true,
161
+ async buildApp(builder) {
162
+ const client = builder.environments[VITE_ENVIRONMENTS.client];
163
+ const server = builder.environments[VITE_ENVIRONMENTS.server];
164
+ if (!client)
165
+ throw new Error("Client environment not found");
166
+ if (!server)
167
+ throw new Error("SSR environment not found");
168
+ if (!client.isBuilt)
169
+ await builder.build(client);
170
+ if (!server.isBuilt)
171
+ await builder.build(server);
172
+ },
173
+ },
174
+ };
175
+ },
176
+ },
177
+ manifest(start),
178
+ fsRoutes({
179
+ routers: {
180
+ client: new SolidStartClientFileRouter({
181
+ dir: absolute(routeDir, root),
182
+ extensions,
183
+ }),
184
+ ssr: new SolidStartServerFileRouter({
185
+ dir: absolute(routeDir, root),
186
+ extensions,
187
+ dataOnly: !start.ssr,
188
+ }),
189
+ },
190
+ }),
191
+ lazy(),
192
+ envPlugin(options?.env),
193
+ boundaryModules(),
194
+ {
195
+ name: "solid-start:boundary-modules",
196
+ enforce: "pre",
197
+ resolveId(id, importer, { ssr }) {
198
+ if (id === "server-only") {
199
+ if (!ssr)
200
+ this.error(`Attempt to import 'server-only' in a client module: ${importer}`);
201
+ }
202
+ else if (id === "client-only") {
203
+ if (ssr)
204
+ this.error(`Attempt to import 'client-only' in a server module: ${importer}`);
205
+ }
206
+ else {
207
+ return null;
208
+ }
209
+ return "\0solid-start:boundary-modules:id";
210
+ },
211
+ load(id) {
212
+ if (id === "\0solid-start:boundary-modules:id")
213
+ return "export {}";
214
+ },
215
+ },
216
+ {
217
+ name: "solid-start:virtual-modules",
218
+ async resolveId(id) {
219
+ const { filename, query } = parseIdQuery(id);
220
+ let base;
221
+ if (filename === VIRTUAL_MODULES.clientEntry)
222
+ base = handlers.client;
223
+ if (filename === VIRTUAL_MODULES.serverEntry)
224
+ base = handlers.server;
225
+ if (filename === VIRTUAL_MODULES.app)
226
+ base = appEntryPath;
227
+ if (base) {
228
+ let id = (await this.resolve(base))?.id;
229
+ if (!id)
230
+ return;
231
+ if (query.size > 0)
232
+ id += `?${query.toString()}`;
233
+ return id;
234
+ }
235
+ },
236
+ },
237
+ {
238
+ name: "solid-start:capture-client-bundle",
239
+ enforce: "post",
240
+ generateBundle(options, bundle) {
241
+ globalThis.START_CLIENT_BUNDLE = bundle;
242
+ globalThis.START_CLIENT_OUT_DIR = options.dir;
243
+ },
244
+ },
245
+ devServer(handlers.server),
246
+ solid({
247
+ ...start.solid,
248
+ ssr: true,
249
+ extensions: extensions.map(ext => `.${ext}`),
250
+ }),
251
+ ];
252
+ }
@@ -0,0 +1,3 @@
1
+ import type { PluginOption } from "vite";
2
+ declare const lazy: () => PluginOption;
3
+ export default lazy;