@solidjs/start 2.0.0-alpha.0 → 2.0.0-alpha.1

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 (96) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/client/mount.d.ts +1 -7
  3. package/dist/client/mount.js +1 -99
  4. package/dist/config/constants.js +2 -2
  5. package/dist/config/fs-router.js +10 -22
  6. package/dist/config/fs-routes/fs-watcher.js +4 -4
  7. package/dist/config/fs-routes/index.js +4 -6
  8. package/dist/config/fs-routes/router.js +5 -5
  9. package/dist/config/fs-routes/tree-shake.js +12 -21
  10. package/dist/config/index.js +33 -36
  11. package/dist/config/lazy.js +9 -9
  12. package/dist/config/manifest.js +1 -1
  13. package/dist/http/index.d.ts +1 -4
  14. package/dist/http/index.js +3 -5
  15. package/dist/index.d.ts +0 -1
  16. package/dist/router.jsx +2 -2
  17. package/dist/server/assets/index.js +1 -1
  18. package/dist/server/assets/render.jsx +2 -2
  19. package/dist/server/fetchEvent.spec.js +1 -1
  20. package/dist/server/handler.js +29 -15
  21. package/dist/server/index.d.ts +1 -0
  22. package/dist/server/manifest/dev-client-manifest.js +1 -1
  23. package/dist/server/manifest/dev-ssr-manifest.js +1 -1
  24. package/dist/server/manifest/prod-ssr-manifest.js +7 -12
  25. package/dist/server/routes.js +3 -3
  26. package/dist/server/server-fns-runtime.js +2 -2
  27. package/dist/server/server-functions-handler.js +6 -11
  28. package/dist/server/server-runtime.js +8 -8
  29. package/dist/shared/dev-overlay/CodeView.d.ts +1 -1
  30. package/dist/shared/dev-overlay/CodeView.jsx +23 -34
  31. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +4 -4
  32. package/dist/shared/dev-overlay/get-source-map.d.ts +1 -1
  33. package/dist/shared/dev-overlay/get-source-map.js +5 -5
  34. package/dist/shared/dev-overlay/icons.d.ts +10 -10
  35. package/dist/shared/dev-overlay/icons.jsx +91 -91
  36. package/dist/shared/dev-overlay/index.jsx +1 -1
  37. package/dist/shared/lazy.js +4 -2
  38. package/env.d.ts +9 -0
  39. package/package.json +5 -4
  40. package/scripts/build.js +3 -3
  41. package/scripts/validate-imports.js +8 -8
  42. package/src/client/mount.ts +1 -114
  43. package/src/config/constants.ts +3 -3
  44. package/src/config/dev-server.ts +95 -99
  45. package/src/config/fs-router.ts +140 -155
  46. package/src/config/fs-routes/fs-watcher.ts +57 -61
  47. package/src/config/fs-routes/index.ts +117 -119
  48. package/src/config/fs-routes/router.ts +7 -7
  49. package/src/config/fs-routes/tree-shake.ts +342 -363
  50. package/src/config/index.ts +36 -39
  51. package/src/config/lazy.ts +13 -13
  52. package/src/config/manifest.ts +5 -5
  53. package/src/config/vite-utils.ts +2 -6
  54. package/src/env.d.ts +10 -28
  55. package/src/http/index.ts +105 -142
  56. package/src/index.tsx +0 -12
  57. package/src/internal.d.ts +1 -1
  58. package/src/middleware/index.ts +39 -49
  59. package/src/router.tsx +4 -3
  60. package/src/server/StartServer.tsx +1 -7
  61. package/src/server/assets/index.ts +1 -1
  62. package/src/server/assets/render.tsx +6 -2
  63. package/src/server/collect-styles.ts +63 -70
  64. package/src/server/fetchEvent.spec.ts +71 -75
  65. package/src/server/fetchEvent.ts +17 -17
  66. package/src/server/handler.ts +136 -129
  67. package/src/server/index.tsx +13 -0
  68. package/src/server/manifest/client-manifest.ts +1 -1
  69. package/src/server/manifest/dev-client-manifest.ts +7 -5
  70. package/src/server/manifest/dev-ssr-manifest.ts +8 -6
  71. package/src/server/manifest/prod-client-manifest.ts +7 -4
  72. package/src/server/manifest/prod-ssr-manifest.ts +78 -94
  73. package/src/server/manifest/ssr-manifest.ts +4 -2
  74. package/src/server/routes.ts +96 -108
  75. package/src/server/server-fns-runtime.ts +3 -3
  76. package/src/server/server-functions-handler.ts +294 -319
  77. package/src/server/server-runtime.ts +13 -13
  78. package/src/server/spa/handler.ts +12 -12
  79. package/src/server/types.ts +46 -46
  80. package/src/server/util.ts +4 -4
  81. package/src/shared/ErrorBoundary.tsx +1 -1
  82. package/src/shared/HttpHeader.tsx +20 -20
  83. package/src/shared/HttpStatusCode.ts +14 -14
  84. package/src/shared/clientOnly.ts +3 -3
  85. package/src/shared/dev-overlay/CodeView.tsx +43 -46
  86. package/src/shared/dev-overlay/DevOverlayDialog.tsx +4 -4
  87. package/src/shared/dev-overlay/createStackFrame.ts +59 -62
  88. package/src/shared/dev-overlay/env.d.ts +2 -2
  89. package/src/shared/dev-overlay/get-source-map.ts +5 -7
  90. package/src/shared/dev-overlay/icons.tsx +289 -121
  91. package/src/shared/dev-overlay/index.tsx +1 -1
  92. package/src/shared/lazy.ts +4 -3
  93. package/src/shared/serverFunction.ts +1 -1
  94. package/src/virtual.d.ts +10 -10
  95. package/tsconfig.json +2 -2
  96. package/vitest.config.ts +2 -2
