@solidjs/start 1.1.7 → 2.0.0-alpha.0

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 (185) hide show
  1. package/README.md +88 -8
  2. package/dist/client/StartClient.d.ts +0 -1
  3. package/dist/client/StartClient.jsx +2 -4
  4. package/dist/client/index.d.ts +2 -3
  5. package/dist/client/index.jsx +2 -4
  6. package/dist/client/mount.js +10 -2
  7. package/dist/client/spa/index.d.ts +1 -2
  8. package/dist/client/spa/index.jsx +1 -2
  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 +108 -0
  13. package/dist/config/fs-router.d.ts +37 -0
  14. package/dist/config/fs-router.js +153 -0
  15. package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
  16. package/dist/config/fs-routes/fs-watcher.js +49 -0
  17. package/dist/config/fs-routes/index.d.ts +7 -0
  18. package/dist/config/fs-routes/index.js +109 -0
  19. package/dist/config/fs-routes/router.d.ts +37 -0
  20. package/dist/config/fs-routes/router.js +136 -0
  21. package/dist/config/fs-routes/tree-shake.d.ts +2 -0
  22. package/dist/config/fs-routes/tree-shake.js +357 -0
  23. package/dist/config/index.d.ts +10 -0
  24. package/dist/config/index.js +217 -0
  25. package/dist/config/lazy.d.ts +3 -0
  26. package/dist/config/lazy.js +82 -0
  27. package/dist/config/manifest.d.ts +3 -0
  28. package/dist/config/manifest.js +74 -0
  29. package/dist/config/utils.d.ts +4 -0
  30. package/dist/config/utils.js +6 -0
  31. package/dist/config/vite-utils.d.ts +16 -0
  32. package/dist/config/vite-utils.js +81 -0
  33. package/dist/http/index.d.ts +84 -0
  34. package/dist/http/index.js +131 -0
  35. package/dist/index.d.ts +6 -5
  36. package/dist/index.jsx +5 -5
  37. package/dist/middleware/index.d.ts +6 -6
  38. package/dist/middleware/index.js +39 -0
  39. package/dist/{router/FileRoutes.js → router.jsx} +5 -6
  40. package/dist/server/StartServer.d.ts +3 -3
  41. package/dist/server/StartServer.jsx +9 -63
  42. package/dist/server/assets/index.d.ts +2 -0
  43. package/dist/server/assets/index.js +52 -0
  44. package/dist/server/assets/render.d.ts +19 -0
  45. package/dist/server/{renderAsset.jsx → assets/render.jsx} +1 -1
  46. package/dist/server/collect-styles.d.ts +3 -0
  47. package/dist/server/collect-styles.js +69 -0
  48. package/dist/server/fetchEvent.d.ts +4 -3
  49. package/dist/server/fetchEvent.js +12 -74
  50. package/dist/server/fetchEvent.spec.d.ts +1 -0
  51. package/dist/server/fetchEvent.spec.js +65 -0
  52. package/dist/server/handler.d.ts +6 -12
  53. package/dist/server/handler.js +180 -95
  54. package/dist/server/index.d.ts +8 -6
  55. package/dist/server/index.jsx +14 -6
  56. package/dist/server/manifest/client-manifest.d.ts +9 -0
  57. package/dist/server/manifest/client-manifest.js +6 -0
  58. package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
  59. package/dist/server/manifest/dev-client-manifest.js +24 -0
  60. package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
  61. package/dist/server/manifest/dev-ssr-manifest.js +23 -0
  62. package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
  63. package/dist/server/manifest/prod-client-manifest.js +26 -0
  64. package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
  65. package/dist/server/manifest/prod-ssr-manifest.js +90 -0
  66. package/dist/server/manifest/ssr-manifest.d.ts +4 -0
  67. package/dist/server/manifest/ssr-manifest.js +6 -0
  68. package/dist/{router → server}/routes.d.ts +6 -10
  69. package/dist/{router → server}/routes.js +35 -27
  70. package/dist/{runtime → server}/server-fns-runtime.d.ts +1 -1
  71. package/dist/{runtime → server}/server-fns-runtime.js +7 -6
  72. package/dist/server/server-functions-handler.d.ts +2 -0
  73. package/dist/{runtime/server-handler.js → server/server-functions-handler.js} +76 -103
  74. package/dist/server/server-runtime.d.ts +3 -0
  75. package/dist/{runtime → server}/server-runtime.js +9 -16
  76. package/dist/server/spa/StartServer.d.ts +1 -1
  77. package/dist/server/spa/StartServer.jsx +7 -9
  78. package/dist/server/spa/handler.d.ts +3 -3
  79. package/dist/server/spa/handler.js +9 -11
  80. package/dist/server/spa/index.d.ts +4 -3
  81. package/dist/server/spa/index.jsx +4 -3
  82. package/dist/server/types.d.ts +7 -9
  83. package/dist/server/util.d.ts +2 -0
  84. package/dist/server/util.js +8 -0
  85. package/dist/shared/ErrorBoundary.jsx +2 -2
  86. package/dist/shared/HttpHeader.jsx +4 -2
  87. package/dist/shared/{HttpStatusCode.jsx → HttpStatusCode.js} +3 -1
  88. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +2 -2
  89. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +75 -66
  90. package/dist/shared/dev-overlay/createStackFrame.js +3 -3
  91. package/dist/shared/dev-overlay/index.jsx +5 -8
  92. package/dist/shared/lazy.d.ts +3 -0
  93. package/dist/shared/lazy.js +40 -0
  94. package/dist/shared/serverFunction.d.ts +1 -1
  95. package/package.json +47 -65
  96. package/scripts/build.js +15 -0
  97. package/scripts/validate-imports.js +316 -0
  98. package/src/client/StartClient.tsx +34 -0
  99. package/src/client/index.tsx +2 -0
  100. package/src/client/mount.ts +114 -0
  101. package/src/client/spa/index.tsx +9 -0
  102. package/src/config/constants.ts +19 -0
  103. package/src/config/dev-server.ts +149 -0
  104. package/src/config/fs-router.ts +177 -0
  105. package/src/config/fs-routes/fs-watcher.ts +81 -0
  106. package/src/config/fs-routes/index.ts +138 -0
  107. package/src/config/fs-routes/router.ts +169 -0
  108. package/src/config/fs-routes/tree-shake.ts +392 -0
  109. package/src/config/index.ts +236 -0
  110. package/src/config/lazy.ts +100 -0
  111. package/src/config/manifest.ts +84 -0
  112. package/src/config/utils.ts +5 -0
  113. package/src/config/vite-utils.ts +113 -0
  114. package/src/env.d.ts +35 -0
  115. package/src/http/index.ts +253 -0
  116. package/src/index.tsx +19 -0
  117. package/src/internal.d.ts +14 -0
  118. package/src/middleware/index.ts +82 -0
  119. package/src/router.tsx +36 -0
  120. package/src/server/StartServer.tsx +62 -0
  121. package/src/server/assets/index.ts +70 -0
  122. package/src/server/assets/render.tsx +42 -0
  123. package/src/server/collect-styles.ts +94 -0
  124. package/src/server/fetchEvent.spec.ts +89 -0
  125. package/src/server/fetchEvent.ts +36 -0
  126. package/src/server/handler.ts +250 -0
  127. package/src/server/index.tsx +16 -0
  128. package/src/server/manifest/client-manifest.ts +8 -0
  129. package/src/server/manifest/dev-client-manifest.ts +19 -0
  130. package/src/server/manifest/dev-ssr-manifest.ts +21 -0
  131. package/src/server/manifest/prod-client-manifest.ts +18 -0
  132. package/src/server/manifest/prod-ssr-manifest.ts +125 -0
  133. package/src/server/manifest/ssr-manifest.ts +8 -0
  134. package/src/server/routes.ts +138 -0
  135. package/src/server/server-fns-runtime.ts +31 -0
  136. package/src/server/server-functions-handler.ts +364 -0
  137. package/src/server/server-runtime.ts +240 -0
  138. package/src/server/spa/StartServer.tsx +40 -0
  139. package/src/server/spa/handler.ts +29 -0
  140. package/src/server/spa/index.tsx +5 -0
  141. package/src/server/types.ts +82 -0
  142. package/src/server/util.ts +12 -0
  143. package/src/shared/ErrorBoundary.tsx +52 -0
  144. package/src/shared/GET.ts +8 -0
  145. package/src/shared/HttpHeader.tsx +42 -0
  146. package/src/shared/HttpStatusCode.ts +27 -0
  147. package/src/shared/clientOnly.ts +44 -0
  148. package/src/shared/dev-overlay/CodeView.tsx +95 -0
  149. package/src/shared/dev-overlay/DevOverlayDialog.tsx +316 -0
  150. package/src/shared/dev-overlay/createStackFrame.ts +77 -0
  151. package/src/shared/dev-overlay/download.ts +6 -0
  152. package/src/shared/dev-overlay/env.d.ts +4 -0
  153. package/src/shared/dev-overlay/get-source-map.ts +35 -0
  154. package/src/shared/dev-overlay/icons.tsx +288 -0
  155. package/src/shared/dev-overlay/index.tsx +63 -0
  156. package/src/shared/dev-overlay/styles.css +292 -0
  157. package/src/shared/lazy.ts +51 -0
  158. package/src/shared/serverFunction.ts +10 -0
  159. package/src/virtual.d.ts +27 -0
  160. package/tsconfig.json +23 -0
  161. package/vitest.config.ts +9 -0
  162. package/config/fs-router.js +0 -142
  163. package/config/index.d.ts +0 -39
  164. package/config/index.js +0 -303
  165. package/config/server-components.js +0 -106
  166. package/dist/client/islands.d.ts +0 -7
  167. package/dist/client/islands.jsx +0 -10
  168. package/dist/middleware/index.jsx +0 -35
  169. package/dist/router/index.d.ts +0 -1
  170. package/dist/router/index.jsx +0 -2
  171. package/dist/router/lazyRoute.d.ts +0 -6
  172. package/dist/router/lazyRoute.js +0 -53
  173. package/dist/runtime/server-handler.d.ts +0 -2
  174. package/dist/runtime/server-runtime.d.ts +0 -3
  175. package/dist/server/islands/index.d.ts +0 -19
  176. package/dist/server/islands/index.jsx +0 -62
  177. package/dist/server/islands/utils.d.ts +0 -1
  178. package/dist/server/islands/utils.jsx +0 -85
  179. package/dist/server/pageEvent.d.ts +0 -2
  180. package/dist/server/pageEvent.js +0 -56
  181. package/dist/server/renderAsset.d.ts +0 -2
  182. package/env.d.ts +0 -26
  183. /package/dist/{router/FileRoutes.d.ts → router.d.ts} +0 -0
  184. /package/dist/shared/{clientOnly.jsx → clientOnly.js} +0 -0
  185. /package/dist/shared/{serverFunction.jsx → serverFunction.js} +0 -0
