@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,441 @@
1
+ import { processInlineCssUrls } from './inlineCss.js';
2
+ import {
3
+ getStylesheetHref,
4
+ resolveManifestAssetLink,
5
+ resolveManifestCssLink,
6
+ rootRouteId,
7
+ } from '@tanstack/router-core';
8
+ import { joinURL } from 'ufo';
9
+ import { serialize } from 'seroval';
10
+ //#region src/start-manifest-plugin/manifestBuilder.ts
11
+ var VISITING_CHUNK = 1;
12
+ function appendUniqueStrings(target, source) {
13
+ if (source.length === 0) return target;
14
+ if (!target || target.length === 0) return source;
15
+ const seen = new Set(target);
16
+ let result;
17
+ for (const value of source) {
18
+ if (seen.has(value)) continue;
19
+ seen.add(value);
20
+ if (!result) result = target.slice();
21
+ result.push(value);
22
+ }
23
+ return result ?? target;
24
+ }
25
+ function appendUniqueStylesheets(target, source) {
26
+ if (source.length === 0) return target;
27
+ if (!target || target.length === 0) return source;
28
+ const seen = new Set(target.map(getStylesheetIdentity));
29
+ let result;
30
+ for (const stylesheet of source) {
31
+ const identity = getStylesheetIdentity(stylesheet);
32
+ if (seen.has(identity)) continue;
33
+ seen.add(identity);
34
+ if (!result) result = target.slice();
35
+ result.push(stylesheet);
36
+ }
37
+ return result ?? target;
38
+ }
39
+ function getStylesheetIdentity(attrs) {
40
+ const resolved = resolveManifestCssLink(attrs);
41
+ return `${resolved.href}\0${resolved.crossOrigin ?? ''}`;
42
+ }
43
+ function getScriptIdentity(script) {
44
+ return JSON.stringify({
45
+ attrs: normalizeAttrs(script.attrs),
46
+ children: script.children ?? null,
47
+ });
48
+ }
49
+ function normalizeAttrs(attrs) {
50
+ if (!attrs) return null;
51
+ const entries = Object.entries(attrs);
52
+ if (entries.length === 0) return null;
53
+ entries.sort(([left], [right]) => left.localeCompare(right));
54
+ return Object.fromEntries(entries);
55
+ }
56
+ function mergeRouteChunkData(options) {
57
+ const stylesheets = options.getChunkCssAssets(options.chunk);
58
+ const chunkPreloads = options.getChunkPreloads(options.chunk);
59
+ appendRouteStylesheets(options.route, stylesheets);
60
+ options.route.preloads = appendUniqueStrings(options.route.preloads, chunkPreloads);
61
+ }
62
+ function appendRouteStylesheets(route, stylesheets) {
63
+ if (stylesheets.length === 0) return;
64
+ route.css = appendUniqueStylesheets(route.css, stylesheets);
65
+ }
66
+ function appendRouteScripts(route, scripts) {
67
+ if (scripts.length === 0) return;
68
+ route.scripts = [...(route.scripts ?? []), ...scripts];
69
+ }
70
+ function buildScript(src, scriptFormat) {
71
+ return {
72
+ attrs: {
73
+ ...(scriptFormat === 'module' ? { type: 'module' } : {}),
74
+ async: true,
75
+ src,
76
+ },
77
+ };
78
+ }
79
+ function appendEntryChunkScripts(options) {
80
+ const scripts = [];
81
+ if (options.scriptFormat === 'iife')
82
+ for (let i = 0; i < options.chunk.imports.length; i++)
83
+ scripts.push(
84
+ buildScript(options.getAssetPath(options.chunk.imports[i]), options.scriptFormat),
85
+ );
86
+ scripts.push(buildScript(options.getAssetPath(options.chunk.fileName), options.scriptFormat));
87
+ appendRouteScripts(options.route, scripts);
88
+ }
89
+ function appendAdditionalRouteEntries(route, entries) {
90
+ if (entries.length === 0) return;
91
+ const stylesheets = [];
92
+ const scripts = [];
93
+ for (const entry of entries)
94
+ if (typeof entry === 'string' || 'href' in entry) stylesheets.push(entry);
95
+ else scripts.push(entry);
96
+ appendRouteStylesheets(route, stylesheets);
97
+ appendRouteScripts(route, scripts);
98
+ }
99
+ function buildStartManifest(options) {
100
+ const scannedChunks = scanClientChunks(options.clientBuild);
101
+ const assetResolvers = createManifestAssetResolvers(options.basePath);
102
+ const routes = buildRouteManifestRoutes({
103
+ routeTreeRoutes: options.routeTreeRoutes,
104
+ routeChunksByFilePath: scannedChunks.routeChunksByFilePath,
105
+ chunksByFileName: scannedChunks.chunksByFileName,
106
+ entryChunk: scannedChunks.entryChunk,
107
+ assetResolvers,
108
+ additionalRouteAssets: options.additionalRouteAssets,
109
+ });
110
+ appendEntryChunkScripts({
111
+ route: routes[rootRouteId],
112
+ chunk: scannedChunks.entryChunk,
113
+ scriptFormat: options.scriptFormat ?? 'module',
114
+ getAssetPath: assetResolvers.getAssetPath,
115
+ });
116
+ dedupeNestedRouteManifestEntries(rootRouteId, routes[rootRouteId], routes);
117
+ for (const routeId in routes) {
118
+ const route = routes[routeId];
119
+ const hasScripts = route.scripts && route.scripts.length > 0;
120
+ const hasCssLinks = route.css && route.css.length > 0;
121
+ const hasPreloads = route.preloads && route.preloads.length > 0;
122
+ if (!hasScripts && !hasCssLinks && !hasPreloads) delete routes[routeId];
123
+ }
124
+ const result = { routes };
125
+ if (options.scriptFormat === 'iife') result.scriptFormat = 'iife';
126
+ if (options.inlineCss?.enabled)
127
+ result.inlineCss = buildInlineCssManifestData({
128
+ routes,
129
+ basePath: options.basePath,
130
+ cssContentByFileName: options.clientBuild.cssContentByFileName,
131
+ transformAssets: options.inlineCss.transformAssets,
132
+ });
133
+ return result;
134
+ }
135
+ function serializeStartManifest(startManifest) {
136
+ return serialize(startManifest);
137
+ }
138
+ function scanClientChunks(clientBuild) {
139
+ const entryChunk = clientBuild.chunksByFileName.get(clientBuild.entryChunkFileName);
140
+ if (!entryChunk) throw new Error(`Missing entry chunk: ${clientBuild.entryChunkFileName}`);
141
+ const routeChunksByFilePath = /* @__PURE__ */ new Map();
142
+ for (const chunk of clientBuild.chunksByFileName.values())
143
+ if (chunk.routeFilePaths.length > 0)
144
+ for (const routeFilePath of chunk.routeFilePaths) {
145
+ let chunks = routeChunksByFilePath.get(routeFilePath);
146
+ if (chunks === void 0) {
147
+ chunks = [];
148
+ routeChunksByFilePath.set(routeFilePath, chunks);
149
+ }
150
+ chunks.push(chunk);
151
+ }
152
+ return {
153
+ entryChunk,
154
+ chunksByFileName: clientBuild.chunksByFileName,
155
+ routeChunksByFilePath,
156
+ };
157
+ }
158
+ function createManifestAssetResolvers(basePath) {
159
+ const assetPathByFileName = /* @__PURE__ */ new Map();
160
+ const stylesheetLinkByFileName = /* @__PURE__ */ new Map();
161
+ const preloadsByChunk = /* @__PURE__ */ new Map();
162
+ const getAssetPath = (fileName) => {
163
+ const cachedPath = assetPathByFileName.get(fileName);
164
+ if (cachedPath) return cachedPath;
165
+ const assetPath = joinURL(basePath, fileName);
166
+ assetPathByFileName.set(fileName, assetPath);
167
+ return assetPath;
168
+ };
169
+ const getStylesheetLink = (cssFile) => {
170
+ const cachedLink = stylesheetLinkByFileName.get(cssFile);
171
+ if (cachedLink) return cachedLink;
172
+ const link = getAssetPath(cssFile);
173
+ stylesheetLinkByFileName.set(cssFile, link);
174
+ return link;
175
+ };
176
+ const getChunkPreloads = (chunk) => {
177
+ const cachedPreloads = preloadsByChunk.get(chunk);
178
+ if (cachedPreloads) return cachedPreloads;
179
+ const preloads = [getAssetPath(chunk.fileName)];
180
+ for (let i = 0; i < chunk.imports.length; i++) preloads.push(getAssetPath(chunk.imports[i]));
181
+ preloadsByChunk.set(chunk, preloads);
182
+ return preloads;
183
+ };
184
+ return {
185
+ getAssetPath,
186
+ getChunkPreloads,
187
+ getStylesheetLink,
188
+ };
189
+ }
190
+ function createChunkCssAssetCollector(options) {
191
+ const linksByChunk = /* @__PURE__ */ new Map();
192
+ const stateByChunk = /* @__PURE__ */ new Map();
193
+ const appendAsset = (links, seenLinks, link) => {
194
+ if (seenLinks.has(link)) return;
195
+ seenLinks.add(link);
196
+ links.push(link);
197
+ };
198
+ const getChunkCssAssets = (chunk) => {
199
+ const cachedLinks = linksByChunk.get(chunk);
200
+ if (cachedLinks) return cachedLinks;
201
+ if (stateByChunk.get(chunk) === VISITING_CHUNK) return [];
202
+ stateByChunk.set(chunk, VISITING_CHUNK);
203
+ const links = [];
204
+ const seenLinks = /* @__PURE__ */ new Set();
205
+ for (let i = 0; i < chunk.imports.length; i++) {
206
+ const importedChunk = options.chunksByFileName.get(chunk.imports[i]);
207
+ if (!importedChunk) continue;
208
+ const importedLinks = getChunkCssAssets(importedChunk);
209
+ for (let j = 0; j < importedLinks.length; j++)
210
+ appendAsset(links, seenLinks, importedLinks[j]);
211
+ }
212
+ for (const cssFile of chunk.css)
213
+ appendAsset(links, seenLinks, options.getStylesheetLink(cssFile));
214
+ stateByChunk.delete(chunk);
215
+ linksByChunk.set(chunk, links);
216
+ return links;
217
+ };
218
+ return { getChunkCssAssets };
219
+ }
220
+ function buildInlineCssManifestData(options) {
221
+ const stylesheetHrefs = /* @__PURE__ */ new Set();
222
+ for (const route of Object.values(options.routes))
223
+ for (const link of route.css ?? []) stylesheetHrefs.add(getStylesheetHref(link));
224
+ if (stylesheetHrefs.size === 0) return { styles: {} };
225
+ if (!options.cssContentByFileName)
226
+ throw new Error(
227
+ 'TanStack Start inlineCss is enabled, but the client build did not provide CSS content',
228
+ );
229
+ const { getAssetPath } = createManifestAssetResolvers(options.basePath);
230
+ const styles = {};
231
+ let templates;
232
+ const missingHrefs = new Set(stylesheetHrefs);
233
+ for (const [cssFile, css] of options.cssContentByFileName) {
234
+ const cssHref = getAssetPath(cssFile);
235
+ if (!stylesheetHrefs.has(cssHref)) continue;
236
+ const result = processInlineCssUrls({
237
+ css,
238
+ cssHref,
239
+ templates: options.transformAssets,
240
+ });
241
+ styles[cssHref] = result.css;
242
+ if (result.template) {
243
+ templates ||= {};
244
+ templates[cssHref] = result.template;
245
+ }
246
+ missingHrefs.delete(cssHref);
247
+ }
248
+ if (missingHrefs.size > 0)
249
+ throw new Error(
250
+ `TanStack Start inlineCss could not find CSS content for: ${Array.from(missingHrefs).join(', ')}`,
251
+ );
252
+ return {
253
+ styles,
254
+ ...(templates ? { templates } : {}),
255
+ };
256
+ }
257
+ function buildRouteManifestRoutes(options) {
258
+ const routes = {};
259
+ const getChunkCssAssets = createChunkCssAssetCollector({
260
+ chunksByFileName: options.chunksByFileName,
261
+ getStylesheetLink: options.assetResolvers.getStylesheetLink,
262
+ }).getChunkCssAssets;
263
+ for (const [routeId, route] of Object.entries(options.routeTreeRoutes)) {
264
+ if (!route.filePath) {
265
+ if (routeId === rootRouteId) {
266
+ routes[routeId] = { ...route };
267
+ continue;
268
+ }
269
+ throw new Error(`expected filePath to be set for ${routeId}`);
270
+ }
271
+ const chunks = options.routeChunksByFilePath.get(route.filePath);
272
+ if (!chunks) {
273
+ routes[routeId] = { ...route };
274
+ continue;
275
+ }
276
+ const existing = routes[routeId];
277
+ const targetRoute = (routes[routeId] = existing ? existing : { ...route });
278
+ for (const chunk of chunks) {
279
+ mergeRouteChunkData({
280
+ route: targetRoute,
281
+ chunk,
282
+ getChunkCssAssets,
283
+ getChunkPreloads: options.assetResolvers.getChunkPreloads,
284
+ });
285
+ if (routeId !== rootRouteId)
286
+ mergeReachableHydrationChunkData({
287
+ route: targetRoute,
288
+ chunk,
289
+ chunksByFileName: options.chunksByFileName,
290
+ getChunkCssAssets,
291
+ });
292
+ }
293
+ }
294
+ const rootRoute = (routes[rootRouteId] = routes[rootRouteId] || {});
295
+ const rootRouteTreeRoute = options.routeTreeRoutes[rootRouteId];
296
+ const rootRouteChunks = rootRouteTreeRoute?.filePath
297
+ ? options.routeChunksByFilePath.get(rootRouteTreeRoute.filePath)
298
+ : void 0;
299
+ if (rootRouteChunks)
300
+ for (const chunk of rootRouteChunks)
301
+ mergeReachableHydrationChunkData({
302
+ route: rootRoute,
303
+ chunk,
304
+ chunksByFileName: options.chunksByFileName,
305
+ getChunkCssAssets,
306
+ });
307
+ mergeRouteChunkData({
308
+ route: rootRoute,
309
+ chunk: options.entryChunk,
310
+ getChunkCssAssets,
311
+ getChunkPreloads: options.assetResolvers.getChunkPreloads,
312
+ });
313
+ if (options.additionalRouteAssets)
314
+ for (const [routeId, assets] of Object.entries(options.additionalRouteAssets)) {
315
+ if (!assets || assets.length === 0) continue;
316
+ if (!(routeId in options.routeTreeRoutes))
317
+ throw new Error(
318
+ `expected additionalRouteAssets routeId to exist in routeTreeRoutes: ${routeId}`,
319
+ );
320
+ appendAdditionalRouteEntries((routes[routeId] = routes[routeId] || {}), assets);
321
+ }
322
+ return routes;
323
+ }
324
+ function mergeReachableHydrationChunkData(options) {
325
+ const visitedStaticChunks = /* @__PURE__ */ new Set();
326
+ const mergedHydrationChunks = /* @__PURE__ */ new Set();
327
+ const mergeHydrationChunk = (chunk) => {
328
+ if (mergedHydrationChunks.has(chunk.fileName)) return;
329
+ mergedHydrationChunks.add(chunk.fileName);
330
+ appendRouteStylesheets(options.route, options.getChunkCssAssets(chunk));
331
+ for (const dynamicImport of chunk.dynamicImports) {
332
+ const dynamicChunk = options.chunksByFileName.get(dynamicImport);
333
+ if (dynamicChunk?.hydrationIds.length) mergeHydrationChunk(dynamicChunk);
334
+ }
335
+ };
336
+ const visitStaticChunk = (chunk) => {
337
+ if (visitedStaticChunks.has(chunk.fileName)) return;
338
+ visitedStaticChunks.add(chunk.fileName);
339
+ for (const importedFileName of chunk.imports) {
340
+ const importedChunk = options.chunksByFileName.get(importedFileName);
341
+ if (importedChunk) visitStaticChunk(importedChunk);
342
+ }
343
+ for (const dynamicImport of chunk.dynamicImports) {
344
+ const dynamicChunk = options.chunksByFileName.get(dynamicImport);
345
+ if (dynamicChunk?.hydrationIds.length) mergeHydrationChunk(dynamicChunk);
346
+ }
347
+ };
348
+ visitStaticChunk(options.chunk);
349
+ }
350
+ function dedupeNestedRouteManifestEntries(
351
+ routeId,
352
+ route,
353
+ routesById,
354
+ seenPreloads = /* @__PURE__ */ new Set(),
355
+ seenScripts = /* @__PURE__ */ new Set(),
356
+ seenStylesheets = /* @__PURE__ */ new Set(),
357
+ ) {
358
+ let routePreloads = route.preloads;
359
+ let routeScripts = route.scripts;
360
+ let routeStylesheets = route.css;
361
+ if (routePreloads && routePreloads.length > 0) {
362
+ let dedupedPreloads;
363
+ for (let i = 0; i < routePreloads.length; i++) {
364
+ const preload = routePreloads[i];
365
+ const preloadHref = resolveManifestAssetLink(preload).href;
366
+ if (seenPreloads.has(preloadHref)) {
367
+ if (dedupedPreloads === void 0) dedupedPreloads = routePreloads.slice(0, i);
368
+ continue;
369
+ }
370
+ seenPreloads.add(preloadHref);
371
+ if (dedupedPreloads) dedupedPreloads.push(preload);
372
+ }
373
+ if (dedupedPreloads) {
374
+ routePreloads = dedupedPreloads;
375
+ route.preloads = dedupedPreloads;
376
+ }
377
+ }
378
+ if (routeScripts && routeScripts.length > 0) {
379
+ let dedupedScripts;
380
+ for (let i = 0; i < routeScripts.length; i++) {
381
+ const script = routeScripts[i];
382
+ const identity = getScriptIdentity(script);
383
+ if (seenScripts.has(identity)) {
384
+ if (dedupedScripts === void 0) dedupedScripts = routeScripts.slice(0, i);
385
+ continue;
386
+ }
387
+ seenScripts.add(identity);
388
+ if (dedupedScripts) dedupedScripts.push(script);
389
+ }
390
+ if (dedupedScripts) {
391
+ routeScripts = dedupedScripts;
392
+ if (dedupedScripts.length > 0) route.scripts = dedupedScripts;
393
+ else delete route.scripts;
394
+ }
395
+ }
396
+ if (routeStylesheets && routeStylesheets.length > 0) {
397
+ let dedupedStylesheets;
398
+ for (let i = 0; i < routeStylesheets.length; i++) {
399
+ const stylesheet = routeStylesheets[i];
400
+ const identity = getStylesheetIdentity(stylesheet);
401
+ if (seenStylesheets.has(identity)) {
402
+ if (dedupedStylesheets === void 0) dedupedStylesheets = routeStylesheets.slice(0, i);
403
+ continue;
404
+ }
405
+ seenStylesheets.add(identity);
406
+ if (dedupedStylesheets) dedupedStylesheets.push(stylesheet);
407
+ }
408
+ if (dedupedStylesheets) {
409
+ routeStylesheets = dedupedStylesheets;
410
+ if (dedupedStylesheets.length > 0) route.css = dedupedStylesheets;
411
+ else delete route.css;
412
+ }
413
+ }
414
+ if (route.children)
415
+ for (const childRouteId of route.children) {
416
+ const childRoute = routesById[childRouteId];
417
+ if (!childRoute)
418
+ throw new Error(
419
+ `Route tree references child route ${childRouteId} from ${routeId}, but no route entry was found`,
420
+ );
421
+ dedupeNestedRouteManifestEntries(
422
+ childRouteId,
423
+ childRoute,
424
+ routesById,
425
+ seenPreloads,
426
+ seenScripts,
427
+ seenStylesheets,
428
+ );
429
+ }
430
+ if (routePreloads)
431
+ for (let i = routePreloads.length - 1; i >= 0; i--)
432
+ seenPreloads.delete(resolveManifestAssetLink(routePreloads[i]).href);
433
+ if (routeScripts)
434
+ for (let i = routeScripts.length - 1; i >= 0; i--)
435
+ seenScripts.delete(getScriptIdentity(routeScripts[i]));
436
+ if (routeStylesheets)
437
+ for (let i = routeStylesheets.length - 1; i >= 0; i--)
438
+ seenStylesheets.delete(getStylesheetIdentity(routeStylesheets[i]));
439
+ }
440
+ //#endregion
441
+ export { buildStartManifest, createManifestAssetResolvers, serializeStartManifest };
@@ -0,0 +1 @@
1
+ export declare const SERVER_PROP = 'server';
@@ -0,0 +1,4 @@
1
+ //#region src/start-router-plugin/constants.ts
2
+ var SERVER_PROP = 'server';
3
+ //#endregion
4
+ export { SERVER_PROP };
@@ -0,0 +1,6 @@
1
+ import { GeneratorPlugin } from '#tanstack-start/router-generator';
2
+ export declare function composeGeneratorPlugins(opts: {
3
+ frameworkPlugins?: ReadonlyArray<GeneratorPlugin> | undefined;
4
+ userPlugins?: ReadonlyArray<GeneratorPlugin> | undefined;
5
+ builtInPlugins: ReadonlyArray<GeneratorPlugin>;
6
+ }): Array<GeneratorPlugin>;
@@ -0,0 +1,6 @@
1
+ //#region src/start-router-plugin/generator-plugins/compose-generator-plugins.ts
2
+ function composeGeneratorPlugins(opts) {
3
+ return [...(opts.frameworkPlugins ?? []), ...(opts.userPlugins ?? []), ...opts.builtInPlugins];
4
+ }
5
+ //#endregion
6
+ export { composeGeneratorPlugins };
@@ -0,0 +1,6 @@
1
+ import { GeneratorPlugin } from '#tanstack-start/router-generator';
2
+ /**
3
+ * this plugin gets the prerenderable paths and stores it on globalThis
4
+ * so that it can be accessed later (e.g. from a vite plugin)
5
+ */
6
+ export declare function prerenderRoutesPlugin(): GeneratorPlugin;
@@ -0,0 +1,27 @@
1
+ import { inferFullPath } from '#tanstack-start/router-generator';
2
+ //#region src/start-router-plugin/generator-plugins/prerender-routes-plugin.ts
3
+ /**
4
+ * this plugin gets the prerenderable paths and stores it on globalThis
5
+ * so that it can be accessed later (e.g. from a vite plugin)
6
+ */
7
+ function prerenderRoutesPlugin() {
8
+ return {
9
+ name: 'prerender-routes-plugin',
10
+ onRouteTreeChanged: ({ routeNodes }) => {
11
+ globalThis.TSS_PRERENDABLE_PATHS = getPrerenderablePaths(routeNodes);
12
+ },
13
+ };
14
+ }
15
+ function getPrerenderablePaths(routeNodes) {
16
+ const paths = new Set(['/']);
17
+ for (const route of routeNodes) {
18
+ if (!route.routePath) continue;
19
+ if (route.isNonPath === true) continue;
20
+ if (route.routePath.includes('$')) continue;
21
+ if (!route.createFileRouteProps?.has('component')) continue;
22
+ paths.add(inferFullPath(route));
23
+ }
24
+ return Array.from(paths).map((path) => ({ path }));
25
+ }
26
+ //#endregion
27
+ export { prerenderRoutesPlugin };
@@ -0,0 +1,6 @@
1
+ import { GeneratorPlugin } from '#tanstack-start/router-generator';
2
+ /**
3
+ * this plugin builds the routes manifest and stores it on globalThis
4
+ * so that it can be accessed later (e.g. from a vite plugin)
5
+ */
6
+ export declare function routesManifestPlugin(): GeneratorPlugin;
@@ -0,0 +1,34 @@
1
+ import { rootRouteId } from '@tanstack/router-core';
2
+ //#region src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts
3
+ /**
4
+ * this plugin builds the routes manifest and stores it on globalThis
5
+ * so that it can be accessed later (e.g. from a vite plugin)
6
+ */
7
+ function routesManifestPlugin() {
8
+ return {
9
+ name: 'routes-manifest-plugin',
10
+ onRouteTreeChanged: ({ routeTree, rootRouteNode, routeNodes }) => {
11
+ const allChildren = routeTree.map((d) => d.routePath);
12
+ const routes = {
13
+ [rootRouteId]: {
14
+ filePath: rootRouteNode.fullPath,
15
+ children: allChildren,
16
+ },
17
+ ...Object.fromEntries(
18
+ routeNodes.map((d) => {
19
+ return [
20
+ d.routePath,
21
+ {
22
+ filePath: d.fullPath,
23
+ children: d.children?.map((childRoute) => childRoute.routePath),
24
+ },
25
+ ];
26
+ }),
27
+ ),
28
+ };
29
+ globalThis.TSS_ROUTES_MANIFEST = routes;
30
+ },
31
+ };
32
+ }
33
+ //#endregion
34
+ export { routesManifestPlugin };
@@ -0,0 +1,11 @@
1
+ import { HandleNodeAccumulator, RouteNode } from '#tanstack-start/router-generator';
2
+ export declare function pruneServerOnlySubtrees({
3
+ rootRouteNode,
4
+ acc,
5
+ }: {
6
+ rootRouteNode: RouteNode;
7
+ acc: HandleNodeAccumulator;
8
+ }): {
9
+ routeTree: RouteNode[];
10
+ routeNodes: RouteNode[];
11
+ };
@@ -0,0 +1,42 @@
1
+ import './constants.js';
2
+ //#region src/start-router-plugin/pruneServerOnlySubtrees.ts
3
+ function pruneServerOnlySubtrees({ rootRouteNode, acc }) {
4
+ const routeNodes = [];
5
+ const routeTree =
6
+ prune(
7
+ {
8
+ ...rootRouteNode,
9
+ children: acc.routeTree,
10
+ },
11
+ routeNodes,
12
+ )?.children || [];
13
+ routeNodes.pop();
14
+ return {
15
+ routeTree,
16
+ routeNodes,
17
+ };
18
+ }
19
+ function prune(node, collectedRouteNodes) {
20
+ const newChildren = [];
21
+ let allChildrenServerOnly = true;
22
+ for (const child of node.children || []) {
23
+ const newChild = prune(child, collectedRouteNodes);
24
+ if (newChild) {
25
+ newChildren.push(newChild);
26
+ allChildrenServerOnly = false;
27
+ }
28
+ }
29
+ if (
30
+ node.createFileRouteProps?.has('server') &&
31
+ node.createFileRouteProps.size === 1 &&
32
+ allChildrenServerOnly
33
+ )
34
+ return null;
35
+ collectedRouteNodes.push(node);
36
+ return {
37
+ ...node,
38
+ children: newChildren,
39
+ };
40
+ }
41
+ //#endregion
42
+ export { pruneServerOnlySubtrees };
@@ -0,0 +1,6 @@
1
+ import { GetConfigFn, TanStackStartCoreOptions } from '../types.js';
2
+ export declare function buildRouteTreeFileFooterFromConfig(opts: {
3
+ generatedRouteTreePath: string;
4
+ getConfig: GetConfigFn;
5
+ corePluginOpts: TanStackStartCoreOptions;
6
+ }): Array<string>;
@@ -0,0 +1,59 @@
1
+ import path from 'pathe';
2
+ import { getStartPackage } from '#tanstack-start/package-names';
3
+ //#region src/start-router-plugin/route-tree-footer.ts
4
+ function buildRouteTreeFileFooter(opts) {
5
+ function getImportPath(absolutePath) {
6
+ let relativePath = path.relative(path.dirname(opts.generatedRouteTreePath), absolutePath);
7
+ if (!relativePath.startsWith('.')) relativePath = './' + relativePath;
8
+ return relativePath.split(path.sep).join('/');
9
+ }
10
+ function appendFooterBlock(lines, block) {
11
+ if (!block) return;
12
+ if (lines.length > 0) {
13
+ lines[lines.length - 1] += `\n${block}`;
14
+ return;
15
+ }
16
+ lines.push(block);
17
+ }
18
+ const footer = [];
19
+ const startPackage = getStartPackage(opts.framework);
20
+ appendFooterBlock(
21
+ footer,
22
+ `import type { getRouter } from '${getImportPath(opts.routerFilePath)}'`,
23
+ );
24
+ if (opts.startFilePath)
25
+ appendFooterBlock(
26
+ footer,
27
+ `import type { startInstance } from '${getImportPath(opts.startFilePath)}'`,
28
+ );
29
+ else appendFooterBlock(footer, `import type { createStart } from '${startPackage}'`);
30
+ appendFooterBlock(
31
+ footer,
32
+ `declare module '${startPackage}' {
33
+ interface Register {
34
+ ssr: true
35
+ router: Awaited<ReturnType<typeof getRouter>>`,
36
+ );
37
+ if (opts.startFilePath)
38
+ appendFooterBlock(footer, ` config: Awaited<ReturnType<typeof startInstance.getOptions>>`);
39
+ appendFooterBlock(
40
+ footer,
41
+ ` }
42
+ }`,
43
+ );
44
+ if (opts.userFooter)
45
+ footer.push(...(Array.isArray(opts.userFooter) ? opts.userFooter : opts.userFooter()));
46
+ return footer;
47
+ }
48
+ function buildRouteTreeFileFooterFromConfig(opts) {
49
+ const { startConfig, resolvedStartConfig } = opts.getConfig();
50
+ return buildRouteTreeFileFooter({
51
+ generatedRouteTreePath: opts.generatedRouteTreePath,
52
+ startFilePath: resolvedStartConfig.startFilePath,
53
+ routerFilePath: resolvedStartConfig.routerFilePath,
54
+ framework: opts.corePluginOpts.framework,
55
+ userFooter: startConfig.router.routeTreeFileFooter,
56
+ });
57
+ }
58
+ //#endregion
59
+ export { buildRouteTreeFileFooterFromConfig };