@@ -1,8 +1,10 @@
1
1
  import { getSsrDevManifest } from "./dev-ssr-manifest.ts";
2
2
  import { getSsrProdManifest } from "./prod-ssr-manifest.ts";
3
3
 
4
- export function getSsrManifest(target: "client" | "ssr"): ReturnType<typeof getSsrDevManifest> | ReturnType<typeof getSsrProdManifest> {
5
- return import.meta.env.DEV ? getSsrDevManifest(target) : getSsrProdManifest();
4
+ export function getSsrManifest(
5
+ target: "client" | "ssr",
6
+ ): ReturnType<typeof getSsrDevManifest> | ReturnType<typeof getSsrProdManifest> {
7
+ return import.meta.env.DEV ? getSsrDevManifest(target) : getSsrProdManifest();
6
8
  }
7
9
 
8
10
  export { getSsrManifest as getManifest };
@@ -5,134 +5,122 @@ import { createRouter } from "radix3";
5
5
  import type { FetchEvent } from "./types.ts";
6
6
 
7
7
  interface Route {
8
- path: string;
9
- id: string;
10
- children?: Route[];
11
- page?: boolean;
12
- $component?: any;
13
- $HEAD?: any;
14
- $GET?: any;
15
- $POST?: any;
16
- $PUT?: any;
17
- $PATCH?: any;
18
- $DELETE?: any;
8
+ path: string;
9
+ id: string;
10
+ children?: Route[];
11
+ page?: boolean;
12
+ $component?: any;
13
+ $HEAD?: any;
14
+ $GET?: any;
15
+ $POST?: any;
16
+ $PUT?: any;
17
+ $PATCH?: any;
18
+ $DELETE?: any;
19
19
  }
20
20
 
21
- export const pageRoutes = defineRoutes(
22
- (fileRoutes as unknown as Route[]).filter((o) => o.page),
23
- );
21
+ export const pageRoutes = defineRoutes((fileRoutes as unknown as Route[]).filter(o => o.page));
24
22
 
25
23
  function defineRoutes(fileRoutes: Route[]) {
26
- function processRoute(
27
- routes: Route[],
28
- route: Route,
29
- id: string,
30
- full: string,
31
- ) {
32
- const parentRoute = Object.values(routes).find((o) => {
33
- return id.startsWith(o.id + "/");
34
- });
24
+ function processRoute(routes: Route[], route: Route, id: string, full: string) {
25
+ const parentRoute = Object.values(routes).find(o => {
26
+ return id.startsWith(o.id + "/");
27
+ });
35
28
 
36
- if (!parentRoute) {
37
- routes.push({
38
- ...route,
39
- id,
40
- path: id.replace(/\([^)/]+\)/g, "").replace(/\/+/g, "/"),
41
- });
42
- return routes;
43
- }
44
- processRoute(
45
- parentRoute.children || (parentRoute.children = []),
46
- route,
47
- id.slice(parentRoute.id.length),
48
- full,
49
- );
29
+ if (!parentRoute) {
30
+ routes.push({
31
+ ...route,
32
+ id,
33
+ path: id.replace(/\([^)/]+\)/g, "").replace(/\/+/g, "/"),
34
+ });
35
+ return routes;
36
+ }
37
+ processRoute(
38
+ parentRoute.children || (parentRoute.children = []),
39
+ route,
40
+ id.slice(parentRoute.id.length),
41
+ full,
42
+ );
50
43
 
51
- return routes;
52
- }
44
+ return routes;
45
+ }
53
46
 
