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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +5 -4
  3. package/src/config/dev-server.ts +5 -1
  4. package/dist/client/StartClient.d.ts +0 -7
  5. package/dist/client/StartClient.jsx +0 -26
  6. package/dist/client/index.d.ts +0 -2
  7. package/dist/client/index.jsx +0 -2
  8. package/dist/client/mount.d.ts +0 -1
  9. package/dist/client/mount.js +0 -1
  10. package/dist/client/spa/index.d.ts +0 -4
  11. package/dist/client/spa/index.jsx +0 -5
  12. package/dist/config/constants.d.ts +0 -16
  13. package/dist/config/constants.js +0 -16
  14. package/dist/config/dev-server.d.ts +0 -2
  15. package/dist/config/dev-server.js +0 -126
  16. package/dist/config/env.d.ts +0 -19
  17. package/dist/config/env.js +0 -81
  18. package/dist/config/fs-router.d.ts +0 -37
  19. package/dist/config/fs-router.js +0 -141
  20. package/dist/config/fs-routes/fs-watcher.d.ts +0 -3
  21. package/dist/config/fs-routes/fs-watcher.js +0 -53
  22. package/dist/config/fs-routes/index.d.ts +0 -7
  23. package/dist/config/fs-routes/index.js +0 -107
  24. package/dist/config/fs-routes/router.d.ts +0 -42
  25. package/dist/config/fs-routes/router.js +0 -148
  26. package/dist/config/fs-routes/tree-shake.d.ts +0 -2
  27. package/dist/config/fs-routes/tree-shake.js +0 -305
  28. package/dist/config/index.d.ts +0 -25
  29. package/dist/config/index.js +0 -217
  30. package/dist/config/lazy.d.ts +0 -3
  31. package/dist/config/lazy.js +0 -114
  32. package/dist/config/manifest.d.ts +0 -3
  33. package/dist/config/manifest.js +0 -109
  34. package/dist/config/utils.d.ts +0 -4
  35. package/dist/config/utils.js +0 -6
  36. package/dist/config/vite-utils.d.ts +0 -21
  37. package/dist/config/vite-utils.js +0 -85
  38. package/dist/directives/bubble-function-declaration.d.ts +0 -3
  39. package/dist/directives/bubble-function-declaration.js +0 -23
  40. package/dist/directives/compile.d.ts +0 -9
  41. package/dist/directives/compile.js +0 -40
  42. package/dist/directives/generate-unique-name.d.ts +0 -3
  43. package/dist/directives/generate-unique-name.js +0 -16
  44. package/dist/directives/get-descriptive-name.d.ts +0 -2
  45. package/dist/directives/get-descriptive-name.js +0 -37
  46. package/dist/directives/get-import-identifier.d.ts +0 -4
  47. package/dist/directives/get-import-identifier.js +0 -19
  48. package/dist/directives/get-root-statement-path.d.ts +0 -2
  49. package/dist/directives/get-root-statement-path.js +0 -12
  50. package/dist/directives/index.d.ts +0 -14
  51. package/dist/directives/index.js +0 -170
  52. package/dist/directives/is-statement-top-level.d.ts +0 -3
  53. package/dist/directives/is-statement-top-level.js +0 -9
  54. package/dist/directives/paths.d.ts +0 -9
  55. package/dist/directives/paths.js +0 -36
  56. package/dist/directives/plugin.d.ts +0 -21
  57. package/dist/directives/plugin.js +0 -302
  58. package/dist/directives/remove-unused-variables.d.ts +0 -3
  59. package/dist/directives/remove-unused-variables.js +0 -66
  60. package/dist/directives/types.d.ts +0 -10
  61. package/dist/directives/types.js +0 -1
  62. package/dist/directives/xxhash32.d.ts +0 -6
  63. package/dist/directives/xxhash32.js +0 -193
  64. package/dist/fns/client.d.ts +0 -3
  65. package/dist/fns/client.js +0 -106
  66. package/dist/fns/handler.d.ts +0 -5
  67. package/dist/fns/handler.js +0 -269
  68. package/dist/fns/registration.d.ts +0 -2
  69. package/dist/fns/registration.js +0 -12
  70. package/dist/fns/serialization.d.ts +0 -6
  71. package/dist/fns/serialization.js +0 -208
  72. package/dist/fns/server.d.ts +0 -7
  73. package/dist/fns/server.js +0 -38
  74. package/dist/fns/shared.d.ts +0 -17
  75. package/dist/fns/shared.js +0 -105
  76. package/dist/http/index.d.ts +0 -81
  77. package/dist/http/index.js +0 -129
  78. package/dist/index.d.ts +0 -5
  79. package/dist/index.jsx +0 -6
  80. package/dist/middleware/index.d.ts +0 -38
  81. package/dist/middleware/index.js +0 -59
  82. package/dist/router.d.ts +0 -6
  83. package/dist/router.jsx +0 -29
  84. package/dist/server/StartServer.d.ts +0 -9
  85. package/dist/server/StartServer.jsx +0 -34
  86. package/dist/server/assets/PatchVirtualDevStyles.d.ts +0 -4
  87. package/dist/server/assets/PatchVirtualDevStyles.jsx +0 -28
  88. package/dist/server/assets/index.d.ts +0 -2
  89. package/dist/server/assets/index.js +0 -52
  90. package/dist/server/assets/render.d.ts +0 -19
  91. package/dist/server/assets/render.jsx +0 -14
  92. package/dist/server/collect-styles.d.ts +0 -3
  93. package/dist/server/collect-styles.js +0 -57
  94. package/dist/server/fetchEvent.d.ts +0 -7
  95. package/dist/server/fetchEvent.js +0 -26
  96. package/dist/server/handler.d.ts +0 -64
  97. package/dist/server/handler.js +0 -222
  98. package/dist/server/index.d.ts +0 -9
  99. package/dist/server/index.jsx +0 -14
  100. package/dist/server/manifest/client-manifest.d.ts +0 -9
  101. package/dist/server/manifest/client-manifest.js +0 -6
  102. package/dist/server/manifest/dev-client-manifest.d.ts +0 -4
  103. package/dist/server/manifest/dev-client-manifest.js +0 -24
  104. package/dist/server/manifest/dev-ssr-manifest.d.ts +0 -5
  105. package/dist/server/manifest/dev-ssr-manifest.js +0 -23
  106. package/dist/server/manifest/prod-client-manifest.d.ts +0 -5
  107. package/dist/server/manifest/prod-client-manifest.js +0 -26
  108. package/dist/server/manifest/prod-ssr-manifest.d.ts +0 -6
  109. package/dist/server/manifest/prod-ssr-manifest.js +0 -85
  110. package/dist/server/manifest/ssr-manifest.d.ts +0 -4
  111. package/dist/server/manifest/ssr-manifest.js +0 -6
  112. package/dist/server/routes.d.ts +0 -23
  113. package/dist/server/routes.js +0 -74
  114. package/dist/server/spa/StartServer.d.ts +0 -9
  115. package/dist/server/spa/StartServer.jsx +0 -25
  116. package/dist/server/spa/handler.d.ts +0 -36
  117. package/dist/server/spa/handler.js +0 -20
  118. package/dist/server/spa/index.d.ts +0 -4
  119. package/dist/server/spa/index.jsx +0 -5
  120. package/dist/server/types.d.ts +0 -75
  121. package/dist/server/types.js +0 -1
  122. package/dist/server/util.d.ts +0 -2
  123. package/dist/server/util.js +0 -8
  124. package/dist/shared/ErrorBoundary.d.ts +0 -3
  125. package/dist/shared/ErrorBoundary.jsx +0 -36
  126. package/dist/shared/GET.d.ts +0 -5
  127. package/dist/shared/GET.js +0 -8
  128. package/dist/shared/HttpHeader.d.ts +0 -10
  129. package/dist/shared/HttpHeader.jsx +0 -38
  130. package/dist/shared/HttpStatusCode.d.ts +0 -9
  131. package/dist/shared/HttpStatusCode.js +0 -18
  132. package/dist/shared/clientOnly.d.ts +0 -12
  133. package/dist/shared/clientOnly.js +0 -27
  134. package/dist/shared/dev-overlay/CodeView.d.ts +0 -7
  135. package/dist/shared/dev-overlay/CodeView.jsx +0 -62
  136. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +0 -9
  137. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +0 -226
  138. package/dist/shared/dev-overlay/createStackFrame.d.ts +0 -9
  139. package/dist/shared/dev-overlay/createStackFrame.js +0 -56
  140. package/dist/shared/dev-overlay/download.d.ts +0 -1
  141. package/dist/shared/dev-overlay/download.js +0 -6
  142. package/dist/shared/dev-overlay/get-source-map.d.ts +0 -2
  143. package/dist/shared/dev-overlay/get-source-map.js +0 -25
  144. package/dist/shared/dev-overlay/icons.d.ts +0 -28
  145. package/dist/shared/dev-overlay/icons.jsx +0 -150
  146. package/dist/shared/dev-overlay/index.d.ts +0 -5
  147. package/dist/shared/dev-overlay/index.jsx +0 -39
  148. package/dist/shared/dev-overlay/styles.css +0 -292
  149. package/dist/shared/lazy.d.ts +0 -3
  150. package/dist/shared/lazy.js +0 -42
  151. package/dist/shared/serverFunction.d.ts +0 -6
  152. package/dist/shared/serverFunction.js +0 -8
  153. package/dist/utils/debounce.d.ts +0 -4
  154. package/dist/utils/debounce.js +0 -10
