@octanejs/tanstack-start 0.1.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 (266) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +52 -0
  3. package/THIRD_PARTY_NOTICES.md +11 -0
  4. package/package.json +149 -0
  5. package/src/client-only.d.ts +1 -0
  6. package/src/client-only.js +0 -0
  7. package/src/client-rpc.d.ts +1 -0
  8. package/src/client-rpc.js +1 -0
  9. package/src/client.d.ts +3 -0
  10. package/src/client.js +2 -0
  11. package/src/default-entry/client.js +12 -0
  12. package/src/default-entry/server.js +13 -0
  13. package/src/default-entry/start.js +1 -0
  14. package/src/default-entry-paths.d.ts +5 -0
  15. package/src/default-entry-paths.js +11 -0
  16. package/src/index.d.ts +11 -0
  17. package/src/index.js +22 -0
  18. package/src/internal/README.md +15 -0
  19. package/src/internal/router-generator/config.d.ts +255 -0
  20. package/src/internal/router-generator/config.js +134 -0
  21. package/src/internal/router-generator/filesystem/physical/getRouteNodes.d.ts +53 -0
  22. package/src/internal/router-generator/filesystem/physical/getRouteNodes.js +335 -0
  23. package/src/internal/router-generator/filesystem/physical/rootPathId.d.ts +1 -0
  24. package/src/internal/router-generator/filesystem/physical/rootPathId.js +4 -0
  25. package/src/internal/router-generator/filesystem/virtual/config.d.ts +3 -0
  26. package/src/internal/router-generator/filesystem/virtual/config.js +36 -0
  27. package/src/internal/router-generator/filesystem/virtual/getRouteNodes.d.ts +31 -0
  28. package/src/internal/router-generator/filesystem/virtual/getRouteNodes.js +272 -0
  29. package/src/internal/router-generator/filesystem/virtual/loadConfigFile.d.ts +1 -0
  30. package/src/internal/router-generator/filesystem/virtual/loadConfigFile.js +10 -0
  31. package/src/internal/router-generator/generator.d.ts +119 -0
  32. package/src/internal/router-generator/generator.js +1080 -0
  33. package/src/internal/router-generator/index.d.ts +40 -0
  34. package/src/internal/router-generator/index.js +49 -0
  35. package/src/internal/router-generator/logger.d.ts +8 -0
  36. package/src/internal/router-generator/logger.js +30 -0
  37. package/src/internal/router-generator/plugin/types.d.ts +37 -0
  38. package/src/internal/router-generator/template.d.ts +38 -0
  39. package/src/internal/router-generator/template.js +220 -0
  40. package/src/internal/router-generator/transform/transform.d.ts +8 -0
  41. package/src/internal/router-generator/transform/transform.js +385 -0
  42. package/src/internal/router-generator/transform/types.d.ts +34 -0
  43. package/src/internal/router-generator/types.d.ts +73 -0
  44. package/src/internal/router-generator/utils.d.ts +270 -0
  45. package/src/internal/router-generator/utils.js +864 -0
  46. package/src/internal/router-generator/validate-route-params.d.ts +13 -0
  47. package/src/internal/router-generator/validate-route-params.js +75 -0
  48. package/src/internal/router-plugin/context.d.ts +2 -0
  49. package/src/internal/router-plugin/context.js +2 -0
  50. package/src/internal/router-plugin/core/code-splitter/compilers.d.ts +69 -0
  51. package/src/internal/router-plugin/core/code-splitter/compilers.js +1042 -0
  52. package/src/internal/router-plugin/core/code-splitter/framework-options.d.ts +11 -0
  53. package/src/internal/router-plugin/core/code-splitter/framework-options.js +41 -0
  54. package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.d.ts +12 -0
  55. package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.js +35 -0
  56. package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.d.ts +5 -0
  57. package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.js +106 -0
  58. package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.d.ts +8 -0
  59. package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.js +85 -0
  60. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +2 -0
  61. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +55 -0
  62. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.d.ts +2 -0
  63. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.js +50 -0
  64. package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +5 -0
  65. package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +54 -0
  66. package/src/internal/router-plugin/core/code-splitter/plugins.d.ts +62 -0
  67. package/src/internal/router-plugin/core/code-splitter/types.d.ts +9 -0
  68. package/src/internal/router-plugin/core/config.d.ts +294 -0
  69. package/src/internal/router-plugin/core/config.js +56 -0
  70. package/src/internal/router-plugin/core/constants.d.ts +12 -0
  71. package/src/internal/router-plugin/core/constants.js +13 -0
  72. package/src/internal/router-plugin/core/framework-plugin-order.d.ts +8 -0
  73. package/src/internal/router-plugin/core/framework-plugin-order.js +78 -0
  74. package/src/internal/router-plugin/core/hmr/handle-route-update.d.ts +1 -0
  75. package/src/internal/router-plugin/core/hmr/handle-route-update.js +126 -0
  76. package/src/internal/router-plugin/core/hmr/index.d.ts +5 -0
  77. package/src/internal/router-plugin/core/hmr/select-adapter.d.ts +17 -0
  78. package/src/internal/router-plugin/core/hmr/select-adapter.js +24 -0
  79. package/src/internal/router-plugin/core/hmr/vite-adapter.d.ts +18 -0
  80. package/src/internal/router-plugin/core/hmr/vite-adapter.js +73 -0
  81. package/src/internal/router-plugin/core/hmr/webpack-adapter.d.ts +22 -0
  82. package/src/internal/router-plugin/core/hmr/webpack-adapter.js +78 -0
  83. package/src/internal/router-plugin/core/router-code-splitter-plugin.d.ts +10 -0
  84. package/src/internal/router-plugin/core/router-code-splitter-plugin.js +244 -0
  85. package/src/internal/router-plugin/core/router-composed-plugin.d.ts +5 -0
  86. package/src/internal/router-plugin/core/router-composed-plugin.js +62 -0
  87. package/src/internal/router-plugin/core/router-generator-plugin.d.ts +10 -0
  88. package/src/internal/router-plugin/core/router-generator-plugin.js +125 -0
  89. package/src/internal/router-plugin/core/router-hmr-plugin.d.ts +13 -0
  90. package/src/internal/router-plugin/core/router-hmr-plugin.js +101 -0
  91. package/src/internal/router-plugin/core/router-plugin-context.d.ts +5 -0
  92. package/src/internal/router-plugin/core/router-plugin-context.js +6 -0
  93. package/src/internal/router-plugin/core/utils.d.ts +17 -0
  94. package/src/internal/router-plugin/core/utils.js +47 -0
  95. package/src/internal/router-plugin/esbuild.d.ts +197 -0
  96. package/src/internal/router-plugin/esbuild.js +58 -0
  97. package/src/internal/router-plugin/index.d.ts +19 -0
  98. package/src/internal/router-plugin/index.js +17 -0
  99. package/src/internal/router-plugin/rspack.d.ts +61 -0
  100. package/src/internal/router-plugin/rspack.js +92 -0
  101. package/src/internal/router-plugin/vite.d.ts +201 -0
  102. package/src/internal/router-plugin/vite.js +62 -0
  103. package/src/internal/router-plugin/webpack.d.ts +50 -0
  104. package/src/internal/router-plugin/webpack.js +77 -0
  105. package/src/internal/start-plugin-core/build-sitemap.d.ts +34 -0
  106. package/src/internal/start-plugin-core/build-sitemap.js +125 -0
  107. package/src/internal/start-plugin-core/config-context.d.ts +30 -0
  108. package/src/internal/start-plugin-core/config-context.js +89 -0
  109. package/src/internal/start-plugin-core/constants.d.ts +20 -0
  110. package/src/internal/start-plugin-core/constants.js +24 -0
  111. package/src/internal/start-plugin-core/debug.d.ts +1 -0
  112. package/src/internal/start-plugin-core/hydrate-when-transform.d.ts +5 -0
  113. package/src/internal/start-plugin-core/hydrate-when-transform.js +661 -0
  114. package/src/internal/start-plugin-core/hydration-constants.d.ts +1 -0
  115. package/src/internal/start-plugin-core/hydration-constants.js +4 -0
  116. package/src/internal/start-plugin-core/import-protection/adapterUtils.d.ts +40 -0
  117. package/src/internal/start-plugin-core/import-protection/adapterUtils.js +42 -0
  118. package/src/internal/start-plugin-core/import-protection/analysis.d.ts +63 -0
  119. package/src/internal/start-plugin-core/import-protection/analysis.js +533 -0
  120. package/src/internal/start-plugin-core/import-protection/constants.d.ts +11 -0
  121. package/src/internal/start-plugin-core/import-protection/constants.js +39 -0
  122. package/src/internal/start-plugin-core/import-protection/defaults.d.ts +19 -0
  123. package/src/internal/start-plugin-core/import-protection/defaults.js +34 -0
  124. package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.d.ts +22 -0
  125. package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.js +94 -0
  126. package/src/internal/start-plugin-core/import-protection/matchers.d.ts +18 -0
  127. package/src/internal/start-plugin-core/import-protection/matchers.js +39 -0
  128. package/src/internal/start-plugin-core/import-protection/rewrite.d.ts +29 -0
  129. package/src/internal/start-plugin-core/import-protection/rewrite.js +184 -0
  130. package/src/internal/start-plugin-core/import-protection/sourceLocation.d.ts +170 -0
  131. package/src/internal/start-plugin-core/import-protection/sourceLocation.js +376 -0
  132. package/src/internal/start-plugin-core/import-protection/trace.d.ts +89 -0
  133. package/src/internal/start-plugin-core/import-protection/trace.js +186 -0
  134. package/src/internal/start-plugin-core/import-protection/utils.d.ts +78 -0
  135. package/src/internal/start-plugin-core/import-protection/utils.js +171 -0
  136. package/src/internal/start-plugin-core/import-protection/virtualModules.d.ts +38 -0
  137. package/src/internal/start-plugin-core/import-protection/virtualModules.js +241 -0
  138. package/src/internal/start-plugin-core/index.d.ts +8 -0
  139. package/src/internal/start-plugin-core/index.js +2 -0
  140. package/src/internal/start-plugin-core/planning.d.ts +44 -0
  141. package/src/internal/start-plugin-core/planning.js +98 -0
  142. package/src/internal/start-plugin-core/post-build.d.ts +12 -0
  143. package/src/internal/start-plugin-core/post-build.js +40 -0
  144. package/src/internal/start-plugin-core/prerender.d.ts +17 -0
  145. package/src/internal/start-plugin-core/prerender.js +172 -0
  146. package/src/internal/start-plugin-core/queue.d.ts +37 -0
  147. package/src/internal/start-plugin-core/queue.js +118 -0
  148. package/src/internal/start-plugin-core/resolve-entries.d.ts +10 -0
  149. package/src/internal/start-plugin-core/resolve-entries.js +32 -0
  150. package/src/internal/start-plugin-core/schema.d.ts +1799 -0
  151. package/src/internal/start-plugin-core/schema.js +252 -0
  152. package/src/internal/start-plugin-core/serialization-adapters-module.d.ts +18 -0
  153. package/src/internal/start-plugin-core/serialization-adapters-module.js +37 -0
  154. package/src/internal/start-plugin-core/start-compiler/compiler.d.ts +181 -0
  155. package/src/internal/start-plugin-core/start-compiler/compiler.js +1078 -0
  156. package/src/internal/start-plugin-core/start-compiler/config.d.ts +20 -0
  157. package/src/internal/start-plugin-core/start-compiler/config.js +84 -0
  158. package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.d.ts +24 -0
  159. package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.js +25 -0
  160. package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.d.ts +11 -0
  161. package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.js +24 -0
  162. package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.d.ts +11 -0
  163. package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.js +35 -0
  164. package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.d.ts +22 -0
  165. package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.js +292 -0
  166. package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.d.ts +14 -0
  167. package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.js +41 -0
  168. package/src/internal/start-plugin-core/start-compiler/host.d.ts +44 -0
  169. package/src/internal/start-plugin-core/start-compiler/host.js +75 -0
  170. package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.d.ts +10 -0
  171. package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.js +87 -0
  172. package/src/internal/start-plugin-core/start-compiler/types.d.ts +119 -0
  173. package/src/internal/start-plugin-core/start-compiler/utils.d.ts +27 -0
  174. package/src/internal/start-plugin-core/start-compiler/utils.js +36 -0
  175. package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.d.ts +16 -0
  176. package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.js +131 -0
  177. package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.d.ts +64 -0
  178. package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.js +441 -0
  179. package/src/internal/start-plugin-core/start-router-plugin/constants.d.ts +1 -0
  180. package/src/internal/start-plugin-core/start-router-plugin/constants.js +4 -0
  181. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.d.ts +6 -0
  182. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.js +6 -0
  183. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.d.ts +6 -0
  184. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.js +27 -0
  185. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
  186. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.js +34 -0
  187. package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.d.ts +11 -0
  188. package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.js +42 -0
  189. package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.d.ts +6 -0
  190. package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.js +59 -0
  191. package/src/internal/start-plugin-core/types.d.ts +135 -0
  192. package/src/internal/start-plugin-core/types.js +4 -0
  193. package/src/internal/start-plugin-core/utils.d.ts +13 -0
  194. package/src/internal/start-plugin-core/utils.js +42 -0
  195. package/src/internal/start-plugin-core/vite/createVirtualModule.d.ts +15 -0
  196. package/src/internal/start-plugin-core/vite/createVirtualModule.js +27 -0
  197. package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.d.ts +26 -0
  198. package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.js +165 -0
  199. package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.d.ts +11 -0
  200. package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.js +170 -0
  201. package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.d.ts +4 -0
  202. package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.js +1553 -0
  203. package/src/internal/start-plugin-core/vite/import-protection-plugin/types.d.ts +103 -0
  204. package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.d.ts +40 -0
  205. package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.js +68 -0
  206. package/src/internal/start-plugin-core/vite/index.d.ts +13 -0
  207. package/src/internal/start-plugin-core/vite/index.js +4 -0
  208. package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.d.ts +2 -0
  209. package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.js +13 -0
  210. package/src/internal/start-plugin-core/vite/output-directory.d.ts +7 -0
  211. package/src/internal/start-plugin-core/vite/output-directory.js +18 -0
  212. package/src/internal/start-plugin-core/vite/planning.d.ts +112 -0
  213. package/src/internal/start-plugin-core/vite/planning.js +152 -0
  214. package/src/internal/start-plugin-core/vite/plugin.d.ts +7 -0
  215. package/src/internal/start-plugin-core/vite/plugin.js +208 -0
  216. package/src/internal/start-plugin-core/vite/plugins.d.ts +17 -0
  217. package/src/internal/start-plugin-core/vite/plugins.js +72 -0
  218. package/src/internal/start-plugin-core/vite/post-server-build.d.ts +9 -0
  219. package/src/internal/start-plugin-core/vite/post-server-build.js +22 -0
  220. package/src/internal/start-plugin-core/vite/prerender.d.ts +9 -0
  221. package/src/internal/start-plugin-core/vite/prerender.js +52 -0
  222. package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.d.ts +2 -0
  223. package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.js +54 -0
  224. package/src/internal/start-plugin-core/vite/schema.d.ts +2423 -0
  225. package/src/internal/start-plugin-core/vite/schema.js +17 -0
  226. package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.d.ts +5 -0
  227. package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.js +63 -0
  228. package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.d.ts +5 -0
  229. package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.js +14 -0
  230. package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.d.ts +5 -0
  231. package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.js +25 -0
  232. package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.d.ts +29 -0
  233. package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.js +380 -0
  234. package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.d.ts +11 -0
  235. package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.js +114 -0
  236. package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.d.ts +3 -0
  237. package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.js +103 -0
  238. package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.d.ts +9 -0
  239. package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.js +143 -0
  240. package/src/internal/start-plugin-core/vite/types.d.ts +17 -0
  241. package/src/package-names.js +10 -0
  242. package/src/plugin-vite.d.ts +23 -0
  243. package/src/plugin-vite.js +62 -0
  244. package/src/runtime/client/StartClient.d.ts +11 -0
  245. package/src/runtime/client/StartClient.js +16 -0
  246. package/src/runtime/client/hydrateStart.d.ts +4 -0
  247. package/src/runtime/client/hydrateStart.js +30 -0
  248. package/src/runtime/server/StartServer.d.ts +10 -0
  249. package/src/runtime/server/StartServer.js +6 -0
  250. package/src/runtime/server/defaultRenderHandler.d.ts +3 -0
  251. package/src/runtime/server/defaultRenderHandler.js +11 -0
  252. package/src/runtime/server/defaultStreamHandler.d.ts +3 -0
  253. package/src/runtime/server/defaultStreamHandler.js +13 -0
  254. package/src/server-entry.d.ts +11 -0
  255. package/src/server-entry.js +13 -0
  256. package/src/server-only.d.ts +1 -0
  257. package/src/server-only.js +0 -0
  258. package/src/server-rpc.d.ts +1 -0
  259. package/src/server-rpc.js +1 -0
  260. package/src/server.d.ts +6 -0
  261. package/src/server.js +4 -0
  262. package/src/ssr-rpc.d.ts +1 -0
  263. package/src/ssr-rpc.js +1 -0
  264. package/src/use-server-fn.d.ts +3 -0
  265. package/src/use-server-fn.js +18 -0
  266. package/src/validate-options.js +7 -0