54
- return fileRoutes
55
- .sort((a, b) => a.path.length - b.path.length)
56
- .reduce((prevRoutes: Route[], route) => {
57
- return processRoute(prevRoutes, route, route.path, route.path);
58
- }, []);
47
+ return fileRoutes
48
+ .sort((a, b) => a.path.length - b.path.length)
49
+ .reduce((prevRoutes: Route[], route) => {
50
+ return processRoute(prevRoutes, route, route.path, route.path);
51
+ }, []);
59
52
  }
60
53
 
61
54
  const router = createRouter({
62
- routes: (fileRoutes as unknown as Route[]).reduce(
63
- (memo, route) => {
64
- if (!containsHTTP(route)) return memo;
65
- const path = route.path
66
- .replace(/\([^)/]+\)/g, "")
67
- .replace(/\/+/g, "/")
68
- .replace(/\*([^/]*)/g, (_, m) => `**:${m}`)
69
- .split("/")
70
- .map((s) =>
71
- s.startsWith(":") || s.startsWith("*") ? s : encodeURIComponent(s),
72
- )
73
- .join("/");
74
- if (/:[^/]*\?/g.test(path)) {
75
- throw new Error(
76
- `Optional parameters are not supported in API routes: ${path}`,
77
- );
78
- }
79
- if (memo[path]) {
80
- throw new Error(
81
- `Duplicate API routes for "${path}" found at "${memo[path]!.route.path}" and "${
82
- route.path
83
- }"`,
84
- );
85
- }
86
- memo[path] = { route };
87
- return memo;
88
- },
89
- {} as Record<string, { route: Route }>,
90
- ),
55
+ routes: (fileRoutes as unknown as Route[]).reduce(
56
+ (memo, route) => {
57
+ if (!containsHTTP(route)) return memo;
58
+ const path = route.path
59
+ .replace(/\([^)/]+\)/g, "")
60
+ .replace(/\/+/g, "/")
61
+ .replace(/\*([^/]*)/g, (_, m) => `**:${m}`)
62
+ .split("/")
63
+ .map(s => (s.startsWith(":") || s.startsWith("*") ? s : encodeURIComponent(s)))
64
+ .join("/");
65
+ if (/:[^/]*\?/g.test(path)) {
66
+ throw new Error(`Optional parameters are not supported in API routes: ${path}`);
67
+ }
68
+ if (memo[path]) {
69
+ throw new Error(
70
+ `Duplicate API routes for "${path}" found at "${memo[path]!.route.path}" and "${
71
+ route.path
72
+ }"`,
73
+ );
74
+ }
75
+ memo[path] = { route };
76
+ return memo;
77
+ },
78
+ {} as Record<string, { route: Route }>,
79
+ ),
91
80
  });
