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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/client/StartClient.d.ts +7 -0
  3. package/{src/client/StartClient.tsx → dist/client/StartClient.jsx} +7 -15
  4. package/dist/client/index.jsx +2 -0
  5. package/dist/client/mount.d.ts +1 -0
  6. package/dist/client/mount.js +1 -0
  7. package/dist/client/spa/index.d.ts +4 -0
  8. package/dist/client/spa/index.jsx +5 -0
  9. package/dist/config/constants.d.ts +16 -0
  10. package/dist/config/constants.js +16 -0
  11. package/dist/config/dev-server.d.ts +2 -0
  12. package/dist/config/dev-server.js +128 -0
  13. package/dist/config/env.d.ts +19 -0
  14. package/dist/config/env.js +81 -0
  15. package/dist/config/fs-router.d.ts +37 -0
  16. package/dist/config/fs-router.js +141 -0
  17. package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
  18. package/dist/config/fs-routes/fs-watcher.js +53 -0
  19. package/dist/config/fs-routes/index.d.ts +7 -0
  20. package/dist/config/fs-routes/index.js +107 -0
  21. package/dist/config/fs-routes/router.d.ts +42 -0
  22. package/dist/config/fs-routes/router.js +148 -0
  23. package/dist/config/fs-routes/tree-shake.d.ts +2 -0
  24. package/dist/config/fs-routes/tree-shake.js +305 -0
  25. package/dist/config/index.d.ts +25 -0
  26. package/dist/config/index.js +217 -0
  27. package/dist/config/lazy.d.ts +3 -0
  28. package/dist/config/lazy.js +114 -0
  29. package/dist/config/manifest.d.ts +3 -0
  30. package/dist/config/manifest.js +109 -0
  31. package/dist/config/utils.d.ts +4 -0
  32. package/dist/config/utils.js +6 -0
  33. package/dist/config/vite-utils.d.ts +21 -0
  34. package/dist/config/vite-utils.js +85 -0
  35. package/dist/directives/bubble-function-declaration.d.ts +3 -0
  36. package/dist/directives/bubble-function-declaration.js +23 -0
  37. package/dist/directives/compile.d.ts +9 -0
  38. package/dist/directives/compile.js +40 -0
  39. package/dist/directives/generate-unique-name.d.ts +3 -0
  40. package/dist/directives/generate-unique-name.js +16 -0
  41. package/dist/directives/get-descriptive-name.d.ts +2 -0
  42. package/dist/directives/get-descriptive-name.js +37 -0
  43. package/dist/directives/get-import-identifier.d.ts +4 -0
  44. package/dist/directives/get-import-identifier.js +19 -0
  45. package/dist/directives/get-root-statement-path.d.ts +2 -0
  46. package/dist/directives/get-root-statement-path.js +12 -0
  47. package/dist/directives/index.d.ts +14 -0
  48. package/dist/directives/index.js +170 -0
  49. package/dist/directives/is-statement-top-level.d.ts +3 -0
  50. package/dist/directives/is-statement-top-level.js +9 -0
  51. package/dist/directives/paths.d.ts +9 -0
  52. package/dist/directives/paths.js +36 -0
  53. package/dist/directives/plugin.d.ts +21 -0
  54. package/dist/directives/plugin.js +302 -0
  55. package/dist/directives/remove-unused-variables.d.ts +3 -0
  56. package/dist/directives/remove-unused-variables.js +66 -0
  57. package/{src/directives/types.ts → dist/directives/types.d.ts} +5 -7
  58. package/dist/directives/types.js +1 -0
  59. package/dist/directives/xxhash32.d.ts +6 -0
  60. package/dist/directives/xxhash32.js +193 -0
  61. package/dist/fns/client.d.ts +3 -0
  62. package/dist/fns/client.js +106 -0
  63. package/dist/fns/handler.d.ts +5 -0
  64. package/dist/fns/handler.js +269 -0
  65. package/dist/fns/registration.d.ts +2 -0
  66. package/dist/fns/registration.js +12 -0
  67. package/dist/fns/serialization.d.ts +6 -0
  68. package/dist/fns/serialization.js +208 -0
  69. package/dist/fns/server.d.ts +7 -0
  70. package/dist/fns/server.js +38 -0
  71. package/dist/fns/shared.d.ts +17 -0
  72. package/dist/fns/shared.js +105 -0
  73. package/dist/http/index.d.ts +81 -0
  74. package/dist/http/index.js +129 -0
  75. package/{src/index.tsx → dist/index.d.ts} +0 -2
  76. package/dist/index.jsx +6 -0
  77. package/dist/middleware/index.d.ts +38 -0
  78. package/dist/middleware/index.js +59 -0
  79. package/dist/router.d.ts +6 -0
  80. package/dist/router.jsx +29 -0
  81. package/dist/server/StartServer.d.ts +9 -0
  82. package/dist/server/StartServer.jsx +34 -0
  83. package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
  84. package/{src/server/assets/PatchVirtualDevStyles.tsx → dist/server/assets/PatchVirtualDevStyles.jsx} +7 -10
  85. package/dist/server/assets/index.d.ts +2 -0
  86. package/dist/server/assets/index.js +52 -0
  87. package/dist/server/assets/render.d.ts +19 -0
  88. package/dist/server/assets/render.jsx +14 -0
  89. package/dist/server/collect-styles.d.ts +3 -0
  90. package/dist/server/collect-styles.js +57 -0
  91. package/dist/server/fetchEvent.d.ts +7 -0
  92. package/dist/server/fetchEvent.js +26 -0
  93. package/dist/server/handler.d.ts +64 -0
  94. package/dist/server/handler.js +222 -0
  95. package/dist/server/index.d.ts +9 -0
  96. package/{src/server/index.tsx → dist/server/index.jsx} +4 -19
  97. package/dist/server/manifest/client-manifest.d.ts +9 -0
  98. package/dist/server/manifest/client-manifest.js +6 -0
  99. package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
  100. package/dist/server/manifest/dev-client-manifest.js +24 -0
  101. package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
  102. package/dist/server/manifest/dev-ssr-manifest.js +23 -0
  103. package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
  104. package/dist/server/manifest/prod-client-manifest.js +26 -0
  105. package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
  106. package/dist/server/manifest/prod-ssr-manifest.js +85 -0
  107. package/dist/server/manifest/ssr-manifest.d.ts +4 -0
  108. package/dist/server/manifest/ssr-manifest.js +6 -0
  109. package/dist/server/routes.d.ts +23 -0
  110. package/dist/server/routes.js +74 -0
  111. package/dist/server/spa/StartServer.d.ts +9 -0
  112. package/dist/server/spa/StartServer.jsx +25 -0
  113. package/dist/server/spa/handler.d.ts +36 -0
  114. package/dist/server/spa/handler.js +20 -0
  115. package/{src/server/spa/index.tsx → dist/server/spa/index.d.ts} +0 -1
  116. package/dist/server/spa/index.jsx +5 -0
  117. package/dist/server/types.d.ts +75 -0
  118. package/dist/server/types.js +1 -0
  119. package/dist/server/util.d.ts +2 -0
  120. package/dist/server/util.js +8 -0
  121. package/dist/shared/ErrorBoundary.d.ts +3 -0
  122. package/dist/shared/ErrorBoundary.jsx +36 -0
  123. package/dist/shared/GET.d.ts +5 -0
  124. package/dist/shared/GET.js +8 -0
  125. package/dist/shared/HttpHeader.d.ts +10 -0
  126. package/dist/shared/HttpHeader.jsx +38 -0
  127. package/dist/shared/HttpStatusCode.d.ts +9 -0
  128. package/dist/shared/HttpStatusCode.js +18 -0
  129. package/dist/shared/clientOnly.d.ts +12 -0
  130. package/dist/shared/clientOnly.js +27 -0
  131. package/dist/shared/dev-overlay/CodeView.d.ts +7 -0
  132. package/dist/shared/dev-overlay/CodeView.jsx +62 -0
  133. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +9 -0
  134. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +226 -0
  135. package/dist/shared/dev-overlay/createStackFrame.d.ts +9 -0
  136. package/dist/shared/dev-overlay/createStackFrame.js +56 -0
  137. package/dist/shared/dev-overlay/download.d.ts +1 -0
  138. package/dist/shared/dev-overlay/download.js +6 -0
  139. package/dist/shared/dev-overlay/get-source-map.d.ts +2 -0
  140. package/dist/shared/dev-overlay/get-source-map.js +25 -0
  141. package/dist/shared/dev-overlay/icons.d.ts +28 -0
  142. package/dist/shared/dev-overlay/icons.jsx +150 -0
  143. package/dist/shared/dev-overlay/index.d.ts +5 -0
  144. package/dist/shared/dev-overlay/index.jsx +39 -0
  145. package/dist/shared/lazy.d.ts +3 -0
  146. package/dist/shared/lazy.js +42 -0
  147. package/dist/shared/serverFunction.d.ts +6 -0
  148. package/dist/shared/serverFunction.js +8 -0
  149. package/dist/utils/debounce.d.ts +4 -0
  150. package/dist/utils/debounce.js +10 -0
  151. package/package.json +7 -2
  152. package/scripts/build.js +0 -15
  153. package/scripts/validate-imports.js +0 -316
  154. package/src/client/mount.ts +0 -1
  155. package/src/client/spa/index.tsx +0 -9
  156. package/src/config/constants.ts +0 -19
  157. package/src/config/dev-server.ts +0 -161
  158. package/src/config/env.ts +0 -105
  159. package/src/config/fs-router.ts +0 -162
  160. package/src/config/fs-routes/fs-watcher.ts +0 -66
  161. package/src/config/fs-routes/index.ts +0 -136
  162. package/src/config/fs-routes/router.ts +0 -184
  163. package/src/config/fs-routes/tree-shake.ts +0 -324
  164. package/src/config/index.ts +0 -239
  165. package/src/config/lazy.ts +0 -132
  166. package/src/config/manifest.ts +0 -120
  167. package/src/config/utils.ts +0 -5
  168. package/src/config/vite-utils.ts +0 -113
  169. package/src/directives/bubble-function-declaration.ts +0 -33
  170. package/src/directives/compile.ts +0 -54
  171. package/src/directives/generate-unique-name.ts +0 -22
  172. package/src/directives/get-descriptive-name.ts +0 -39
  173. package/src/directives/get-import-identifier.ts +0 -34
  174. package/src/directives/get-root-statement-path.ts +0 -14
  175. package/src/directives/index.ts +0 -233
  176. package/src/directives/is-statement-top-level.ts +0 -13
  177. package/src/directives/paths.ts +0 -63
  178. package/src/directives/plugin.ts +0 -389
  179. package/src/directives/remove-unused-variables.ts +0 -70
  180. package/src/directives/xxhash32.ts +0 -214
  181. package/src/env.d.ts +0 -17
  182. package/src/fns/client.ts +0 -141
  183. package/src/fns/handler.spec.ts +0 -85
  184. package/src/fns/handler.ts +0 -287
  185. package/src/fns/registration.ts +0 -19
  186. package/src/fns/serialization.ts +0 -250
  187. package/src/fns/server.ts +0 -46
  188. package/src/fns/shared.ts +0 -116
  189. package/src/http/index.ts +0 -216
  190. package/src/internal.d.ts +0 -14
  191. package/src/middleware/index.ts +0 -92
  192. package/src/router.tsx +0 -37
  193. package/src/server/StartServer.tsx +0 -58
  194. package/src/server/assets/index.ts +0 -70
  195. package/src/server/assets/render.tsx +0 -46
  196. package/src/server/collect-styles.ts +0 -70
  197. package/src/server/fetchEvent.spec.ts +0 -85
  198. package/src/server/fetchEvent.ts +0 -36
  199. package/src/server/handler.ts +0 -261
  200. package/src/server/manifest/client-manifest.ts +0 -8
  201. package/src/server/manifest/dev-client-manifest.ts +0 -21
  202. package/src/server/manifest/dev-ssr-manifest.ts +0 -23
  203. package/src/server/manifest/prod-client-manifest.ts +0 -21
  204. package/src/server/manifest/prod-ssr-manifest.ts +0 -109
  205. package/src/server/manifest/ssr-manifest.ts +0 -10
  206. package/src/server/routes.ts +0 -126
  207. package/src/server/spa/StartServer.tsx +0 -42
  208. package/src/server/spa/handler.ts +0 -29
  209. package/src/server/types.ts +0 -82
  210. package/src/server/util.ts +0 -12
  211. package/src/shared/ErrorBoundary.tsx +0 -52
  212. package/src/shared/GET.ts +0 -8
  213. package/src/shared/HttpHeader.tsx +0 -42
  214. package/src/shared/HttpStatusCode.ts +0 -27
  215. package/src/shared/clientOnly.ts +0 -44
  216. package/src/shared/dev-overlay/CodeView.tsx +0 -90
  217. package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
  218. package/src/shared/dev-overlay/createStackFrame.ts +0 -74
  219. package/src/shared/dev-overlay/download.ts +0 -6
  220. package/src/shared/dev-overlay/env.d.ts +0 -4
  221. package/src/shared/dev-overlay/get-source-map.ts +0 -33
  222. package/src/shared/dev-overlay/icons.tsx +0 -456
  223. package/src/shared/dev-overlay/index.tsx +0 -63
  224. package/src/shared/lazy.ts +0 -52
  225. package/src/shared/serverFunction.ts +0 -10
  226. package/src/utils/debounce.ts +0 -10
  227. package/src/virtual.d.ts +0 -27
  228. package/tsconfig.json +0 -24
  229. package/vitest.config.ts +0 -9
  230. /package/{src/client/index.tsx → dist/client/index.d.ts} +0 -0
  231. /package/{src → dist}/shared/dev-overlay/styles.css +0 -0