@@ -1,217 +0,0 @@
1
- import { defu } from "defu";
2
- import { globSync } from "node:fs";
3
- import { extname, isAbsolute, join } from "node:path";
4
- import solid from "vite-plugin-solid";
5
- import { serverFunctionsPlugin } from "../directives/index.js";
6
- import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.js";
7
- import { devServer } from "./dev-server.js";
8
- import { envPlugin } from "./env.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
- // TODO (Alexis): check if the comment below is still relevant
41
- //
42
- // Must be placed after fsRoutes, as treeShake will remove the
43
- // server fn exports added in by this plugin
44
- serverFunctionsPlugin({
45
- manifest: VIRTUAL_MODULES.serverFnManifest,
46
- runtime: {
47
- server: '@solidjs/start/fns/server',
48
- client: '@solidjs/start/fns/client',
49
- },
50
- filter: options?.serverFunctions?.filter,
51
- }),
52
- {
53
- name: "solid-start:config",
54
- enforce: "pre",
55
- configEnvironment(name) {
56
- return {
57
- resolve: {
58
- // remove when https://github.com/solidjs/vite-plugin-solid/pull/228 is released
59
- externalConditions: ["solid", "node"],
60
- },
61
- };
62
- },
63
- async config(_, env) {
64
- const clientInput = [handlers.client];
65
- if (env.command === "build") {
66
- const clientRouter = globalThis.ROUTERS.client;
67
- for (const route of await clientRouter.getRoutes()) {
68
- for (const [key, value] of Object.entries(route)) {
69
- if (value && key.startsWith("$") && !key.startsWith("$$")) {
70
- function toRouteId(route) {
71
- return `${route.src}?${route.pick.map((p) => `pick=${p}`).join("&")}`;
72
- }
73
- clientInput.push(toRouteId(value));
74
- }
75
- }
76
- }
77
- }
78
- return {
79
- appType: "custom",
80
- build: { assetsDir: "_build/assets" },
81
- optimizeDeps: {
82
- // Suppress TS errors from Vite 7 types when configuring Vite 8's Rolldown
83
- ...{
84
- rolldownOptions: {
85
- transform: {
86
- jsx: "react",
87
- },
88
- },
89
- },
90
- },
91
- environments: {
92
- [VITE_ENVIRONMENTS.client]: {
93
- consumer: "client",
94
- build: {
95
- write: true,
96
- manifest: true,
97
- outDir: "dist/client",
98
- rollupOptions: {
99
- input: clientInput,
100
- treeshake: true,
101
- preserveEntrySignatures: "exports-only",
102
- },
103
- },
104
- },
105
- [VITE_ENVIRONMENTS.server]: {
106
- consumer: "server",
107
- build: {
108
- ssr: true,
109
- write: true,
110
- manifest: true,
111
- copyPublicDir: false,
112
- rollupOptions: {
113
- input: "~/entry-server.tsx",
114
- },
115
- outDir: "dist/server",
116
- commonjsOptions: {
117
- include: [/node_modules/],
118
- },
119
- },
120
- },
121
- },
122
- resolve: {
123
- alias: {
124
- "@solidjs/start/server/entry": handlers.server,
125
- "~": join(process.cwd(), start.appRoot),
126
- ...(!start.ssr
127
- ? {
128
- "@solidjs/start/server": "@solidjs/start/server/spa",
129
- "@solidjs/start/client": "@solidjs/start/client/spa",
130
- }
131
- : {}),
132
- },
133
- // Depending on the package manager and dependency structure Vite externalizes @solidjs/start
134
- // This makes sure that @solidjs/start goes through the Vite build process
135
- noExternal: ["@solidjs/start"],
136
- },
137
- define: {
138
- "import.meta.env.MANIFEST": `globalThis.MANIFEST`,
139
- "import.meta.env.START_SSR": JSON.stringify(start.ssr),
140
- // Use JSON.stringify so backslashes on Windows are escaped and
141
- // esbuild receives a valid JS string literal for the define value
142
- "import.meta.env.START_APP_ENTRY": JSON.stringify(appEntryPath),
143
- "import.meta.env.START_CLIENT_ENTRY": JSON.stringify(handlers.client),
144
- "import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
145
- "import.meta.env.SEROVAL_MODE": JSON.stringify(start.serialization?.mode || "json"),
146
- },
147
- builder: {
148
- sharedPlugins: true,
149
- async buildApp(builder) {
150
- const client = builder.environments[VITE_ENVIRONMENTS.client];
151
- const server = builder.environments[VITE_ENVIRONMENTS.server];
152
- if (!client)
153
- throw new Error("Client environment not found");
154
- if (!server)
155
- throw new Error("SSR environment not found");
156
- if (!client.isBuilt)
157
- await builder.build(client);
158
- if (!server.isBuilt)
159
- await builder.build(server);
160
- },
161
- },
162
- };
163
- },
164
- },
165
- manifest(start),
166
- fsRoutes({
167
- routers: {
168
- client: new SolidStartClientFileRouter({
169
- dir: absolute(routeDir, root),
170
- extensions,
171
- }),
172
- ssr: new SolidStartServerFileRouter({
173
- dir: absolute(routeDir, root),
174
- extensions,
175
- dataOnly: !start.ssr,
176
- }),
177
- },
178
- }),
179
- lazy(),
180
- envPlugin(options?.env),
181
- {
182
- name: "solid-start:virtual-modules",
183
- async resolveId(id) {
184
- const { filename, query } = parseIdQuery(id);
185
- let base;
186
- if (filename === VIRTUAL_MODULES.clientEntry)
187
- base = handlers.client;
188
- if (filename === VIRTUAL_MODULES.serverEntry)
189
- base = handlers.server;
190
- if (filename === VIRTUAL_MODULES.app)
191
- base = appEntryPath;
192
- if (base) {
193
- let id = (await this.resolve(base))?.id;
194
- if (!id)
195
- return;
196
- if (query.size > 0)
197
- id += `?${query.toString()}`;
198
- return id;
199
- }
200
- },
201
- },
202
- {
203
- name: "solid-start:capture-client-bundle",
204
- enforce: "post",
205
- generateBundle(options, bundle) {
206
- globalThis.START_CLIENT_BUNDLE = bundle;
207
- globalThis.START_CLIENT_OUT_DIR = options.dir;
208
- },
209
- },
210
- devServer(),
211
- solid({
212
- ...start.solid,
213
- ssr: true,
214
- extensions: extensions.map(ext => `.${ext}`),
215
- }),
216
- ];
217
- }
@@ -1,3 +0,0 @@
1
- import type { PluginOption } from "vite";
2
- declare const lazy: () => PluginOption;
3
- export default lazy;
@@ -1,114 +0,0 @@
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;
@@ -1,3 +0,0 @@
1
- import { type PluginOption } from "vite";
2
- import { type SolidStartOptions } from "./index.ts";
3
- export declare function manifest(start: SolidStartOptions): PluginOption;
@@ -1,109 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
1
- export declare function parseIdQuery(id: string): {
2
- filename: string;
3
- query: URLSearchParams;
4
- };
@@ -1,6 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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;
@@ -1,85 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
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;
@@ -1,23 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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>;
@@ -1,40 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
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;