@@ -0,0 +1,17 @@
1
+ import {
2
+ parseStartConfig as parseStartConfig$1,
3
+ tanstackStartOptionsObjectSchema,
4
+ } from '../schema.js';
5
+ import { z } from 'zod';
6
+ //#region src/vite/schema.ts
7
+ var tanstackStartViteOptionsSchema = tanstackStartOptionsObjectSchema
8
+ .extend({ vite: z.object({ installDevServerMiddleware: z.boolean().optional() }).optional() })
9
+ .optional()
10
+ .prefault({});
11
+ function parseStartConfig(opts, corePluginOpts, root) {
12
+ tanstackStartViteOptionsSchema.parse(opts);
13
+ const { vite: _vite, ...coreOptions } = opts ?? {};
14
+ return parseStartConfig$1(coreOptions, corePluginOpts, root);
15
+ }
16
+ //#endregion
17
+ export { parseStartConfig };
@@ -0,0 +1,5 @@
1
+ import { SerializationAdapterConfig } from '../types.js';
2
+ import { PluginOption } from 'vite';
3
+ export declare function serializationAdaptersPlugin(opts: {
4
+ adapters: Array<SerializationAdapterConfig> | undefined;
5
+ }): PluginOption;
@@ -0,0 +1,63 @@
1
+ import { START_ENVIRONMENT_NAMES } from '../constants.js';
2
+ import { createIdFilter } from '../utils.js';
3
+ import { generateSerializationAdaptersModule } from '../serialization-adapters-module.js';
4
+ import { VIRTUAL_MODULES } from '@tanstack/start-server-core';
5
+ //#region src/vite/serialization-adapters-plugin.ts
6
+ var CLIENT_MODULE_ID = 'virtual:tanstack-start-plugin-adapters/client';
7
+ var SERVER_MODULE_ID = 'virtual:tanstack-start-plugin-adapters/server';
8
+ var BUILD_CLIENT_MODULE_ID = `\0${CLIENT_MODULE_ID}`;
9
+ var BUILD_SERVER_MODULE_ID = `\0${SERVER_MODULE_ID}`;
10
+ var MODULE_IDS = [
11
+ CLIENT_MODULE_ID,
12
+ SERVER_MODULE_ID,
13
+ BUILD_CLIENT_MODULE_ID,
14
+ BUILD_SERVER_MODULE_ID,
15
+ ];
16
+ var moduleIdFilter = createIdFilter(MODULE_IDS);
17
+ var resolveIdFilter = createIdFilter([VIRTUAL_MODULES.pluginAdapters, ...MODULE_IDS]);
18
+ function serializationAdaptersPlugin(opts) {
19
+ return {
20
+ name: 'tanstack-start:plugin-adapters',
21
+ enforce: 'pre',
22
+ resolveId: {
23
+ filter: { id: resolveIdFilter },
24
+ handler(id) {
25
+ if (getRuntime(id)) return id;
26
+ if (id !== VIRTUAL_MODULES.pluginAdapters) return;
27
+ return getModuleId(
28
+ this.environment.name === START_ENVIRONMENT_NAMES.client ? 'client' : 'server',
29
+ this.environment.config.command,
30
+ );
31
+ },
32
+ },
33
+ load: {
34
+ filter: { id: moduleIdFilter },
35
+ handler(id) {
36
+ const runtime = getRuntime(id);
37
+ if (!runtime) return;
38
+ return generateSerializationAdaptersModule({
39
+ adapters: opts.adapters,
40
+ runtime,
41
+ });
42
+ },
43
+ },
44
+ };
45
+ }
46
+ function getModuleId(runtime, command) {
47
+ if (runtime === 'client') return command === 'serve' ? CLIENT_MODULE_ID : BUILD_CLIENT_MODULE_ID;
48
+ return command === 'serve' ? SERVER_MODULE_ID : BUILD_SERVER_MODULE_ID;
49
+ }
50
+ function getRuntime(id) {
51
+ switch (id) {
52
+ case CLIENT_MODULE_ID:
53
+ case BUILD_CLIENT_MODULE_ID:
54
+ return 'client';
55
+ case SERVER_MODULE_ID:
56
+ case BUILD_SERVER_MODULE_ID:
57
+ return 'server';
58
+ default:
59
+ return;
60
+ }
61
+ }
62
+ //#endregion
63
+ export { serializationAdaptersPlugin };
@@ -0,0 +1,5 @@
1
+ import { EnvironmentModuleNode } from 'vite';
2
+ export declare function mergeHotUpdateModules(
3
+ currentModules: Array<EnvironmentModuleNode>,
4
+ additionalModules: Array<EnvironmentModuleNode>,
5
+ ): Array<EnvironmentModuleNode> | undefined;
@@ -0,0 +1,14 @@
1
+ //#region src/vite/start-compiler-plugin/hot-update.ts
2
+ function mergeHotUpdateModules(currentModules, additionalModules) {
3
+ if (additionalModules.length === 0) return;
4
+ const mergedModules = currentModules.slice();
5
+ const seenModules = new Set(currentModules);
6
+ for (const mod of additionalModules) {
7
+ if (seenModules.has(mod)) continue;
8
+ seenModules.add(mod);
9
+ mergedModules.push(mod);
10
+ }
11
+ return mergedModules;
12
+ }
13
+ //#endregion
14
+ export { mergeHotUpdateModules };
@@ -0,0 +1,5 @@
1
+ import { DevServerFnModuleSpecifierEncoder } from '../../start-compiler/types.js';
2
+ export declare function createViteDevServerFnModuleSpecifierEncoder(
3
+ root: string,
4
+ ): DevServerFnModuleSpecifierEncoder;
5
+ export declare function decodeViteDevServerModuleSpecifier(moduleSpecifier: string): string;
@@ -0,0 +1,25 @@
1
+ //#region src/vite/start-compiler-plugin/module-specifier.ts
2
+ function createViteDevServerFnModuleSpecifierEncoder(root) {
3
+ const normalizedRoot = root.replace(/\\/g, '/');
4
+ const rootWithTrailingSlash = normalizedRoot.endsWith('/')
5
+ ? normalizedRoot
6
+ : `${normalizedRoot}/`;
7
+ return ({ extractedFilename }) => {
8
+ const normalizedFile = extractedFilename.replace(/\\/g, '/');
9
+ if (normalizedFile.startsWith(rootWithTrailingSlash))
10
+ return `/${normalizedFile.slice(rootWithTrailingSlash.length)}`;
11
+ return normalizedFile.startsWith('/') ? `/@fs${normalizedFile}` : `/@fs/${normalizedFile}`;
12
+ };
13
+ }
14
+ function decodeViteDevServerModuleSpecifier(moduleSpecifier) {
15
+ let sourceFile = moduleSpecifier;
16
+ if (sourceFile.startsWith('/@id/')) sourceFile = sourceFile.slice(5);
17
+ else if (sourceFile.startsWith('/@fs/')) {
18
+ sourceFile = sourceFile.slice(4);
19
+ sourceFile = sourceFile.replace(/^\/([A-Za-z]:\/)/, '$1');
20
+ } else if (sourceFile.startsWith('/')) sourceFile = sourceFile.slice(1);
21
+ const queryIndex = sourceFile.indexOf('?');
22
+ return queryIndex === -1 ? sourceFile : sourceFile.slice(0, queryIndex);
23
+ }
24
+ //#endregion
25
+ export { createViteDevServerFnModuleSpecifierEncoder, decodeViteDevServerModuleSpecifier };
@@ -0,0 +1,29 @@
1
+ import { SERVER_FN_LOOKUP } from '../../constants.js';
2
+ import {
3
+ CompileStartFrameworkOptions,
4
+ StartCompilerImportTransform,
5
+ StartCompilerPlugin,
6
+ } from '../../types.js';
7
+ import { GenerateFunctionIdFnOptional } from '../../start-compiler/types.js';
8
+ import { PluginOption } from 'vite';
9
+ export { SERVER_FN_LOOKUP };
10
+ export interface StartCompilerPluginOptions {
11
+ framework: CompileStartFrameworkOptions;
12
+ environments: Array<{
13
+ name: string;
14
+ type: 'client' | 'server';
15
+ getServerFnById?: string;
16
+ }>;
17
+ /**
18
+ * Custom function ID generator (optional).
19
+ */
20
+ generateFunctionId?: GenerateFunctionIdFnOptional;
21
+ compilerTransforms?: Array<StartCompilerImportTransform> | undefined;
22
+ compilerPlugins?: Array<StartCompilerPlugin> | undefined;
23
+ serverFnProviderModuleDirectives?: ReadonlyArray<string> | undefined;
24
+ /**
25
+ * The Vite environment name for the server function provider.
26
+ */
27
+ providerEnvName: string;
28
+ }
29
+ export declare function startCompilerPlugin(opts: StartCompilerPluginOptions): PluginOption;
@@ -0,0 +1,380 @@
1
+ import { SERVER_FN_LOOKUP, TRANSFORM_ID_REGEX, VITE_ENVIRONMENT_NAMES } from '../../constants.js';
2
+ import { resolveViteId } from '../../utils.js';
3
+ import { createVirtualModule } from '../createVirtualModule.js';
4
+ import { cleanId } from '../../start-compiler/utils.js';
5
+ import { detectKindsInCode } from '../../start-compiler/compiler.js';
6
+ import { getTransformCodeFilterForEnv } from '../../start-compiler/config.js';
7
+ import {
8
+ createCompilerVirtualModuleIdPattern,
9
+ createStartCompiler,
10
+ loadCompilerVirtualModule,
11
+ mergeServerFnsById,
12
+ } from '../../start-compiler/host.js';
13
+ import { generateServerFnResolverModule } from '../../start-compiler/server-fn-resolver-module.js';
14
+ import {
15
+ MissingHydrateSourceError,
16
+ createHydrateCompilerPlugin,
17
+ } from '../../hydrate-when-transform.js';
18
+ import {
19
+ createViteDevServerFnModuleSpecifierEncoder,
20
+ decodeViteDevServerModuleSpecifier,
21
+ } from './module-specifier.js';
22
+ import { mergeHotUpdateModules } from './hot-update.js';
23
+ import { resolve } from 'pathe';
24
+ import { VIRTUAL_MODULES } from '@tanstack/start-server-core';
25
+ //#region src/vite/start-compiler-plugin/plugin.ts
26
+ var validateServerFnIdVirtualModule = `virtual:tanstack-start-validate-server-fn-id`;
27
+ var TSS_SERVERFN_SPLIT_PARAM = 'tss-serverfn-split';
28
+ async function loadViteModuleFromEnvironment(environment, id, opts) {
29
+ if (environment.mode === 'build') return (await opts.load({ id }))?.code ?? '';
30
+ if (environment.mode === 'dev') {
31
+ await environment.transformRequest(opts.devId ?? id);
32
+ return;
33
+ }
34
+ opts.error(`could not load module ${id}: unknown environment mode ${environment.mode}`);
35
+ }
36
+ function invalidateMatchingFileModules(environment, ids, shouldInvalidate) {
37
+ const seen = /* @__PURE__ */ new Set();
38
+ const invalidatedModules = [];
39
+ for (const id of ids) {
40
+ const fileModules = environment.moduleGraph.getModulesByFile(cleanId(id));
41
+ if (!fileModules) continue;
42
+ for (const fileModule of fileModules) {
43
+ if (!shouldInvalidate(fileModule)) continue;
44
+ environment.moduleGraph.invalidateModule(fileModule, seen);
45
+ invalidatedModules.push(fileModule);
46
+ }
47
+ }
48
+ return invalidatedModules;
49
+ }
50
+ function invalidateServerFnProviderModules(environment, ids) {
51
+ return invalidateMatchingFileModules(
52
+ environment,
53
+ ids,
54
+ (fileModule) => fileModule.id?.includes(TSS_SERVERFN_SPLIT_PARAM) ?? false,
55
+ );
56
+ }
57
+ function invalidateServerFnLookupModules(environment, ids) {
58
+ invalidateMatchingFileModules(
59
+ environment,
60
+ ids,
61
+ (fileModule) => fileModule.id?.includes('server-fn-module-lookup') ?? false,
62
+ );
63
+ }
64
+ function invalidateCompilerVirtualModules(environment, ids, pattern) {
65
+ if (!pattern) return [];
66
+ return invalidateMatchingFileModules(environment, ids, (fileModule) => {
67
+ if (!fileModule.id) return false;
68
+ pattern.lastIndex = 0;
69
+ return pattern.test(fileModule.id);
70
+ });
71
+ }
72
+ function getServerFnProviderIds(ids) {
73
+ const providerIds = /* @__PURE__ */ new Set();
74
+ for (const id of ids) {
75
+ const cleanedId = cleanId(id);
76
+ providerIds.add(`${cleanedId}?${TSS_SERVERFN_SPLIT_PARAM}`);
77
+ }
78
+ return providerIds;
79
+ }
80
+ function invalidateModuleNodes(environment, modules) {
81
+ const seen = /* @__PURE__ */ new Set();
82
+ for (const mod of modules) environment.moduleGraph.invalidateModule(mod, seen);
83
+ }
84
+ function getDevServerFnValidatorModule() {
85
+ return `
86
+ export async function getServerFnById(id, _access) {
87
+ const validateIdImport = ${JSON.stringify(validateServerFnIdVirtualModule)} + '?id=' + id
88
+ await import(/* @vite-ignore */ '/@id/__x00__' + validateIdImport)
89
+ const decoded = Buffer.from(id, 'base64url').toString('utf8')
90
+ const devServerFn = JSON.parse(decoded)
91
+ const mod = await import(/* @vite-ignore */ devServerFn.file)
92
+ return mod[devServerFn.export]
93
+ }
94
+ `;
95
+ }
96
+ function parseIdQuery(id) {
97
+ if (!id.includes('?'))
98
+ return {
99
+ filename: id,
100
+ query: {},
101
+ };
102
+ const [filename, rawQuery] = id.split(`?`, 2);
103
+ return {
104
+ filename,
105
+ query: Object.fromEntries(new URLSearchParams(rawQuery)),
106
+ };
107
+ }
108
+ function startCompilerPlugin(opts) {
109
+ const compilers = /* @__PURE__ */ new Map();
110
+ const compilerPlugins = [createHydrateCompilerPlugin(), ...(opts.compilerPlugins ?? [])];
111
+ const compilerVirtualModuleIdPattern = createCompilerVirtualModuleIdPattern(compilerPlugins);
112
+ const environmentByName = new Map(
113
+ opts.environments.map((environment) => [environment.name, environment]),
114
+ );
115
+ const serverFnsById = {};
116
+ const onServerFnsById = (d) => {
117
+ mergeServerFnsById(serverFnsById, d);
118
+ };
119
+ let root = process.cwd();
120
+ let bundledDev = false;
121
+ const ssrEnvName = VITE_ENVIRONMENT_NAMES.server;
122
+ const ssrIsProvider = opts.providerEnvName === ssrEnvName;
123
+ const appliedResolverEnvironments = new Set(
124
+ ssrIsProvider ? [opts.providerEnvName] : [ssrEnvName, opts.providerEnvName],
125
+ );
126
+ function perEnvServerFnPlugin(environment) {
127
+ const compilerTransforms =
128
+ environment.name === opts.providerEnvName ? opts.compilerTransforms : void 0;
129
+ const serverFnProviderModuleDirectives =
130
+ environment.name === opts.providerEnvName ? opts.serverFnProviderModuleDirectives : void 0;
131
+ const transformCodeFilter = getTransformCodeFilterForEnv(environment.type, {
132
+ compilerTransforms,
133
+ compilerPlugins,
134
+ });
135
+ return {
136
+ name: `tanstack-start-core::server-fn:${environment.name}`,
137
+ enforce: 'pre',
138
+ applyToEnvironment(env) {
139
+ return env.name === environment.name;
140
+ },
141
+ configResolved(config) {
142
+ root = config.root;
143
+ bundledDev = !!config.experimental.bundledDev;
144
+ },
145
+ buildStart() {
146
+ if (
147
+ this.environment.mode === 'build' ||
148
+ (bundledDev && this.environment.name === VITE_ENVIRONMENT_NAMES.client)
149
+ )
150
+ compilers.delete(this.environment.name);
151
+ },
152
+ watchChange(id) {
153
+ if (bundledDev && this.environment.mode === 'dev')
154
+ compilers.get(this.environment.name)?.invalidateModule(id);
155
+ },
156
+ transform: {
157
+ filter: {
158
+ id: {
159
+ exclude: new RegExp(`${SERVER_FN_LOOKUP}$`),
160
+ include: TRANSFORM_ID_REGEX,
161
+ },
162
+ code: { include: transformCodeFilter },
163
+ },
164
+ async handler(code, id) {
165
+ let compiler = compilers.get(this.environment.name);
166
+ if (!compiler) {
167
+ const mode = this.environment.mode === 'build' ? 'build' : 'dev';
168
+ compiler = createStartCompiler({
169
+ env: environment.type,
170
+ envName: environment.name,
171
+ root,
172
+ mode,
173
+ framework: opts.framework,
174
+ providerEnvName: opts.providerEnvName,
175
+ generateFunctionId: opts.generateFunctionId,
176
+ compilerTransforms,
177
+ compilerPlugins,
178
+ serverFnProviderModuleDirectives,
179
+ onServerFnsById,
180
+ getKnownServerFns: () => serverFnsById,
181
+ encodeModuleSpecifierInDev:
182
+ mode === 'dev' ? createViteDevServerFnModuleSpecifierEncoder(root) : void 0,
183
+ loadModule: async (id) => {
184
+ const code = await loadViteModuleFromEnvironment(this.environment, id, {
185
+ load: (options) => this.load(options),
186
+ error: (message) => this.error(message),
187
+ devId: `${id}?${SERVER_FN_LOOKUP}`,
188
+ });
189
+ if (code !== void 0)
190
+ compiler.ingestModule({
191
+ code,
192
+ id,
193
+ });
194
+ },
195
+ resolveId: async (source, importer) => {
196
+ const r = await this.resolve(source, importer);
197
+ if (r) {
198
+ if (!r.external) return cleanId(r.id);
199
+ }
200
+ return null;
201
+ },
202
+ });
203
+ compilers.set(this.environment.name, compiler);
204
+ }
205
+ const detectedKinds = detectKindsInCode(code, environment.type, { compilerTransforms });
206
+ return await compiler.compile({
207
+ id,
208
+ code,
209
+ detectedKinds,
210
+ warn: (message) => this.warn(message),
211
+ });
212
+ },
213
+ },
214
+ hotUpdate(ctx) {
215
+ const compiler = compilers.get(this.environment.name);
216
+ const idsToInvalidate = /* @__PURE__ */ new Set();
217
+ const transitiveCompilerImportersToInvalidate = /* @__PURE__ */ new Set();
218
+ const importerModulesToInvalidate = /* @__PURE__ */ new Set();
219
+ const changedIds = [];
220
+ ctx.modules.forEach((m) => {
221
+ if (m.id) {
222
+ idsToInvalidate.add(m.id);
223
+ changedIds.push(m.id);
224
+ }
225
+ });
226
+ const deletedIds = compiler?.invalidateModules(changedIds) ?? /* @__PURE__ */ new Set();
227
+ ctx.modules.forEach((m) => {
228
+ if (m.id) {
229
+ if (deletedIds.has(cleanId(m.id))) {
230
+ transitiveCompilerImportersToInvalidate.add(cleanId(m.id));
231
+ m.importers.forEach((importer) => {
232
+ if (importer.id) {
233
+ idsToInvalidate.add(importer.id);
234
+ importerModulesToInvalidate.add(importer);
235
+ transitiveCompilerImportersToInvalidate.add(cleanId(importer.id));
236
+ }
237
+ });
238
+ }
239
+ }
240
+ });
241
+ const finishHotUpdate = async () => {
242
+ if (
243
+ environment.type === 'server' &&
244
+ compiler &&
245
+ transitiveCompilerImportersToInvalidate.size > 0
246
+ ) {
247
+ const seenImporters = new Set(transitiveCompilerImportersToInvalidate);
248
+ const nestedImporters = await compiler.getTransitiveImporters(seenImporters);
249
+ for (const nestedImporterId of nestedImporters) seenImporters.add(nestedImporterId);
250
+ for (const importerId of seenImporters) idsToInvalidate.add(importerId);
251
+ compiler.invalidateModules(seenImporters);
252
+ }
253
+ invalidateModuleNodes(this.environment, importerModulesToInvalidate);
254
+ invalidateServerFnLookupModules(this.environment, idsToInvalidate);
255
+ const compilerVirtualModules = invalidateCompilerVirtualModules(
256
+ this.environment,
257
+ idsToInvalidate,
258
+ compilerVirtualModuleIdPattern,
259
+ );
260
+ if (environment.type !== 'server')
261
+ return mergeHotUpdateModules(ctx.modules, compilerVirtualModules);
262
+ invalidateModuleNodes(this.environment, ctx.modules);
263
+ const providerIdsToInvalidate = getServerFnProviderIds(idsToInvalidate);
264
+ compiler?.invalidateModules(providerIdsToInvalidate);
265
+ const providerModules = invalidateServerFnProviderModules(this.environment, [
266
+ ...idsToInvalidate,
267
+ ...providerIdsToInvalidate,
268
+ ]);
269
+ return mergeHotUpdateModules(ctx.modules, [
270
+ ...compilerVirtualModules,
271
+ ...providerModules,
272
+ ]);
273
+ };
274
+ return finishHotUpdate();
275
+ },
276
+ };
277
+ }
278
+ return [
279
+ ...opts.environments.map(perEnvServerFnPlugin),
280
+ {
281
+ name: 'tanstack-start-core:capture-server-fn-module-lookup',
282
+ apply: 'serve',
283
+ applyToEnvironment(env) {
284
+ return !!opts.environments.find((e) => e.name === env.name);
285
+ },
286
+ transform: {
287
+ filter: { id: new RegExp(`${SERVER_FN_LOOKUP}$`) },
288
+ handler(code, id) {
289
+ compilers.get(this.environment.name)?.ingestModule({
290
+ code,
291
+ id: cleanId(id),
292
+ });
293
+ },
294
+ },
295
+ },
296
+ {
297
+ name: 'tanstack-start-core:compiler-virtual-module',
298
+ enforce: 'pre',
299
+ load: {
300
+ filter: { id: compilerVirtualModuleIdPattern ?? /$^/ },
301
+ async handler(id) {
302
+ const environment = environmentByName.get(this.environment.name);
303
+ if (!environment || !compilerVirtualModuleIdPattern) return null;
304
+ const loadVirtualModule = () =>
305
+ loadCompilerVirtualModule(compilerPlugins, {
306
+ id,
307
+ root,
308
+ env: environment.type,
309
+ envName: this.environment.name,
310
+ });
311
+ try {
312
+ return loadVirtualModule();
313
+ } catch (error) {
314
+ if (!(error instanceof MissingHydrateSourceError)) throw error;
315
+ }
316
+ const sourceId = cleanId(id);
317
+ await loadViteModuleFromEnvironment(this.environment, sourceId, {
318
+ load: (options) => this.load(options),
319
+ error: (message) => this.error(message),
320
+ });
321
+ return loadVirtualModule();
322
+ },
323
+ },
324
+ },
325
+ {
326
+ name: 'tanstack-start-core:validate-server-fn-id',
327
+ apply: 'serve',
328
+ load: {
329
+ filter: { id: new RegExp(resolveViteId(validateServerFnIdVirtualModule)) },
330
+ async handler(id) {
331
+ const fnId = parseIdQuery(id).query.id;
332
+ if (fnId && serverFnsById[fnId]) return `export {}`;
333
+ if (fnId)
334
+ try {
335
+ const decoded = JSON.parse(Buffer.from(fnId, 'base64url').toString('utf8'));
336
+ if (typeof decoded.file === 'string' && typeof decoded.export === 'string') {
337
+ const sourceFile = decodeViteDevServerModuleSpecifier(decoded.file);
338
+ if (sourceFile) {
339
+ const absPath = resolve(root, sourceFile);
340
+ if (this.environment.mode !== 'dev')
341
+ this.error(
342
+ `could not validate server function ID ${fnId}: unknown environment mode ${this.environment.mode}`,
343
+ );
344
+ await this.environment.transformRequest(`${absPath}?${SERVER_FN_LOOKUP}`);
345
+ if (serverFnsById[fnId]) return `export {}`;
346
+ }
347
+ }
348
+ } catch {}
349
+ this.error(`Invalid server function ID: ${fnId}`);
350
+ },
351
+ },
352
+ },
353
+ createVirtualModule({
354
+ name: 'tanstack-start-core:server-fn-resolver',
355
+ moduleId: VIRTUAL_MODULES.serverFnResolver,
356
+ enforce: 'pre',
357
+ applyToEnvironment: (env) => {
358
+ return appliedResolverEnvironments.has(env.name);
359
+ },
360
+ load() {
361
+ if (this.environment.name !== opts.providerEnvName) {
362
+ const mod = opts.environments.find(
363
+ (e) => e.name === this.environment.name,
364
+ )?.getServerFnById;
365
+ if (mod) return mod;
366
+ this.error(
367
+ `No getServerFnById implementation found for caller environment: ${this.environment.name}`,
368
+ );
369
+ }
370
+ if (this.environment.mode !== 'build') return getDevServerFnValidatorModule();
371
+ return generateServerFnResolverModule({
372
+ serverFnsById,
373
+ includeClientReferencedCheck: !ssrIsProvider,
374
+ });
375
+ },
376
+ }),
377
+ ];
378
+ }
379
+ //#endregion
380
+ export { startCompilerPlugin };
@@ -0,0 +1,11 @@
1
+ import { Rollup } from 'vite';
2
+ import { NormalizedClientBuild, NormalizedClientChunk } from '../../types.js';
3
+ export declare function normalizeViteClientChunk(chunk: Rollup.OutputChunk): NormalizedClientChunk;
4
+ export declare function normalizeViteClientChunks(
5
+ clientBundle: Rollup.OutputBundle,
6
+ ): ReadonlyMap<string, NormalizedClientChunk>;
7
+ export declare function normalizeViteClientBuild(
8
+ clientBundle: Rollup.OutputBundle,
9
+ ): NormalizedClientBuild;
10
+ export declare function getRouteFilePathsFromModuleIds(moduleIds: Array<string>): string[];
11
+ export declare function getHydrationIdsFromModuleIds(moduleIds: Array<string>): string[];
@@ -0,0 +1,114 @@
1
+ import { tssHydrate } from '../../hydration-constants.js';
2
+ import { getCssAssetSource } from '../../start-manifest-plugin/inlineCss.js';
3
+ import { tsrSplit } from '#tanstack-start/router-plugin';
4
+ //#region src/vite/start-manifest-plugin/normalized-client-build.ts
5
+ function normalizeViteClientChunk(chunk) {
6
+ return {
7
+ fileName: chunk.fileName,
8
+ isEntry: chunk.isEntry,
9
+ imports: chunk.imports,
10
+ dynamicImports: chunk.dynamicImports,
11
+ css: Array.from(chunk.viteMetadata?.importedCss ?? []),
12
+ routeFilePaths: getRouteFilePathsFromModuleIds(chunk.moduleIds),
13
+ hydrationIds: getHydrationIdsFromModuleIds(chunk.moduleIds),
14
+ };
15
+ }
16
+ function normalizeViteClientChunks(clientBundle) {
17
+ const chunksByFileName = /* @__PURE__ */ new Map();
18
+ for (const fileName in clientBundle) {
19
+ const bundleEntry = clientBundle[fileName];
20
+ if (bundleEntry.type !== 'chunk') continue;
21
+ const normalizedChunk = normalizeViteClientChunk(bundleEntry);
22
+ chunksByFileName.set(normalizedChunk.fileName, normalizedChunk);
23
+ }
24
+ return chunksByFileName;
25
+ }
26
+ function normalizeViteClientBuild(clientBundle) {
27
+ let entryChunkFileName;
28
+ const chunksByFileName = normalizeViteClientChunks(clientBundle);
29
+ const chunkFileNamesByRouteFilePath = /* @__PURE__ */ new Map();
30
+ const cssFilesBySourcePath = /* @__PURE__ */ new Map();
31
+ const cssContentByFileName = /* @__PURE__ */ new Map();
32
+ for (const chunk of chunksByFileName.values()) {
33
+ const bundleEntry = clientBundle[chunk.fileName];
34
+ if (chunk.isEntry) {
35
+ if (entryChunkFileName)
36
+ throw new Error(`multiple entries detected: ${entryChunkFileName} ${chunk.fileName}`);
37
+ entryChunkFileName = chunk.fileName;
38
+ }
39
+ for (const routeFilePath of chunk.routeFilePaths) {
40
+ let chunkFileNames = chunkFileNamesByRouteFilePath.get(routeFilePath);
41
+ if (chunkFileNames === void 0) {
42
+ chunkFileNames = [];
43
+ chunkFileNamesByRouteFilePath.set(routeFilePath, chunkFileNames);
44
+ }
45
+ chunkFileNames.push(chunk.fileName);
46
+ }
47
+ for (const moduleId of bundleEntry.moduleIds) {
48
+ const queryIndex = moduleId.indexOf('?');
49
+ const sourcePath = queryIndex >= 0 ? moduleId.slice(0, queryIndex) : moduleId;
50
+ if (!sourcePath) continue;
51
+ const existing = cssFilesBySourcePath.get(sourcePath);
52
+ cssFilesBySourcePath.set(
53
+ sourcePath,
54
+ existing ? Array.from(new Set([...existing, ...chunk.css])) : chunk.css.slice(),
55
+ );
56
+ }
57
+ }
58
+ for (const fileName in clientBundle) {
59
+ if (!fileName.endsWith('.css')) continue;
60
+ const bundleEntry = clientBundle[fileName];
61
+ if (bundleEntry.type !== 'asset') continue;
62
+ const css = getCssAssetSource(bundleEntry.source);
63
+ if (css !== void 0) cssContentByFileName.set(fileName, css);
64
+ }
65
+ if (!entryChunkFileName) throw new Error('No entry file found');
66
+ return {
67
+ entryChunkFileName,
68
+ chunksByFileName,
69
+ chunkFileNamesByRouteFilePath,
70
+ cssFilesBySourcePath,
71
+ cssContentByFileName,
72
+ };
73
+ }
74
+ function getRouteFilePathsFromModuleIds(moduleIds) {
75
+ let routeFilePaths;
76
+ let seenRouteFilePaths;
77
+ for (const moduleId of moduleIds) {
78
+ const queryIndex = moduleId.indexOf('?');
79
+ if (queryIndex < 0) continue;
80
+ const query = moduleId.slice(queryIndex + 1);
81
+ if (!query.includes(tsrSplit)) continue;
82
+ if (!new URLSearchParams(query).has(tsrSplit)) continue;
83
+ const routeFilePath = moduleId.slice(0, queryIndex);
84
+ if (seenRouteFilePaths?.has(routeFilePath)) continue;
85
+ if (routeFilePaths === void 0 || seenRouteFilePaths === void 0) {
86
+ routeFilePaths = [];
87
+ seenRouteFilePaths = /* @__PURE__ */ new Set();
88
+ }
89
+ routeFilePaths.push(routeFilePath);
90
+ seenRouteFilePaths.add(routeFilePath);
91
+ }
92
+ return routeFilePaths ?? [];
93
+ }
94
+ function getHydrationIdsFromModuleIds(moduleIds) {
95
+ let hydrationIds;
96
+ let seen;
97
+ for (const moduleId of moduleIds) {
98
+ const queryIndex = moduleId.indexOf('?');
99
+ if (queryIndex < 0) continue;
100
+ const query = moduleId.slice(queryIndex + 1);
101
+ if (!query.includes('tss-hydrate')) continue;
102
+ const hydrationId = new URLSearchParams(query).get(tssHydrate);
103
+ if (!hydrationId || seen?.has(hydrationId)) continue;
104
+ if (hydrationIds === void 0 || seen === void 0) {
105
+ hydrationIds = [];
106
+ seen = /* @__PURE__ */ new Set();
107
+ }
108
+ hydrationIds.push(hydrationId);
109
+ seen.add(hydrationId);
110
+ }
111
+ return hydrationIds ?? [];
112
+ }
113
+ //#endregion
114
+ export { normalizeViteClientBuild };
@@ -0,0 +1,3 @@
1
+ import { GetConfigFn } from '../../types.js';
2
+ import { PluginOption } from 'vite';
3
+ export declare function startManifestPlugin(opts: { getConfig: GetConfigFn }): PluginOption;