@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,114 @@
1
+ import babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ import { sep as osSep } from "node:path";
4
+ import { basename, relative, sep } from "node:path/posix";
5
+ import { VITE_ENVIRONMENTS } from "./constants.js";
6
+ const idTransform = (id) => {
7
+ return {
8
+ visitor: {
9
+ Program(path) {
10
+ path.node.body.unshift(t.exportNamedDeclaration(t.variableDeclaration("const", [
11
+ t.variableDeclarator(t.identifier("id$$"), t.stringLiteral(id)),
12
+ ])));
13
+ },
14
+ },
15
+ };
16
+ };
17
+ const importTransform = () => {
18
+ return {
19
+ visitor: {
20
+ ImportDeclaration(path) {
21
+ if (path.node.source.value !== "solid-js")
22
+ return;
23
+ path.traverse({
24
+ ImportSpecifier(subPath) {
25
+ if (subPath.node.local.name !== "lazy")
26
+ return;
27
+ subPath.remove();
28
+ path.insertAfter(t.importDeclaration([t.importSpecifier(t.identifier("lazy"), t.identifier("lazy"))], t.stringLiteral("@solidjs/start/server")));
29
+ },
30
+ });
31
+ },
32
+ },
33
+ };
34
+ };
35
+ const fileEndingRegex = /(ts|js)x(\?.*)?$/;
36
+ const lazy = () => {
37
+ const cwd = process.cwd().replaceAll(osSep, sep);
38
+ /**
39
+ * Maps module ids to their client-specific shared chunk names.
40
+ * Modules in shared chunks need to find their assets via the chunk name, instead of their module id.
41
+ *
42
+ * Vite includes assets of such modules in the manifest via the chunk name:
43
+ * https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L179
44
+ * https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L319
45
+ *
46
+ * Rollup occassionally creates shared chunks automatically,
47
+ * but they can also be manually created by the user via:
48
+ * https://rollupjs.org/configuration-options/#output-manualchunks
49
+ *
50
+ * More infos on Rollup's logic:
51
+ * https://github.com/rollup/rollup/issues/3772#issuecomment-689955168
52
+ */
53
+ const sharedChunkNames = {};
54
+ return {
55
+ name: "solid-lazy-css",
56
+ enforce: "pre",
57
+ generateBundle(_, bundle) {
58
+ if (this.environment.name !== VITE_ENVIRONMENTS.client)
59
+ return;
60
+ for (const chunk of Object.values(bundle)) {
61
+ if (chunk.type !== "chunk" || !chunk.isDynamicEntry || chunk.facadeModuleId)
62
+ continue;
63
+ // Has to follow Vites implementation:
64
+ // https://github.com/vitejs/vite/blob/4be37a8389c67873880f826b01fe40137e1c29a7/packages/vite/src/node/plugins/manifest.ts#L179
65
+ const chunkName = `_${basename(chunk.fileName)}`;
66
+ for (const id of chunk.moduleIds) {
67
+ sharedChunkNames[id] = chunkName;
68
+ }
69
+ }
70
+ },
71
+ async transform(src, id) {
72
+ if (this.environment.name !== VITE_ENVIRONMENTS.server)
73
+ return;
74
+ if (!id.match(fileEndingRegex))
75
+ return;
76
+ // The transformed files either import "lazy" or css files
77
+ // Therefore we skip, if the src doesn't have any import
78
+ if (src.indexOf("import") === -1)
79
+ return;
80
+ if (id.includes("entry-server"))
81
+ return;
82
+ const plugins = [];
83
+ const hasDefaultExport = src.indexOf("export default") !== -1;
84
+ if (hasDefaultExport) {
85
+ const localId = relative(cwd, id);
86
+ const chunkName = sharedChunkNames[id];
87
+ plugins.push(idTransform(chunkName ?? localId));
88
+ }
89
+ const hasLazy = src.indexOf("lazy(") !== -1;
90
+ if (hasLazy)
91
+ plugins.push(importTransform());
92
+ if (!plugins.length) {
93
+ return;
94
+ }
95
+ const transformed = await babel.transformAsync(src, {
96
+ plugins,
97
+ parserOpts: {
98
+ plugins: ["jsx", "typescript"],
99
+ },
100
+ filename: basename(id),
101
+ ast: false,
102
+ sourceMaps: true,
103
+ configFile: false,
104
+ babelrc: false,
105
+ sourceFileName: id,
106
+ });
107
+ if (!transformed?.code)
108
+ return;
109
+ const { code, map } = transformed;
110
+ return { code, map };
111
+ },
112
+ };
113
+ };
114
+ export default lazy;
@@ -0,0 +1,3 @@
1
+ import { type PluginOption } from "vite";
2
+ import { type SolidStartOptions } from "./index.ts";
3
+ export declare function manifest(start: SolidStartOptions): PluginOption;
@@ -0,0 +1,109 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { version as viteVersion } from "vite";
4
+ import { fileURLToPath } from "node:url";
5
+ import { findStylesInModuleGraph } from "../server/collect-styles.js";
6
+ import { VIRTUAL_MODULES } from "./constants.js";
7
+ import { wrapId } from "./vite-utils.js";
8
+ export function manifest(start) {
9
+ let devServer = undefined;
10
+ return {
11
+ name: "solid-start:manifest-plugin",
12
+ enforce: "pre",
13
+ configureServer(server) {
14
+ devServer = server;
15
+ },
16
+ async resolveId(id) {
17
+ if (id === VIRTUAL_MODULES.clientViteManifest)
18
+ return `\0${VIRTUAL_MODULES.clientViteManifest}`;
19
+ if (id === VIRTUAL_MODULES.getClientManifest)
20
+ return this.resolve(fileURLToPath(new URL("../server/manifest/client-manifest", import.meta.url)));
21
+ if (id === VIRTUAL_MODULES.getManifest) {
22
+ return this.environment.config.consumer === "client"
23
+ ? this.resolve(fileURLToPath(new URL("../server/manifest/client-manifest", import.meta.url)))
24
+ : this.resolve(fileURLToPath(new URL("../server/manifest/ssr-manifest", import.meta.url)));
25
+ }
26
+ if (id === VIRTUAL_MODULES.middleware) {
27
+ if (start.middleware)
28
+ return await this.resolve(start.middleware);
29
+ return `\0${VIRTUAL_MODULES.middleware}`;
30
+ }
31
+ },
32
+ async load(id) {
33
+ if (id === `\0${VIRTUAL_MODULES.clientViteManifest}`) {
34
+ let clientViteManifest;
35
+ if (this.environment.config.command === "serve") {
36
+ clientViteManifest = {};
37
+ }
38
+ else {
39
+ const entry = Object.values(globalThis.START_CLIENT_BUNDLE).find(v => "isEntry" in v && v.isEntry);
40
+ if (!entry)
41
+ throw new Error("No client entry found");
42
+ let rawManifest;
43
+ const viteMajor = parseInt(viteVersion.split('.')[0], 10);
44
+ const manifestKey = Object.keys(globalThis.START_CLIENT_BUNDLE).find(k => k.endsWith("manifest.json"));
45
+ if (manifestKey && viteMajor < 8) {
46
+ const manifestAsset = globalThis.START_CLIENT_BUNDLE[manifestKey];
47
+ rawManifest = manifestAsset.source;
48
+ }
49
+ else {
50
+ try {
51
+ const appRoot = start.appRoot || "./src";
52
+ let outDir = ".solid-start/client";
53
+ if (devServer?.environments?.client?.config?.build?.outDir) {
54
+ outDir = devServer.environments.client.config.build.outDir;
55
+ }
56
+ else if (this.environment?.config?.build?.outDir && this.environment?.config?.consumer === "client") {
57
+ outDir = this.environment.config.build.outDir;
58
+ }
59
+ else if (globalThis.START_CLIENT_OUT_DIR) {
60
+ outDir = globalThis.START_CLIENT_OUT_DIR;
61
+ }
62
+ const manifestPath = path.resolve(appRoot, "..", outDir, ".vite/manifest.json");
63
+ rawManifest = fs.readFileSync(manifestPath, "utf-8");
64
+ }
65
+ catch (e) {
66
+ throw new Error(`Manifest asset not found in bundle and could not be read from disk. Keys: ${Object.keys(globalThis.START_CLIENT_BUNDLE).join(", ")}. Error: ${e}`);
67
+ }
68
+ }
69
+ if (!rawManifest) {
70
+ throw new Error("Failed to extract or read raw manifest.");
71
+ }
72
+ clientViteManifest = JSON.parse(rawManifest);
73
+ }
74
+ return `export const clientViteManifest = ${JSON.stringify(clientViteManifest)};`;
75
+ }
76
+ else if (id === `\0${VIRTUAL_MODULES.middleware}`)
77
+ return "export default {};";
78
+ else if (id.startsWith("/@manifest")) {
79
+ if (this.environment.mode !== "dev")
80
+ throw new Error("@manifest queries are only allowed in dev");
81
+ const [urlPath, query] = id.split("?");
82
+ const target = id.split("/")[2];
83
+ const params = new URLSearchParams(query);
84
+ if (!urlPath || !query)
85
+ return;
86
+ if (urlPath.endsWith("assets")) {
87
+ const id = params.get("id");
88
+ if (!id) {
89
+ throw new Error("Missing id to get assets.");
90
+ }
91
+ // Client env does not have css dependencies in mod.transformResult
92
+ // Aalways use ssr env instead, to prevent hydration mismatches
93
+ const env = devServer.environments["ssr"];
94
+ const styles = await findStylesInModuleGraph(env, id);
95
+ const cssAssets = Object.entries(styles).map(([key, value]) => `{
96
+ tag: "style",
97
+ attrs: {
98
+ type: "text/css",
99
+ "data-vite-dev-id": "${wrapId(key)}",
100
+ "data-vite-ref": "0",
101
+ },
102
+ children: () => import("${wrapId(value)}?inline").then(mod => mod.default),
103
+ }`);
104
+ return `export default [${cssAssets.join(",")}]`;
105
+ }
106
+ }
107
+ },
108
+ };
109
+ }
@@ -0,0 +1,4 @@
1
+ export declare function parseIdQuery(id: string): {
2
+ filename: string;
3
+ query: URLSearchParams;
4
+ };
@@ -0,0 +1,6 @@
1
+ export function parseIdQuery(id) {
2
+ if (!id.includes("?"))
3
+ return { filename: id, query: new URLSearchParams() };
4
+ const [filename, rawQuery] = id.split(`?`, 2);
5
+ return { filename, query: new URLSearchParams(rawQuery) };
6
+ }
@@ -0,0 +1,21 @@
1
+ import type { DevEnvironment, Rollup } from "vite";
2
+ export declare function cleanUrl(url: string): string;
3
+ export declare const FS_PREFIX = "/@fs/";
4
+ export declare const VALID_ID_PREFIX = "/@id/";
5
+ export declare const NULL_BYTE_PLACEHOLDER = "__x00__";
6
+ export declare function normalizeResolvedIdToUrl(environment: DevEnvironment, url: string, resolved: Rollup.PartialResolvedId): string;
7
+ /**
8
+ * Inspired by:
9
+ * https://github.com/withastro/astro/blob/fddde5fad81007795eb263c7fd0cea096b8e2cba/packages/astro/src/core/util.ts#L115
10
+ * https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/shared/utils.ts#L11
11
+ */
12
+ export declare function wrapId(id: string): string;
13
+ export declare function unwrapId(id: string): string;
14
+ export declare function normalizeViteImportAnalysisUrl(environment: DevEnvironment, id: string): string;
15
+ export declare function withTrailingSlash(path: string): string;
16
+ export declare function splitFileAndPostfix(path: string): {
17
+ file: string;
18
+ postfix: string;
19
+ };
20
+ export declare function slash(p: string): string;
21
+ export declare function injectQuery(url: string, queryToInject: string): string;
@@ -0,0 +1,85 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ const postfixRE = /[?#].*$/;
4
+ export function cleanUrl(url) {
5
+ return url.replace(postfixRE, "");
6
+ }
7
+ export const FS_PREFIX = `/@fs/`;
8
+ export const VALID_ID_PREFIX = `/@id/`;
9
+ export const NULL_BYTE_PLACEHOLDER = `__x00__`;
10
+ const NULL_BYTE_REGEX = /^\0/;
11
+ export function normalizeResolvedIdToUrl(environment, url, resolved) {
12
+ const root = environment.config.root;
13
+ const depsOptimizer = environment.depsOptimizer;
14
+ // normalize all imports into resolved URLs
15
+ // e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
16
+ if (resolved.id.startsWith(withTrailingSlash(root))) {
17
+ // in root: infer short absolute path from root
18
+ url = resolved.id.slice(root.length);
19
+ }
20
+ else if (depsOptimizer?.isOptimizedDepFile(resolved.id) ||
21
+ // vite-plugin-react isn't following the leading \0 virtual module convention.
22
+ // This is a temporary hack to avoid expensive fs checks for React apps.
23
+ // We'll remove this as soon we're able to fix the react plugins.
24
+ (resolved.id !== "/@react-refresh" &&
25
+ path.isAbsolute(resolved.id) &&
26
+ fs.existsSync(cleanUrl(resolved.id)))) {
27
+ // an optimized deps may not yet exists in the filesystem, or
28
+ // a regular file exists but is out of root: rewrite to absolute /@fs/ paths
29
+ url = path.posix.join(FS_PREFIX, resolved.id);
30
+ }
31
+ else {
32
+ url = resolved.id;
33
+ }
34
+ // if the resolved id is not a valid browser import specifier,
35
+ // prefix it to make it valid. We will strip this before feeding it
36
+ // back into the transform pipeline
37
+ if (url[0] !== "." && url[0] !== "/") {
38
+ url = wrapId(resolved.id);
39
+ }
40
+ return url;
41
+ }
42
+ /**
43
+ * Inspired by:
44
+ * https://github.com/withastro/astro/blob/fddde5fad81007795eb263c7fd0cea096b8e2cba/packages/astro/src/core/util.ts#L115
45
+ * https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/shared/utils.ts#L11
46
+ */
47
+ export function wrapId(id) {
48
+ return id.replace(NULL_BYTE_REGEX, `${VALID_ID_PREFIX}${NULL_BYTE_PLACEHOLDER}`);
49
+ }
50
+ export function unwrapId(id) {
51
+ return id.startsWith(VALID_ID_PREFIX)
52
+ ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0")
53
+ : id;
54
+ }
55
+ export function normalizeViteImportAnalysisUrl(environment, id) {
56
+ let url = normalizeResolvedIdToUrl(environment, id, { id });
57
+ // https://github.com/vitejs/vite/blob/c18ce868c4d70873406e9f7d1b2d0a03264d2168/packages/vite/src/node/plugins/importAnalysis.ts#L416
58
+ if (environment.config.consumer === "client") {
59
+ const mod = environment.moduleGraph.getModuleById(id);
60
+ if (mod && mod.lastHMRTimestamp > 0) {
61
+ url = injectQuery(url, `t=${mod.lastHMRTimestamp}`);
62
+ }
63
+ }
64
+ return url;
65
+ }
66
+ export function withTrailingSlash(path) {
67
+ if (path[path.length - 1] !== "/") {
68
+ return `${path}/`;
69
+ }
70
+ return path;
71
+ }
72
+ export function splitFileAndPostfix(path) {
73
+ const file = cleanUrl(path);
74
+ return { file, postfix: path.slice(file.length) };
75
+ }
76
+ const windowsSlashRE = /\\/g;
77
+ export function slash(p) {
78
+ return p.replace(windowsSlashRE, "/");
79
+ }
80
+ const isWindows = typeof process !== "undefined" && process.platform === "win32";
81
+ export function injectQuery(url, queryToInject) {
82
+ const { file, postfix } = splitFileAndPostfix(url);
83
+ const normalizedFile = isWindows ? slash(file) : file;
84
+ return `${normalizedFile}?${queryToInject}${postfix[0] === "?" ? `&${postfix.slice(1)}` : /* hash only */ postfix}`;
85
+ }
@@ -0,0 +1,3 @@
1
+ import type * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ export declare function bubbleFunctionDeclaration(path: babel.NodePath<t.FunctionDeclaration>): void;
@@ -0,0 +1,23 @@
1
+ import * as t from "@babel/types";
2
+ export function bubbleFunctionDeclaration(path) {
3
+ const decl = path.node;
4
+ // Check if declaration is FunctionDeclaration
5
+ if (decl.id) {
6
+ const block = (path.findParent(current => current.isBlockStatement()) ||
7
+ path.scope.getProgramParent().path);
8
+ if (path.parentPath.isExportNamedDeclaration()) {
9
+ path.parentPath.replaceWith(t.exportNamedDeclaration(undefined, [t.exportSpecifier(decl.id, decl.id)]));
10
+ }
11
+ else if (path.parentPath.isExportDefaultDeclaration()) {
12
+ path.replaceWith(decl.id);
13
+ }
14
+ else {
15
+ path.remove();
16
+ }
17
+ const [tmp] = block.unshiftContainer("body", t.variableDeclaration("const", [
18
+ t.variableDeclarator(decl.id, t.functionExpression(decl.id, decl.params, decl.body, decl.generator, decl.async)),
19
+ ]));
20
+ block.scope.registerDeclaration(tmp);
21
+ tmp.skip();
22
+ }
23
+ }
@@ -0,0 +1,9 @@
1
+ import * as babel from "@babel/core";
2
+ import { type StateContext } from "./plugin.ts";
3
+ export interface CompileResult {
4
+ valid: boolean;
5
+ code: string;
6
+ map: babel.BabelFileResult["map"];
7
+ }
8
+ export type CompileOptions = Omit<StateContext, "count" | "hash" | "imports" | "valid">;
9
+ export declare function compile(id: string, code: string, options: CompileOptions): Promise<CompileResult>;
@@ -0,0 +1,40 @@
1
+ import * as babel from "@babel/core";
2
+ import path from "node:path";
3
+ import { directivesPlugin } from "./plugin.js";
4
+ import xxHash32 from "./xxhash32.js";
5
+ export async function compile(id, code, options) {
6
+ const context = {
7
+ ...options,
8
+ valid: false,
9
+ hash: xxHash32(id).toString(16),
10
+ count: 0,
11
+ imports: new Map(),
12
+ };
13
+ const pluginOption = [directivesPlugin, context];
14
+ const plugins = [
15
+ "jsx",
16
+ ];
17
+ if (/\.[mc]?tsx?$/i.test(id)) {
18
+ plugins.push("typescript");
19
+ }
20
+ const result = await babel.transformAsync(code, {
21
+ plugins: [pluginOption],
22
+ parserOpts: {
23
+ plugins,
24
+ },
25
+ filename: path.basename(id),
26
+ ast: false,
27
+ sourceMaps: true,
28
+ configFile: false,
29
+ babelrc: false,
30
+ sourceFileName: id,
31
+ });
32
+ if (result) {
33
+ return {
34
+ valid: context.valid,
35
+ code: result.code || "",
36
+ map: result.map,
37
+ };
38
+ }
39
+ throw new Error("invariant");
40
+ }
@@ -0,0 +1,3 @@
1
+ import type * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ export declare function generateUniqueName(path: babel.NodePath, name: string): t.Identifier;
@@ -0,0 +1,16 @@
1
+ import * as t from "@babel/types";
2
+ export function generateUniqueName(path, name) {
3
+ let uid;
4
+ let i = 1;
5
+ do {
6
+ uid = name + "_" + i;
7
+ i++;
8
+ } while (path.scope.hasLabel(uid) ||
9
+ path.scope.hasBinding(uid) ||
10
+ path.scope.hasGlobal(uid) ||
11
+ path.scope.hasReference(uid));
12
+ const program = path.scope.getProgramParent();
13
+ program.references[uid] = true;
14
+ program.uids[uid] = true;
15
+ return t.identifier(uid);
16
+ }
@@ -0,0 +1,2 @@
1
+ import type { NodePath } from "@babel/core";
2
+ export declare function getDescriptiveName(path: NodePath, defaultName: string): string;
@@ -0,0 +1,37 @@
1
+ export function getDescriptiveName(path, defaultName) {
2
+ let current = path;
3
+ while (current) {
4
+ switch (current.node.type) {
5
+ case "FunctionDeclaration":
6
+ case "FunctionExpression": {
7
+ if (current.node.id) {
8
+ return current.node.id.name;
9
+ }
10
+ break;
11
+ }
12
+ case "VariableDeclarator": {
13
+ if (current.node.id.type === "Identifier") {
14
+ return current.node.id.name;
15
+ }
16
+ break;
17
+ }
18
+ case "ClassPrivateMethod":
19
+ case "ClassMethod":
20
+ case "ObjectMethod": {
21
+ switch (current.node.key.type) {
22
+ case "Identifier":
23
+ return current.node.key.name;
24
+ case "PrivateName":
25
+ return current.node.key.id.name;
26
+ default:
27
+ break;
28
+ }
29
+ break;
30
+ }
31
+ default:
32
+ break;
33
+ }
34
+ current = current.parentPath;
35
+ }
36
+ return defaultName;
37
+ }
@@ -0,0 +1,4 @@
1
+ import type * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ import type { ImportDefinition } from "./types.ts";
4
+ export declare function getImportIdentifier(imports: Map<string, t.Identifier>, path: babel.NodePath, registration: ImportDefinition): t.Identifier;
@@ -0,0 +1,19 @@
1
+ import * as t from "@babel/types";
2
+ import { generateUniqueName } from "./generate-unique-name.js";
3
+ export function getImportIdentifier(imports, path, registration) {
4
+ const name = registration.kind === "named" ? registration.name : "default";
5
+ const target = `${registration.source}[${name}]`;
6
+ const current = imports.get(target);
7
+ if (current) {
8
+ return current;
9
+ }
10
+ const programParent = path.scope.getProgramParent();
11
+ const uid = generateUniqueName(programParent.path, name);
12
+ programParent.registerDeclaration(programParent.path.unshiftContainer("body", t.importDeclaration([
13
+ registration.kind === "named"
14
+ ? t.importSpecifier(uid, t.identifier(registration.name))
15
+ : t.importDefaultSpecifier(uid),
16
+ ], t.stringLiteral(registration.source)))[0]);
17
+ imports.set(target, uid);
18
+ return uid;
19
+ }
@@ -0,0 +1,2 @@
1
+ import type * as babel from "@babel/core";
2
+ export declare function getRootStatementPath(path: babel.NodePath): babel.NodePath;
@@ -0,0 +1,12 @@
1
+ import * as t from "@babel/types";
2
+ export function getRootStatementPath(path) {
3
+ let current = path.parentPath;
4
+ while (current) {
5
+ const next = current.parentPath;
6
+ if (next && t.isProgram(next.node)) {
7
+ return current;
8
+ }
9
+ current = next;
10
+ }
11
+ return path;
12
+ }
@@ -0,0 +1,14 @@
1
+ import { type FilterPattern, type Plugin } from "vite";
2
+ export interface ServerFunctionsFilter {
3
+ include?: FilterPattern;
4
+ exclude?: FilterPattern;
5
+ }
6
+ export interface ServerFunctionsOptions {
7
+ manifest: string;
8
+ runtime: {
9
+ server: string;
10
+ client: string;
11
+ };
12
+ filter?: ServerFunctionsFilter;
13
+ }
14
+ export declare function serverFunctionsPlugin(options: ServerFunctionsOptions): Plugin[];