92
81
 
93
82
  function containsHTTP(route: Route) {
94
- return (
95
- route["$HEAD"] ||
96
- route["$GET"] ||
97
- route["$POST"] ||
98
- route["$PUT"] ||
99
- route["$PATCH"] ||
100
- route["$DELETE"]
101
- );
83
+ return (
84
+ route["$HEAD"] ||
85
+ route["$GET"] ||
86
+ route["$POST"] ||
87
+ route["$PUT"] ||
88
+ route["$PATCH"] ||
89
+ route["$DELETE"]
90
+ );
102
91
  }
103
92
 
104
93
  export function matchAPIRoute(
105
- path: string,
106
- method: string,
94
+ path: string,
95
+ method: string,
107
96
  ):
108
- | {
109
- params?: Record<string, any>;
110
- handler: {
111
- import: () => Promise<Record<string, (e: FetchEvent) => Promise<any>>>;
112
- };
113
- isPage: boolean;
114
- }
115
- | undefined {
116
- const match = router.lookup(path);
117
- if (match && match.route) {
118
- const route = match.route;
97
+ | {
98
+ params?: Record<string, any>;
99
+ handler: {
100
+ import: () => Promise<Record<string, (e: FetchEvent) => Promise<any>>>;
101
+ };
102
+ isPage: boolean;
103
+ }
104
+ | undefined {
105
+ const match = router.lookup(path);
106
+ if (match && match.route) {
107
+ const route = match.route;
119
108
 
120
- // Find the appropriate handler for the HTTP method
121
- const handler =
122
- method === "HEAD" ? route.$HEAD || route.$GET : route[`$${method}`];
109
+ // Find the appropriate handler for the HTTP method
110
+ const handler = method === "HEAD" ? route.$HEAD || route.$GET : route[`$${method}`];
123
111
 
124
- if (handler === undefined) return;
112
+ if (handler === undefined) return;
125
113
 
126
- // Check if this is a page route
127
- const isPage = route.page === true && route.$component !== undefined;
114
+ // Check if this is a page route
115
+ const isPage = route.page === true && route.$component !== undefined;
128
116
 
129
- // Return comprehensive route information
130
- return {
131
- handler,
132
- params: match.params,
133
- isPage,
134
- };
135
- }
117
+ // Return comprehensive route information
118
+ return {
119
+ handler,
120
+ params: match.params,
121
+ isPage,
122
+ };
123
+ }
136
124
 
137
- return undefined;
125
+ return undefined;
138
126
  }
@@ -5,7 +5,7 @@ export function createServerReference(fn: Function, id: string) {
5
5
  if (typeof fn !== "function")
6
6
  throw new Error("Export from a 'use server' module must be a function");
7
7
  let baseURL = import.meta.env.BASE_URL ?? "/";
8
- if(!baseURL.endsWith("/")) baseURL += "/"
8
+ if (!baseURL.endsWith("/")) baseURL += "/";
9
9
 
10
10
  return new Proxy(fn, {
11
11
  get(target, prop, receiver) {
@@ -20,12 +20,12 @@ export function createServerReference(fn: Function, id: string) {
20
20
  if (!ogEvt) throw new Error("Cannot call server function outside of a request");
21
21
  const evt = { ...ogEvt };
22
22
  evt.locals.serverFunctionMeta = {
23
- id
23
+ id,
24
24
  };
25
25
  evt.serverOnly = true;
26
26
  return provideRequestEvent(evt, () => {
27
27
  return fn.apply(thisArg, args);
28
28
  });
29
- }
29
+ },
30
30
  });
31
31
  }