@@ -0,0 +1,217 @@
1
+ import { TanStackServerFnPlugin } from "@tanstack/server-functions-plugin";
2
+ import { defu } from "defu";
3
+ import { globSync } from "node:fs";
4
+ import { extname, isAbsolute, join, normalize } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import solid from "vite-plugin-solid";
7
+ import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.js";
8
+ import { devServer } from "./dev-server.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
+ {
41
+ name: "solid-start:config",
42
+ enforce: "pre",
43
+ configEnvironment(name) {
44
+ return {
45
+ define: {
46
+ "import.meta.env.SSR": JSON.stringify(name === VITE_ENVIRONMENTS.server)
47
+ },
48
+ resolve: {
49
+ // remove when https://github.com/solidjs/vite-plugin-solid/pull/228 is released
50
+ externalConditions: ["solid", "node"]
51
+ }
52
+ };
53
+ },
54
+ async config(_, env) {
55
+ const clientInput = [handlers.client];
56
+ if (env.command === "build") {
57
+ const clientRouter = globalThis.ROUTERS.client;
58
+ for (const route of await clientRouter.getRoutes()) {
59
+ for (const [key, value] of Object.entries(route)) {
60
+ if (value && key.startsWith("$") && !key.startsWith("$$")) {
61
+ function toRouteId(route) {
62
+ return `${route.src}?${route.pick.map((p) => `pick=${p}`).join("&")}`;
63
+ }
64
+ clientInput.push(toRouteId(value));
65
+ }
66
+ }
67
+ }
68
+ }
69
+ return {
70
+ appType: "custom",
71
+ build: { assetsDir: "_build/assets" },
72
+ environments: {
73
+ [VITE_ENVIRONMENTS.client]: {
74
+ consumer: "client",
75
+ build: {
76
+ write: true,
77
+ manifest: true,
78
+ outDir: "dist/client",
79
+ rollupOptions: {
80
+ input: clientInput,
81
+ treeshake: true,
82
+ preserveEntrySignatures: "exports-only"
83
+ }
84
+ }
85
+ },
86
+ [VITE_ENVIRONMENTS.server]: {
87
+ consumer: "server",
88
+ build: {
89
+ ssr: true,
90
+ write: true,
91
+ manifest: true,
92
+ copyPublicDir: false,
93
+ rollupOptions: {
94
+ input: "~/entry-server.tsx"
95
+ },
96
+ outDir: "dist/server",
97
+ commonjsOptions: {
98
+ include: [/node_modules/]
99
+ }
100
+ }
101
+ }
102
+ },
103
+ resolve: {
104
+ alias: {
105
+ "@solidjs/start/server/entry": handlers.server,
106
+ "~": join(process.cwd(), start.appRoot),
107
+ ...(!start.ssr
108
+ ? {
109
+ "@solidjs/start/server": "@solidjs/start/server/spa",
110
+ "@solidjs/start/client": "@solidjs/start/client/spa"
111
+ }
112
+ : {})
113
+ }
114
+ },
115
+ define: {
116
+ "import.meta.env.MANIFEST": `globalThis.MANIFEST`,
117
+ "import.meta.env.START_SSR": JSON.stringify(start.ssr),
118
+ "import.meta.env.START_APP_ENTRY": `"${appEntryPath}"`,
119
+ "import.meta.env.START_CLIENT_ENTRY": `"${handlers.client}"`,
120
+ "import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay)
121
+ },
122
+ builder: {
123
+ sharedPlugins: true,
124
+ async buildApp(builder) {
125
+ const client = builder.environments[VITE_ENVIRONMENTS.client];
126
+ const server = builder.environments[VITE_ENVIRONMENTS.server];
127
+ if (!client)
128
+ throw new Error("Client environment not found");
129
+ if (!server)
130
+ throw new Error("SSR environment not found");
131
+ if (!client.isBuilt)
132
+ await builder.build(client);
133
+ if (!server.isBuilt)
134
+ await builder.build(server);
135
+ }
136
+ }
137
+ };
138
+ }
139
+ },
140
+ manifest(start),
141
+ fsRoutes({
142
+ routers: {
143
+ client: new SolidStartClientFileRouter({
144
+ dir: absolute(routeDir, root),
145
+ extensions
146
+ }),
147
+ ssr: new SolidStartServerFileRouter({
148
+ dir: absolute(routeDir, root),
149
+ extensions,
150
+ dataOnly: !start.ssr
151
+ })
152
+ }
153
+ }),
154
+ lazy(),
155
+ // Must be placed after fsRoutes, as treeShake will remove the
156
+ // server fn exports added in by this plugin
157
+ TanStackServerFnPlugin({
158
+ // This is the ID that will be available to look up and import
159
+ // our server function manifest and resolve its module
160
+ manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,
161
+ directive: "use server",
162
+ callers: [
163
+ {
164
+ envConsumer: "client",
165
+ envName: VITE_ENVIRONMENTS.client,
166
+ getRuntimeCode: () => `import { createServerReference } from "${normalize(fileURLToPath(new URL("../server/server-runtime", import.meta.url)))}"`,
167
+ replacer: opts => `createServerReference('${opts.functionId}')`
168
+ },
169
+ {
170
+ envConsumer: "server",
171
+ envName: VITE_ENVIRONMENTS.server,
172
+ getRuntimeCode: () => `import { createServerReference } from '${normalize(fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)))}'`,
173
+ replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`
174
+ }
175
+ ],
176
+ provider: {
177
+ envName: VITE_ENVIRONMENTS.server,
178
+ getRuntimeCode: () => `import { createServerReference } from '${normalize(fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)))}'`,
179
+ replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`
180
+ }
181
+ }),
182
+ {
183
+ name: "solid-start:virtual-modules",
184
+ async resolveId(id) {
185
+ const { filename, query } = parseIdQuery(id);
186
+ let base;
187
+ if (filename === VIRTUAL_MODULES.clientEntry)
188
+ base = handlers.client;
189
+ if (filename === VIRTUAL_MODULES.serverEntry)
190
+ base = handlers.server;
191
+ if (filename === VIRTUAL_MODULES.app)
192
+ base = appEntryPath;
193
+ if (base) {
194
+ let id = (await this.resolve(base))?.id;
195
+ if (!id)
196
+ return;
197
+ if (query.size > 0)
198
+ id += `?${query.toString()}`;
199
+ return id;
200
+ }
201
+ }
202
+ },
203
+ {
204
+ name: "solid-start:capture-client-bundle",
205
+ enforce: "post",
206
+ generateBundle(_options, bundle) {
207
+ globalThis.START_CLIENT_BUNDLE = bundle;
208
+ }
209
+ },
210
+ devServer(),
211
+ solid({
212
+ ...start.solid,
213
+ ssr: true,
214
+ extensions: extensions.map(ext => `.${ext}`)
215
+ })
216
+ ];
217
+ }
@@ -0,0 +1,3 @@
1
+ import type { PluginOption } from "vite";
2
+ declare const lazy: () => PluginOption;
3
+ export default lazy;
@@ -0,0 +1,82 @@
1
+ import babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ import { sep as osSep } from "path";
4
+ import { basename, relative, sep } from "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
+ return {
39
+ name: "solid-lazy-css",
40
+ enforce: "pre",
41
+ applyToEnvironment(env) {
42
+ return env.name === VITE_ENVIRONMENTS.server;
43
+ },
44
+ async transform(src, id) {
45
+ if (!id.match(fileEndingRegex))
46
+ return;
47
+ // The transformed files either import "lazy" or css files
48
+ // Therefore we skip, if the src doesn't have any import
49
+ if (src.indexOf("import") === -1)
50
+ return;
51
+ const plugins = [];
52
+ const hasDefaultExport = src.indexOf("export default") !== -1;
53
+ if (hasDefaultExport) {
54
+ const localId = relative(cwd, id);
55
+ plugins.push(idTransform(localId));
56
+ }
57
+ const hasLazy = src.indexOf("lazy(") !== -1;
58
+ if (hasLazy)
59
+ plugins.push(importTransform());
60
+ if (!plugins.length) {
61
+ return;
62
+ }
63
+ const transformed = await babel.transformAsync(src, {
64
+ plugins,
65
+ parserOpts: {
66
+ plugins: ["jsx", "typescript"]
67
+ },
68
+ filename: basename(id),
69
+ ast: false,
70
+ sourceMaps: true,
71
+ configFile: false,
72
+ babelrc: false,
73
+ sourceFileName: id
74
+ });
75
+ if (!transformed?.code)
76
+ return;
77
+ const { code, map } = transformed;
78
+ return { code, map };
79
+ }
80
+ };
81
+ };
82
+ 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,74 @@
1
+ import { findStylesInModuleGraph } from "../server/collect-styles.js";
2
+ import { VIRTUAL_MODULES } from "./constants.js";
3
+ export function manifest(start) {
4
+ let devServer = undefined;
5
+ return {
6
+ name: "solid-start:manifest-plugin",
7
+ enforce: "pre",
8
+ configureServer(server) {
9
+ devServer = server;
10
+ },
11
+ async resolveId(id) {
12
+ if (id === VIRTUAL_MODULES.clientViteManifest)
13
+ return `\0${VIRTUAL_MODULES.clientViteManifest}`;
14
+ if (id === VIRTUAL_MODULES.getClientManifest)
15
+ return this.resolve(new URL("../server/manifest/client-manifest", import.meta.url).pathname);
16
+ if (id === VIRTUAL_MODULES.getManifest) {
17
+ return this.environment.config.consumer === "client"
18
+ ? this.resolve(new URL("../server/manifest/client-manifest", import.meta.url).pathname)
19
+ : this.resolve(new URL("../server/manifest/ssr-manifest", import.meta.url).pathname);
20
+ }
21
+ if (id === VIRTUAL_MODULES.middleware) {
22
+ if (start.middleware)
23
+ return await this.resolve(start.middleware);
24
+ return `\0${VIRTUAL_MODULES.middleware}`;
25
+ }
26
+ },
27
+ async load(id) {
28
+ if (id === `\0${VIRTUAL_MODULES.clientViteManifest}`) {
29
+ let clientViteManifest;
30
+ if (this.environment.config.command === "serve") {
31
+ clientViteManifest = {};
32
+ }
33
+ else {
34
+ const entry = Object.values(globalThis.START_CLIENT_BUNDLE).find(v => "isEntry" in v && v.isEntry);
35
+ if (!entry)
36
+ throw new Error("No client entry found");
37
+ clientViteManifest = JSON.parse(globalThis.START_CLIENT_BUNDLE[".vite/manifest.json"].source);
38
+ }
39
+ return `export const clientViteManifest = ${JSON.stringify(clientViteManifest)};`;
40
+ }
41
+ else if (id === `\0${VIRTUAL_MODULES.middleware}`)
42
+ return "export default {};";
43
+ else if (id.startsWith("/@manifest")) {
44
+ if (this.environment.mode !== "dev")
45
+ throw new Error("@manifest queries are only allowed in dev");
46
+ const [path, query] = id.split("?");
47
+ const target = id.split("/")[2];
48
+ const params = new URLSearchParams(query);
49
+ if (!path || !query)
50
+ return;
51
+ if (path.endsWith("assets")) {
52
+ const id = params.get("id");
53
+ if (!id) {
54
+ throw new Error("Missing id to get assets.");
55
+ }
56
+ // Client env does not have css dependencies in mod.transformResult
57
+ // Aalways use ssr env instead, to prevent hydration mismatches
58
+ const env = devServer.environments["ssr"];
59
+ const styles = await findStylesInModuleGraph(env, id);
60
+ const cssAssets = Object.entries(styles).map(([key, value]) => `{
61
+ tag: "style",
62
+ attrs: {
63
+ type: "text/css",
64
+ "data-vite-dev-id": "${key}",
65
+ "data-vite-ref": "0",
66
+ },
67
+ children: () => import("${value}?inline").then(mod => mod.default),
68
+ }`);
69
+ return `export default [${cssAssets.join(",")}]`;
70
+ }
71
+ }
72
+ }
73
+ };
74
+ }
@@ -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,16 @@
1
+ import { 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
+ export declare function wrapId(id: string): string;
8
+ export declare function unwrapId(id: string): string;
9
+ export declare function normalizeViteImportAnalysisUrl(environment: DevEnvironment, id: string): string;
10
+ export declare function withTrailingSlash(path: string): string;
11
+ export declare function splitFileAndPostfix(path: string): {
12
+ file: string;
13
+ postfix: string;
14
+ };
15
+ export declare function slash(p: string): string;
16
+ export declare function injectQuery(url: string, queryToInject: string): string;
@@ -0,0 +1,81 @@
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
+ export function normalizeResolvedIdToUrl(environment, url, resolved) {
11
+ const root = environment.config.root;
12
+ const depsOptimizer = environment.depsOptimizer;
13
+ // normalize all imports into resolved URLs
14
+ // e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
15
+ if (resolved.id.startsWith(withTrailingSlash(root))) {
16
+ // in root: infer short absolute path from root
17
+ url = resolved.id.slice(root.length);
18
+ }
19
+ else if (depsOptimizer?.isOptimizedDepFile(resolved.id) ||
20
+ // vite-plugin-react isn't following the leading \0 virtual module convention.
21
+ // This is a temporary hack to avoid expensive fs checks for React apps.
22
+ // We'll remove this as soon we're able to fix the react plugins.
23
+ (resolved.id !== "/@react-refresh" &&
24
+ path.isAbsolute(resolved.id) &&
25
+ fs.existsSync(cleanUrl(resolved.id)))) {
26
+ // an optimized deps may not yet exists in the filesystem, or
27
+ // a regular file exists but is out of root: rewrite to absolute /@fs/ paths
28
+ url = path.posix.join(FS_PREFIX, resolved.id);
29
+ }
30
+ else {
31
+ url = resolved.id;
32
+ }
33
+ // if the resolved id is not a valid browser import specifier,
34
+ // prefix it to make it valid. We will strip this before feeding it
35
+ // back into the transform pipeline
36
+ if (url[0] !== "." && url[0] !== "/") {
37
+ url = wrapId(resolved.id);
38
+ }
39
+ return url;
40
+ }
41
+ export function wrapId(id) {
42
+ return id.startsWith(VALID_ID_PREFIX)
43
+ ? id
44
+ : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
45
+ }
46
+ export function unwrapId(id) {
47
+ return id.startsWith(VALID_ID_PREFIX)
48
+ ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0")
49
+ : id;
50
+ }
51
+ export function normalizeViteImportAnalysisUrl(environment, id) {
52
+ let url = normalizeResolvedIdToUrl(environment, id, { id });
53
+ // https://github.com/vitejs/vite/blob/c18ce868c4d70873406e9f7d1b2d0a03264d2168/packages/vite/src/node/plugins/importAnalysis.ts#L416
54
+ if (environment.config.consumer === "client") {
55
+ const mod = environment.moduleGraph.getModuleById(id);
56
+ if (mod && mod.lastHMRTimestamp > 0) {
57
+ url = injectQuery(url, `t=${mod.lastHMRTimestamp}`);
58
+ }
59
+ }
60
+ return url;
61
+ }
62
+ export function withTrailingSlash(path) {
63
+ if (path[path.length - 1] !== "/") {
64
+ return `${path}/`;
65
+ }
66
+ return path;
67
+ }
68
+ export function splitFileAndPostfix(path) {
69
+ const file = cleanUrl(path);
70
+ return { file, postfix: path.slice(file.length) };
71
+ }
72
+ const windowsSlashRE = /\\/g;
73
+ export function slash(p) {
74
+ return p.replace(windowsSlashRE, "/");
75
+ }
76
+ const isWindows = typeof process !== "undefined" && process.platform === "win32";
77
+ export function injectQuery(url, queryToInject) {
78
+ const { file, postfix } = splitFileAndPostfix(url);
79
+ const normalizedFile = isWindows ? slash(file) : file;
80
+ return `${normalizedFile}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : /* hash only */ postfix}`;
81
+ }
@@ -0,0 +1,84 @@
1
+ import type { H3Event, HTTPEvent, InferEventInput } from "h3";
2
+ import * as h3 from "h3";
3
+ declare function _setContext(event: H3Event, key: string, value: any): void;
4
+ declare function _getContext(event: H3Event, key: string): unknown;
5
+ export declare function getWebRequest(): Request;
6
+ export declare const HTTPEventSymbol: unique symbol;
7
+ export declare function isEvent(obj: any): obj is h3.H3Event | {
8
+ [HTTPEventSymbol]: h3.H3Event;
9
+ };
10
+ type Tail<T> = T extends [any, ...infer U] ? U : never;
11
+ type PrependOverload<TOriginal extends (...args: Array<any>) => any, TOverload extends (...args: Array<any>) => any> = TOverload & TOriginal;
12
+ type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<TFn, (...args: Parameters<TFn> extends [
13
+ h3.HTTPEvent<any> | h3.H3Event<any>,
14
+ ...infer TArgs
15
+ ] ? TArgs : Parameters<TFn>) => ReturnType<TFn>>;
16
+ type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
17
+ export declare const readBody: PrependOverload<typeof h3.readBody, WrappedReadBody>;
18
+ type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
19
+ export declare const getQuery: PrependOverload<typeof h3.getQuery, WrappedGetQuery>;
20
+ export declare const isMethod: WrapFunction<typeof h3.isMethod>;
21
+ export declare const isPreflightRequest: WrapFunction<typeof h3.isPreflightRequest>;
22
+ type WrappedGetValidatedQuery = <T extends HTTPEvent, TEventInput = InferEventInput<"query", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>;
23
+ export declare const getValidatedQuery: PrependOverload<typeof h3.getValidatedQuery, WrappedGetValidatedQuery>;
24
+ export declare const getRouterParams: WrapFunction<typeof h3.getRouterParams>;
25
+ export declare const getRouterParam: WrapFunction<typeof h3.getRouterParam>;
26
+ type WrappedGetValidatedRouterParams = <T extends HTTPEvent, TEventInput = InferEventInput<"routerParams", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>;
27
+ export declare const getValidatedRouterParams: PrependOverload<typeof h3.getValidatedRouterParams, WrappedGetValidatedRouterParams>;
28
+ export declare const assertMethod: WrapFunction<typeof h3.assertMethod>;
29
+ export declare const getRequestHeaders: WrapFunction<typeof h3.getRequestHeaders>;
30
+ export declare const getRequestHeader: WrapFunction<typeof h3.getRequestHeader>;
31
+ export declare const getRequestURL: WrapFunction<typeof h3.getRequestURL>;
32
+ export declare const getRequestHost: WrapFunction<typeof h3.getRequestHost>;
33
+ export declare const getRequestProtocol: WrapFunction<typeof h3.getRequestProtocol>;
34
+ export declare const getRequestIP: WrapFunction<typeof h3.getRequestIP>;
35
+ export declare const setResponseStatus: (code?: number, text?: string) => void;
36
+ export declare const getResponseStatus: () => number | undefined;
37
+ export declare const getResponseStatusText: () => string | undefined;
38
+ export declare const getResponseHeaders: () => {
39
+ [k: string]: string;
40
+ };
41
+ export declare const getResponseHeader: (name: string) => string | null;
42
+ export declare const setResponseHeaders: (values: Record<string, string>) => void;
43
+ export declare const setResponseHeader: (name: string, value: string | string[]) => void;
44
+ export declare const appendResponseHeaders: (values: Record<string, string>) => void;
45
+ export declare const appendResponseHeader: (name: string, value: string | string[]) => void;
46
+ export declare const defaultContentType: (type: string) => void;
47
+ export declare const proxyRequest: WrapFunction<typeof h3.proxyRequest>;
48
+ export declare const fetchWithEvent: WrapFunction<typeof h3.fetchWithEvent>;
49
+ export declare const getProxyRequestHeaders: WrapFunction<typeof h3.getProxyRequestHeaders>;
50
+ export declare const parseCookies: WrapFunction<typeof h3.parseCookies>;
51
+ export declare const getCookie: WrapFunction<typeof h3.getCookie>;
52
+ export declare const setCookie: WrapFunction<typeof h3.setCookie>;
53
+ export declare const deleteCookie: WrapFunction<typeof h3.deleteCookie>;
54
+ type SessionDataT = Record<string, any>;
55
+ type WrappedUseSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.useSession<T>>>) => ReturnType<typeof h3.useSession<T>>;
56
+ export declare const useSession: WrappedUseSession;
57
+ type WrappedGetSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.getSession<T>>>) => ReturnType<typeof h3.getSession<T>>;
58
+ export declare const getSession: WrappedGetSession;
59
+ type WrappedUpdateSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.updateSession<T>>>) => ReturnType<typeof h3.updateSession<T>>;
60
+ export declare const updateSession: WrappedUpdateSession;
61
+ type WrappedSealSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.sealSession<T>>>) => ReturnType<typeof h3.sealSession<T>>;
62
+ export declare const sealSession: WrappedSealSession;
63
+ export declare const unsealSession: WrapFunction<typeof h3.unsealSession>;
64
+ export declare const clearSession: WrapFunction<typeof h3.clearSession>;
65
+ export declare const handleCacheHeaders: WrapFunction<typeof h3.handleCacheHeaders>;
66
+ export declare const handleCors: WrapFunction<typeof h3.handleCors>;
67
+ export declare const appendCorsHeaders: WrapFunction<typeof h3.appendCorsHeaders>;
68
+ export declare const appendCorsPreflightHeaders: WrapFunction<typeof h3.appendCorsPreflightHeaders>;
69
+ export declare const appendHeader: (name: string, value: string | string[]) => void;
70
+ export declare const appendHeaders: (values: Record<string, string>) => void;
71
+ export declare const setHeader: (name: string, value: string | string[]) => void;
72
+ export declare const setHeaders: (values: Record<string, string>) => void;
73
+ export declare const getHeader: WrapFunction<typeof h3.getRequestHeader>;
74
+ export declare const getHeaders: WrapFunction<typeof h3.getRequestHeaders>;
75
+ export declare const getRequestFingerprint: WrapFunction<typeof h3.getRequestFingerprint>;
76
+ export declare const getRequestWebStream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
77
+ export declare const readFormData: () => Promise<FormData>;
78
+ type WrappedReadValidatedBody = <T extends HTTPEvent, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readValidatedBody<T, H3Event, TEventInput>>;
79
+ export declare const readValidatedBody: PrependOverload<typeof h3.readValidatedBody, WrappedReadValidatedBody>;
80
+ export declare const getContext: WrapFunction<typeof _getContext>;
81
+ export declare const setContext: WrapFunction<typeof _setContext>;
82
+ export declare const removeResponseHeader: (name: string) => void;
83
+ export declare const clearResponseHeaders: (headerNames?: string[]) => void;
84
+ export {};