@@ -1,54 +0,0 @@
1
- import * as babel from "@babel/core";
2
- import path from "node:path";
3
- import { directivesPlugin, type StateContext } from "./plugin.ts";
4
- import xxHash32 from "./xxhash32.ts";
5
-
6
- export interface CompileResult {
7
- valid: boolean;
8
- code: string;
9
- map: babel.BabelFileResult["map"];
10
- }
11
-
12
- export type CompileOptions = Omit<StateContext, "count" | "hash" | "imports" | "valid">;
13
-
14
- export async function compile(
15
- id: string,
16
- code: string,
17
- options: CompileOptions,
18
- ): Promise<CompileResult> {
19
- const context: StateContext = {
20
- ...options,
21
- valid: false,
22
- hash: xxHash32(id).toString(16),
23
- count: 0,
24
- imports: new Map(),
25
- };
26
- const pluginOption = [directivesPlugin, context];
27
- const plugins: NonNullable<NonNullable<babel.TransformOptions["parserOpts"]>["plugins"]> = [
28
- "jsx",
29
- ];
30
- if (/\.[mc]?tsx?$/i.test(id)) {
31
- plugins.push("typescript");
32
- }
33
- const result = await babel.transformAsync(code, {
34
- plugins: [pluginOption],
35
- parserOpts: {
36
- plugins,
37
- },
38
- filename: path.basename(id),
39
- ast: false,
40
- sourceMaps: true,
41
- configFile: false,
42
- babelrc: false,
43
- sourceFileName: id,
44
- });
45
-
46
- if (result) {
47
- return {
48
- valid: context.valid,
49
- code: result.code || "",
50
- map: result.map,
51
- };
52
- }
53
- throw new Error("invariant");
54
- }
@@ -1,22 +0,0 @@
1
- import type * as babel from "@babel/core";
2
- import * as t from "@babel/types";
3
-
4
- export function generateUniqueName(path: babel.NodePath, name: string): t.Identifier {
5
- let uid: string;
6
- let i = 1;
7
- do {
8
- uid = name + "_" + i;
9
- i++;
10
- } while (
11
- path.scope.hasLabel(uid) ||
12
- path.scope.hasBinding(uid) ||
13
- path.scope.hasGlobal(uid) ||
14
- path.scope.hasReference(uid)
15
- );
16
-
17
- const program = path.scope.getProgramParent();
18
- program.references[uid] = true;
19
- program.uids[uid] = true;
20
-
21
- return t.identifier(uid);
22
- }
@@ -1,39 +0,0 @@
1
- import type { NodePath } from "@babel/core";
2
-
3
- export function getDescriptiveName(path: NodePath, defaultName: string): string {
4
- let current: NodePath | null = path;
5
- while (current) {
6
- switch (current.node.type) {
7
- case "FunctionDeclaration":
8
- case "FunctionExpression": {
9
- if (current.node.id) {
10
- return current.node.id.name;
11
- }
12
- break;
13
- }
14
- case "VariableDeclarator": {
15
- if (current.node.id.type === "Identifier") {
16
- return current.node.id.name;
17
- }
18
- break;
19
- }
20
- case "ClassPrivateMethod":
21
- case "ClassMethod":
22
- case "ObjectMethod": {
23
- switch (current.node.key.type) {
24
- case "Identifier":
25
- return current.node.key.name;
26
- case "PrivateName":
27
- return current.node.key.id.name;
28
- default:
29
- break;
30
- }
31
- break;
32
- }
33
- default:
34
- break;
35
- }
36
- current = current.parentPath;
37
- }
38
- return defaultName;
39
- }
@@ -1,34 +0,0 @@
1
- import type * as babel from "@babel/core";
2
- import * as t from "@babel/types";
3
- import { generateUniqueName } from "./generate-unique-name.ts";
4
- import type { ImportDefinition } from "./types.ts";
5
-
6
- export function getImportIdentifier(
7
- imports: Map<string, t.Identifier>,
8
- path: babel.NodePath,
9
- registration: ImportDefinition,
10
- ): t.Identifier {
11
- const name = registration.kind === "named" ? registration.name : "default";
12
- const target = `${registration.source}[${name}]`;
13
- const current = imports.get(target);
14
- if (current) {
15
- return current;
16
- }
17
- const programParent = path.scope.getProgramParent();
18
- const uid = generateUniqueName(programParent.path, name);
19
- programParent.registerDeclaration(
20
- (programParent.path as babel.NodePath<t.Program>).unshiftContainer(
21
- "body",
22
- t.importDeclaration(
23
- [
24
- registration.kind === "named"
25
- ? t.importSpecifier(uid, t.identifier(registration.name))
26
- : t.importDefaultSpecifier(uid),
27
- ],
28
- t.stringLiteral(registration.source),
29
- ),
30
- )[0],
31
- );
32
- imports.set(target, uid);
33
- return uid;
34
- }
@@ -1,14 +0,0 @@
1
- import type * as babel from "@babel/core";
2
- import * as t from "@babel/types";
3
-
4
- export function getRootStatementPath(path: babel.NodePath): babel.NodePath {
5
- let current = path.parentPath;
6
- while (current) {
7
- const next = current.parentPath;
8
- if (next && t.isProgram(next.node)) {
9
- return current;
10
- }
11
- current = next;
12
- }
13
- return path;
14
- }
@@ -1,233 +0,0 @@
1
- import {
2
- createFilter,
3
- type EnvironmentModuleGraph,
4
- type FilterPattern,
5
- type Plugin,
6
- type ViteDevServer,
7
- } from "vite";
8
- import { compile, type CompileOptions } from "./compile.ts";
9
-
10
- export interface ServerFunctionsFilter {
11
- include?: FilterPattern;
12
- exclude?: FilterPattern;
13
- }
14
-
15
- export interface ServerFunctionsOptions {
16
- manifest: string;
17
- runtime: {
18
- server: string;
19
- client: string;
20
- };
21
- filter?: ServerFunctionsFilter;
22
- }
23
-
24
- const DEFAULT_INCLUDE = "src/**/*.{jsx,tsx,ts,js,mjs,cjs}";
25
- const DEFAULT_EXCLUDE = "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}";
26
- const DIRECTIVE = "use server";
27
-
28
- type Manifest = Record<CompileOptions["mode"], Set<string>>;
29
-
30
- function createManifest(): Manifest {
31
- return {
32
- server: new Set(),
33
- client: new Set(),
34
- };
35
- }
36
-
37
- interface DeferredPromise<T> {
38
- reference: Promise<T>;
39
- resolve: (value: T) => void;
40
- reject: (value: any) => void;
41
- }
42
-
43
- function createDeferredPromise<T>(): DeferredPromise<T> {
44
- let resolve: DeferredPromise<T>["resolve"];
45
- let reject: DeferredPromise<T>["reject"];
46
-
47
- return {
48
- reference: new Promise((res, rej) => {
49
- resolve = res;
50
- reject = rej;
51
- }),
52
- resolve(value) {
53
- resolve(value);
54
- },
55
- reject(value) {
56
- reject(value);
57
- },
58
- };
59
- }
60
-
61
- class Debouncer<T> {
62
- promise: DeferredPromise<T>;
63
-
64
- private timeout: ReturnType<typeof setTimeout> | undefined;
65
-
66
- constructor(private source: () => T) {
67
- this.promise = createDeferredPromise();
68
- this.defer();
69
- }
70
-
71
- defer(): void {
72
- if (this.timeout) {
73
- clearTimeout(this.timeout);
74
- this.timeout = undefined;
75
- }
76
- this.timeout = setTimeout(() => {
77
- this.promise.resolve(this.source());
78
- }, 1000);
79
- }
80
- }
81
-
82
- function mergeManifestRecord(
83
- source: Set<string>,
84
- target: Set<string>,
85
- ): { invalidPreload: boolean; invalidated: string[] } {
86
- const current = source.size;
87
- for (const entry of target) {
88
- source.add(entry);
89
- }
90
- return {
91
- invalidPreload: current !== source.size,
92
- invalidated: [...source],
93
- };
94
- }
95
-
96
- function invalidateModule(moduleGraph: EnvironmentModuleGraph, path: string) {
97
- const target = moduleGraph.getModuleById(path);
98
- if (target) {
99
- moduleGraph.invalidateModule(target);
100
- }
101
- }
102
-
103
- function invalidateModules(
104
- server: ViteDevServer | undefined,
105
- result: ReturnType<typeof mergeManifestRecord>,
106
- manifest: string,
107
- ): void {
108
- if (server) {
109
- if (result.invalidPreload) {
110
- invalidateModule(server.environments.client.moduleGraph, manifest);
111
- invalidateModule(server.environments.ssr.moduleGraph, manifest);
112
- }
113
- }
114
- }
115
-
116
-
117
- export function serverFunctionsPlugin(options: ServerFunctionsOptions): Plugin[] {
118
- const filter = createFilter(
119
- options.filter?.include || DEFAULT_INCLUDE,
120
- options.filter?.exclude || DEFAULT_EXCLUDE,
121
- );
122
-
123
- let env: CompileOptions["env"];
124
-
125
- const manifest = createManifest();
126
-
127
- const preload: Record<CompileOptions["mode"], Debouncer<string> | undefined> = {
128
- server: undefined,
129
- client: undefined,
130
- };
131
- let currentServer: ViteDevServer;
132
-
133
- const clientOptions: Pick<CompileOptions, "directive" | "definitions"> = {
134
- directive: DIRECTIVE,
135
- definitions: {
136
- register: {
137
- kind: "named",
138
- name: "createServerReference",
139
- source: options.runtime.client,
140
- },
141
- clone: {
142
- kind: "named",
143
- name: "cloneServerReference",
144
- source: options.runtime.client,
145
- },
146
- },
147
- };
148
- const serverOptions: Pick<CompileOptions, "directive" | "definitions"> = {
149
- directive: DIRECTIVE,
150
- definitions: {
151
- register: {
152
- kind: "named",
153
- name: "createServerReference",
154
- source: options.runtime.server,
155
- },
156
- clone: {
157
- kind: "named",
158
- name: "cloneServerReference",
159
- source: options.runtime.server,
160
- },
161
- },
162
- };
163
-
164
- return [
165
- {
166
- name: "solid-start:server-functions/setup",
167
- enforce: "pre",
168
- configResolved(config) {
169
- env = config.mode !== "production" ? "development" : "production";
170
- },
171
- configureServer(server) {
172
- currentServer = server;
173
- },
174
- },
175
- {
176
- name: "solid-start:server-functions/preload",
177
- enforce: "pre",
178
- resolveId(source) {
179
- if (source === options.manifest) {
180
- return { id: options.manifest, moduleSideEffects: true };
181
- }
182
- return null;
183
- },
184
- async load(id, opts) {
185
- const mode = opts?.ssr ? "server" : "client";
186
- if (id === options.manifest) {
187
- const current = new Debouncer(() =>
188
- [...manifest[mode]].map(entry => `import "${entry}";`).join("\n"),
189
- );
190
- preload[mode] = current;
191
- const result = await current.promise.reference;
192
- return result;
193
- }
194
- return null;
195
- },
196
- },
197
- {
198
- name: "solid-start:server-functions/compiler",
199
- enforce: 'pre',
200
- async transform(code, fileId, opts) {
201
- const mode = opts?.ssr ? "server" : "client";
202
- const [id] = fileId.split("?");
203
- if (!filter(id)) {
204
- return null;
205
- }
206
-
207
- const result = await compile(id!, code, {
208
- ...(mode === "server" ? serverOptions : clientOptions),
209
- mode,
210
- env,
211
- });
212
-
213
- if (result.valid) {
214
- const preloader = preload[mode];
215
- if (preloader) {
216
- preloader.defer();
217
- }
218
- invalidateModules(
219
- currentServer,
220
- mergeManifestRecord(manifest.server, new Set([id!])),
221
- options.manifest,
222
- );
223
-
224
- return {
225
- code: result.code || "",
226
- map: result.map,
227
- };
228
- }
229
- return null;
230
- },
231
- },
232
- ];
233
- }
@@ -1,13 +0,0 @@
1
- import type * as babel from "@babel/core";
2
- import type * as t from "@babel/types";
3
-
4
- export function isStatementTopLevel(path: babel.NodePath<t.Statement>): boolean {
5
- let blockParent = path.scope.getBlockParent();
6
- const programParent = path.scope.getProgramParent();
7
- // a FunctionDeclaration binding refers to itself as the block parent
8
- if (blockParent.path === path) {
9
- blockParent = blockParent.parent;
10
- }
11
-
12
- return programParent === blockParent;
13
- }
@@ -1,63 +0,0 @@
1
- import type * as t from "@babel/types";
2
-
3
- type TypeFilter<V extends t.Node> = (node: t.Node) => node is V;
4
-
5
- export function isPathValid<V extends t.Node>(
6
- path: unknown,
7
- key: TypeFilter<V>,
8
- ): path is babel.NodePath<V> {
9
- const node = (path as babel.NodePath).node;
10
- return node ? key(node) : false;
11
- }
12
-
13
- export type NestedExpression =
14
- | t.ParenthesizedExpression
15
- | t.TypeCastExpression
16
- | t.TSAsExpression
17
- | t.TSSatisfiesExpression
18
- | t.TSNonNullExpression
19
- | t.TSInstantiationExpression
20
- | t.TSTypeAssertion;
21
-
22
- export function isNestedExpression(node: t.Node): node is NestedExpression {
23
- switch (node.type) {
24
- case "ParenthesizedExpression":
25
- case "TypeCastExpression":
26
- case "TSAsExpression":
27
- case "TSSatisfiesExpression":
28
- case "TSNonNullExpression":
29
- case "TSTypeAssertion":
30
- case "TSInstantiationExpression":
31
- return true;
32
- default:
33
- return false;
34
- }
35
- }
36
-
37
- type TypeCheck<K> = K extends TypeFilter<infer U> ? U : never;
38
-
39
- export function unwrapNode<K extends (value: t.Node) => boolean>(
40
- node: t.Node,
41
- key: K,
42
- ): TypeCheck<K> | undefined {
43
- if (key(node)) {
44
- return node as TypeCheck<K>;
45
- }
46
- if (isNestedExpression(node)) {
47
- return unwrapNode(node.expression, key);
48
- }
49
- return undefined;
50
- }
51
-
52
- export function unwrapPath<V extends t.Node>(
53
- path: unknown,
54
- key: TypeFilter<V>,
55
- ): babel.NodePath<V> | undefined {
56
- if (isPathValid(path, key)) {
57
- return path;
58
- }
59
- if (isPathValid(path, isNestedExpression)) {
60
- return unwrapPath(path.get("expression"), key);
61
- }
62
- return undefined;
63
- }