@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,103 @@
1
+ import { DEV_CLIENT_ENTRY, START_ENVIRONMENT_NAMES } from '../../constants.js';
2
+ import { createVirtualModule } from '../createVirtualModule.js';
3
+ import {
4
+ buildStartManifest,
5
+ createManifestAssetResolvers,
6
+ serializeStartManifest,
7
+ } from '../../start-manifest-plugin/manifestBuilder.js';
8
+ import { normalizeViteClientBuild } from './normalized-client-build.js';
9
+ import { rootRouteId } from '@tanstack/router-core';
10
+ import { VIRTUAL_MODULES } from '@tanstack/start-server-core';
11
+ import { joinURL } from 'ufo';
12
+ //#region src/vite/start-manifest-plugin/plugin.ts
13
+ function startManifestPlugin(opts) {
14
+ let clientBuild;
15
+ let cssCodeSplitDisabledFileName;
16
+ return [
17
+ {
18
+ name: 'tanstack-start:start-manifest-capture-client-build',
19
+ applyToEnvironment(environment) {
20
+ return environment.name === START_ENVIRONMENT_NAMES.client;
21
+ },
22
+ enforce: 'post',
23
+ generateBundle(_options, bundle) {
24
+ if (this.environment.name !== START_ENVIRONMENT_NAMES.client)
25
+ throw new Error(
26
+ `Unexpected environment for client build capture: ${this.environment.name}`,
27
+ );
28
+ clientBuild = normalizeViteClientBuild(bundle);
29
+ cssCodeSplitDisabledFileName = getAssetFileNameByName(bundle, 'style.css');
30
+ },
31
+ },
32
+ createVirtualModule({
33
+ name: 'tanstack-start:start-manifest-plugin',
34
+ moduleId: VIRTUAL_MODULES.startManifest,
35
+ enforce: 'pre',
36
+ load() {
37
+ const { resolvedStartConfig, startConfig } = opts.getConfig();
38
+ const clientEntry = getDevClientEntry({
39
+ basePath: resolvedStartConfig.basePaths.publicBase,
40
+ bundledDev: isClientBundledDev(this.environment),
41
+ });
42
+ if (this.environment.name !== START_ENVIRONMENT_NAMES.server)
43
+ return getEmptyStartManifestModule(clientEntry);
44
+ if (this.environment.config.command === 'serve')
45
+ return getEmptyStartManifestModule(clientEntry);
46
+ const routeTreeRoutes = globalThis.TSS_ROUTES_MANIFEST;
47
+ if (!clientBuild) return getEmptyStartManifestModule(clientEntry);
48
+ return `export const tsrStartManifest = () => (${serializeStartManifest(
49
+ buildStartManifest({
50
+ clientBuild,
51
+ routeTreeRoutes,
52
+ basePath: resolvedStartConfig.basePaths.publicBase,
53
+ inlineCss: startConfig.server.build.inlineCss,
54
+ additionalRouteAssets: getViteAdditionalRouteAssets({
55
+ cssCodeSplitDisabledFileName,
56
+ basePath: resolvedStartConfig.basePaths.publicBase,
57
+ cssCodeSplit: this.environment.config.build.cssCodeSplit,
58
+ }),
59
+ }),
60
+ )})`;
61
+ },
62
+ }),
63
+ ];
64
+ }
65
+ function getViteAdditionalRouteAssets(options) {
66
+ if (options.cssCodeSplit !== false) return;
67
+ if (!options.cssCodeSplitDisabledFileName)
68
+ throw new Error(
69
+ "TanStack Start could not find Vite's generated `style.css` manifest entry while `build.cssCodeSplit` is disabled",
70
+ );
71
+ const { getStylesheetLink } = createManifestAssetResolvers(options.basePath);
72
+ return { [rootRouteId]: [getStylesheetLink(options.cssCodeSplitDisabledFileName)] };
73
+ }
74
+ function getAssetFileNameByName(bundle, assetName) {
75
+ for (const fileName in bundle) {
76
+ const bundleEntry = bundle[fileName];
77
+ if (bundleEntry.type !== 'asset') continue;
78
+ if (bundleEntry.name === assetName) return fileName;
79
+ if ('names' in bundleEntry && bundleEntry.names.includes(assetName)) return fileName;
80
+ }
81
+ }
82
+ function getEmptyStartManifestModule(clientEntry) {
83
+ return `export const tsrStartManifest = () => ({
84
+ routes: {
85
+ __root__: {
86
+ preloads: ['${clientEntry}'],
87
+ scripts: [{ attrs: { type: 'module', async: true, src: '${clientEntry}' } }],
88
+ },
89
+ },
90
+ })`;
91
+ }
92
+ function getDevClientEntry(opts) {
93
+ if (opts.bundledDev) return joinURL(opts.basePath, 'assets', 'index.js');
94
+ return joinURL(opts.basePath, '@id', DEV_CLIENT_ENTRY);
95
+ }
96
+ function isClientBundledDev(environment) {
97
+ return (
98
+ environment.config.command === 'serve' &&
99
+ environment.config.environments?.[START_ENVIRONMENT_NAMES.client]?.isBundled === true
100
+ );
101
+ }
102
+ //#endregion
103
+ export { startManifestPlugin };
@@ -0,0 +1,9 @@
1
+ import { GetConfigFn } from '../../types.js';
2
+ import { TanStackStartVitePluginCoreOptions } from '../types.js';
3
+ import { PluginOption } from 'vite';
4
+ import { TanStackStartInputConfig } from '../../schema.js';
5
+ export declare function tanStackStartRouter(
6
+ startPluginOpts: TanStackStartInputConfig,
7
+ getConfig: GetConfigFn,
8
+ corePluginOpts: TanStackStartVitePluginCoreOptions,
9
+ ): Array<PluginOption>;
@@ -0,0 +1,143 @@
1
+ import { VITE_ENVIRONMENT_NAMES } from '../../constants.js';
2
+ import { routesManifestPlugin } from '../../start-router-plugin/generator-plugins/routes-manifest-plugin.js';
3
+ import { prerenderRoutesPlugin } from '../../start-router-plugin/generator-plugins/prerender-routes-plugin.js';
4
+ import { composeGeneratorPlugins } from '../../start-router-plugin/generator-plugins/compose-generator-plugins.js';
5
+ import { buildRouteTreeFileFooterFromConfig } from '../../start-router-plugin/route-tree-footer.js';
6
+ import '../../start-router-plugin/constants.js';
7
+ import { pruneServerOnlySubtrees } from '../../start-router-plugin/pruneServerOnlySubtrees.js';
8
+ import path from 'pathe';
9
+ import { normalizePath } from 'vite';
10
+ import { createRouterPluginContext } from '#tanstack-start/router-plugin/context';
11
+ import {
12
+ tanStackRouterCodeSplitter,
13
+ tanstackRouterGenerator,
14
+ } from '#tanstack-start/router-plugin/vite';
15
+ //#region src/vite/start-router-plugin/plugin.ts
16
+ function isServerOnlyNode(node) {
17
+ if (!node?.createFileRouteProps) return false;
18
+ return node.createFileRouteProps.has('server') && node.createFileRouteProps.size === 1;
19
+ }
20
+ function tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts) {
21
+ const routerPluginContext = createRouterPluginContext();
22
+ const getGeneratedRouteTreePath = () => {
23
+ const { startConfig } = getConfig();
24
+ return path.resolve(startConfig.router.generatedRouteTree);
25
+ };
26
+ let clientEnvironment = null;
27
+ function invalidate() {
28
+ if (!clientEnvironment) return;
29
+ const mod = clientEnvironment.moduleGraph.getModuleById(getGeneratedRouteTreePath());
30
+ if (mod) clientEnvironment.moduleGraph.invalidateModule(mod);
31
+ clientEnvironment.hot.send({
32
+ type: 'full-reload',
33
+ path: '*',
34
+ });
35
+ }
36
+ let generatorInstance = null;
37
+ const clientTreeGeneratorPlugin = {
38
+ name: 'start-client-tree-plugin',
39
+ init({ generator }) {
40
+ generatorInstance = generator;
41
+ },
42
+ afterTransform({ node, prevNode }) {
43
+ if (isServerOnlyNode(node) !== isServerOnlyNode(prevNode)) invalidate();
44
+ },
45
+ };
46
+ let routeTreeFileFooter = null;
47
+ function getRouteTreeFileFooter() {
48
+ if (routeTreeFileFooter) return routeTreeFileFooter;
49
+ routeTreeFileFooter = [
50
+ ...buildRouteTreeFileFooterFromConfig({
51
+ generatedRouteTreePath: getGeneratedRouteTreePath(),
52
+ getConfig,
53
+ corePluginOpts,
54
+ }),
55
+ ];
56
+ return routeTreeFileFooter;
57
+ }
58
+ let resolvedGeneratedRouteTreePath = null;
59
+ const clientTreePlugin = {
60
+ name: 'tanstack-start:route-tree-client-plugin',
61
+ enforce: 'pre',
62
+ applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
63
+ configureServer(server) {
64
+ clientEnvironment = server.environments[VITE_ENVIRONMENT_NAMES.client];
65
+ },
66
+ config() {
67
+ resolvedGeneratedRouteTreePath = normalizePath(getGeneratedRouteTreePath());
68
+ clientTreePlugin.load.filter = {
69
+ id: { include: new RegExp(resolvedGeneratedRouteTreePath) },
70
+ };
71
+ },
72
+ load: {
73
+ filter: {},
74
+ async handler() {
75
+ if (!generatorInstance) throw new Error('Generator instance not initialized');
76
+ const crawlingResult = await generatorInstance.getCrawlingResult();
77
+ if (!crawlingResult) throw new Error('Crawling result not available');
78
+ const prunedAcc = pruneServerOnlySubtrees(crawlingResult);
79
+ const acc = {
80
+ ...crawlingResult.acc,
81
+ ...prunedAcc,
82
+ };
83
+ return {
84
+ code: generatorInstance.buildRouteTree({
85
+ ...crawlingResult,
86
+ acc,
87
+ config: {
88
+ disableTypes: true,
89
+ enableRouteTreeFormatting: false,
90
+ routeTreeFileHeader: [],
91
+ routeTreeFileFooter: [],
92
+ },
93
+ }).routeTreeContent,
94
+ map: null,
95
+ };
96
+ },
97
+ },
98
+ };
99
+ return [
100
+ clientTreePlugin,
101
+ tanstackRouterGenerator(() => {
102
+ const routerConfig = getConfig().startConfig.router;
103
+ const builtInPlugins = [clientTreeGeneratorPlugin, routesManifestPlugin()];
104
+ if (startPluginOpts.prerender?.enabled === true) builtInPlugins.push(prerenderRoutesPlugin());
105
+ const plugins = composeGeneratorPlugins({
106
+ frameworkPlugins: corePluginOpts.routerGeneratorPlugins,
107
+ userPlugins: routerConfig.plugins,
108
+ builtInPlugins,
109
+ });
110
+ return {
111
+ ...routerConfig,
112
+ target: corePluginOpts.framework,
113
+ routeTreeFileFooter: getRouteTreeFileFooter,
114
+ plugins,
115
+ };
116
+ }, routerPluginContext),
117
+ tanStackRouterCodeSplitter(() => {
118
+ const routerConfig = getConfig().startConfig.router;
119
+ return {
120
+ ...routerConfig,
121
+ codeSplittingOptions: {
122
+ ...routerConfig.codeSplittingOptions,
123
+ deleteNodes: ['ssr', 'server', 'headers'],
124
+ addHmr: true,
125
+ },
126
+ plugin: { vite: { environmentName: VITE_ENVIRONMENT_NAMES.client } },
127
+ };
128
+ }, routerPluginContext),
129
+ tanStackRouterCodeSplitter(() => {
130
+ const routerConfig = getConfig().startConfig.router;
131
+ return {
132
+ ...routerConfig,
133
+ codeSplittingOptions: {
134
+ ...routerConfig.codeSplittingOptions,
135
+ addHmr: false,
136
+ },
137
+ plugin: { vite: { environmentName: VITE_ENVIRONMENT_NAMES.server } },
138
+ };
139
+ }, routerPluginContext),
140
+ ];
141
+ }
142
+ //#endregion
143
+ export { tanStackStartRouter };
@@ -0,0 +1,17 @@
1
+ import { TanStackStartCoreOptions } from '../types.js';
2
+ export interface ViteRscForwardSsrResolverStrategy {
3
+ type: 'vite-rsc-forward';
4
+ sourceEnvironmentName: string;
5
+ sourceEntry: string;
6
+ exportName: 'getServerFnById';
7
+ }
8
+ export type SsrResolverStrategy =
9
+ | {
10
+ type: 'default';
11
+ }
12
+ | ViteRscForwardSsrResolverStrategy;
13
+ export type TanStackStartVitePluginCoreOptions = TanStackStartCoreOptions & {
14
+ providerEnvironmentName: string;
15
+ ssrIsProvider: boolean;
16
+ ssrResolverStrategy: SsrResolverStrategy;
17
+ };
@@ -0,0 +1,10 @@
1
+ export const OCTANE_ROUTER_PACKAGE = '@octanejs/tanstack-router';
2
+ export const OCTANE_START_PACKAGE = '@octanejs/tanstack-start';
3
+
4
+ export function getRouterPackage(framework) {
5
+ return framework === 'octane' ? OCTANE_ROUTER_PACKAGE : `@tanstack/${framework}-router`;
6
+ }
7
+
8
+ export function getStartPackage(framework) {
9
+ return framework === 'octane' ? OCTANE_START_PACKAGE : `@tanstack/${framework}-start`;
10
+ }
@@ -0,0 +1,23 @@
1
+ import type { TanStackStartViteInputConfig } from '#tanstack-start/plugin-core/vite';
2
+ import type {
3
+ OctaneRendererBoundaryOptions,
4
+ OctaneRendererConfigOptions,
5
+ OctaneRendererRegistryEntry,
6
+ OctaneRendererRuleOptions,
7
+ OctaneVitePluginOptions,
8
+ } from 'octane/compiler/vite';
9
+ import type { PluginOption } from 'vite';
10
+
11
+ export type OctaneRendererDescriptor = Exclude<OctaneRendererRegistryEntry, string>;
12
+ export type OctaneRendererBoundary = OctaneRendererBoundaryOptions;
13
+ export type OctaneRendererRule = OctaneRendererRuleOptions;
14
+ export type OctaneRendererConfig = OctaneRendererConfigOptions;
15
+ export type OctaneCompilerOptions = Omit<OctaneVitePluginOptions, 'ssr'>;
16
+
17
+ export type TanStackOctaneStartViteInputConfig = TanStackStartViteInputConfig & {
18
+ octane?: OctaneCompilerOptions;
19
+ };
20
+
21
+ export declare function tanstackStart(
22
+ options?: TanStackOctaneStartViteInputConfig,
23
+ ): Array<PluginOption>;
@@ -0,0 +1,62 @@
1
+ import { START_ENVIRONMENT_NAMES, tanStackStartVite } from '#tanstack-start/plugin-core/vite';
2
+ import { octaneRouteGeneratorPlugin } from '@octanejs/tanstack-router/generator-plugin';
3
+ import { octane } from 'octane/compiler/vite';
4
+ import { octaneStartDefaultEntryPaths } from './default-entry-paths.js';
5
+ import { validateOctaneCompilerOptions } from './validate-options.js';
6
+
7
+ // The Start runtime chain must be source-served. Its compiler removes
8
+ // environment-specific branches; a prebundled dependency bypasses that
9
+ // transform and can execute server-only storage code in the browser.
10
+ const WORKSPACE_SOURCE_EXCLUDES = [
11
+ '@octanejs/tanstack-start',
12
+ '@octanejs/tanstack-router',
13
+ '@tanstack/start-client-core',
14
+ '@tanstack/start-storage-context',
15
+ '@tanstack/start-fn-stubs',
16
+ '@tanstack/start-static-server-functions',
17
+ 'octane',
18
+ ];
19
+
20
+ // The router ships raw TSRX, so its registry subpath imports surface after
21
+ // initial dependency discovery. Predeclare them to prevent a mid-hydration
22
+ // optimized-dependency reload on a cold cache.
23
+ const WORKSPACE_SOURCE_INCLUDES = [
24
+ '@octanejs/tanstack-router > @tanstack/router-core/isServer',
25
+ '@octanejs/tanstack-router > @tanstack/router-core/scroll-restoration-script',
26
+ ];
27
+
28
+ export function tanstackStart(options) {
29
+ const { octane: octaneOptions, ...startOptions } = options ?? {};
30
+ validateOctaneCompilerOptions(octaneOptions);
31
+
32
+ const corePluginOptions = {
33
+ framework: 'octane',
34
+ defaultEntryPaths: octaneStartDefaultEntryPaths,
35
+ providerEnvironmentName: START_ENVIRONMENT_NAMES.server,
36
+ ssrIsProvider: true,
37
+ ssrResolverStrategy: { type: 'default' },
38
+ routerGeneratorPlugins: [octaneRouteGeneratorPlugin()],
39
+ };
40
+
41
+ return [
42
+ octane(octaneOptions),
43
+ {
44
+ name: 'octanejs-tanstack-start:workspace-source-deps',
45
+ configEnvironment(environmentName, environmentOptions) {
46
+ const applies =
47
+ environmentName === START_ENVIRONMENT_NAMES.client ||
48
+ (environmentName === START_ENVIRONMENT_NAMES.server &&
49
+ environmentOptions.optimizeDeps?.noDiscovery === false);
50
+ return applies
51
+ ? {
52
+ optimizeDeps: {
53
+ exclude: WORKSPACE_SOURCE_EXCLUDES,
54
+ include: WORKSPACE_SOURCE_INCLUDES,
55
+ },
56
+ }
57
+ : undefined;
58
+ },
59
+ },
60
+ tanStackStartVite(corePluginOptions, startOptions),
61
+ ];
62
+ }
@@ -0,0 +1,11 @@
1
+ import type { AnyRouter } from '@tanstack/router-core';
2
+
3
+ export interface StartClientProps {
4
+ router: AnyRouter;
5
+ }
6
+
7
+ export declare function StartClient({
8
+ router,
9
+ }: StartClientProps): import('octane').ElementDescriptor<{
10
+ router: AnyRouter;
11
+ }>;
@@ -0,0 +1,16 @@
1
+ import { HYDRATION_RANGE_BOUNDARY, createElement, hookSlots, useEffect } from 'octane';
2
+ import { RouterProvider } from '@octanejs/tanstack-router';
3
+
4
+ export function StartClient({ router }) {
5
+ useEffect(
6
+ () => {
7
+ window.$_TSR?.h();
8
+ },
9
+ [],
10
+ startClientEffectSlot,
11
+ );
12
+ return createElement(RouterProvider, { router });
13
+ }
14
+
15
+ StartClient[HYDRATION_RANGE_BOUNDARY] = 'passthrough';
16
+ const startClientEffectSlot = Symbol(hookSlots(1));
@@ -0,0 +1,4 @@
1
+ import type { AnyRouter } from '@tanstack/router-core';
2
+
3
+ export declare function waitForRouterMatches(router: AnyRouter): Promise<void>;
4
+ export declare function hydrateStart(): Promise<AnyRouter>;
@@ -0,0 +1,30 @@
1
+ import { hydrateStart as hydrateStartCore } from '@tanstack/start-client-core/client';
2
+
3
+ /**
4
+ * Octane batches router store writes in a transition. The core hydration
5
+ * promise can therefore settle before hydrated matches are observable to the
6
+ * first render. Wait for that commit so hydration never adopts the server
7
+ * document with an empty match tree.
8
+ */
9
+ export function waitForRouterMatches(router) {
10
+ const matchesId = router.stores.matchesId;
11
+ if (matchesId.get().length > 0) return Promise.resolve();
12
+
13
+ return new Promise((resolve) => {
14
+ let resolved = false;
15
+ const finish = () => {
16
+ if (resolved || matchesId.get().length === 0) return;
17
+ resolved = true;
18
+ subscription.unsubscribe();
19
+ resolve();
20
+ };
21
+ const subscription = matchesId.subscribe(finish);
22
+ finish();
23
+ });
24
+ }
25
+
26
+ export async function hydrateStart() {
27
+ const router = await hydrateStartCore();
28
+ await waitForRouterMatches(router);
29
+ return router;
30
+ }
@@ -0,0 +1,10 @@
1
+ import type { AnyRouter } from '@tanstack/router-core';
2
+ import type { ElementDescriptor } from 'octane';
3
+
4
+ export interface StartServerProps {
5
+ router: AnyRouter;
6
+ }
7
+
8
+ export declare function StartServer({
9
+ router,
10
+ }: StartServerProps): ElementDescriptor<StartServerProps>;
@@ -0,0 +1,6 @@
1
+ import { createElement } from 'octane/server';
2
+ import { RouterProvider } from '@octanejs/tanstack-router';
3
+
4
+ export function StartServer({ router }) {
5
+ return createElement(RouterProvider, { router });
6
+ }
@@ -0,0 +1,3 @@
1
+ export declare const defaultRenderHandler: import('@tanstack/start-server-core').HandlerCallback<
2
+ import('@tanstack/router-core').AnyRouter
3
+ >;
@@ -0,0 +1,11 @@
1
+ import { defineHandlerCallback } from '@tanstack/start-server-core';
2
+ import { renderRouterToString } from '@octanejs/tanstack-router/ssr/server';
3
+ import { StartServer } from './StartServer.js';
4
+
5
+ export const defaultRenderHandler = defineHandlerCallback(({ router, responseHeaders }) =>
6
+ renderRouterToString({
7
+ router,
8
+ responseHeaders,
9
+ App: StartServer,
10
+ }),
11
+ );
@@ -0,0 +1,3 @@
1
+ export declare const defaultStreamHandler: import('@tanstack/start-server-core').HandlerCallback<
2
+ import('@tanstack/router-core').AnyRouter
3
+ >;
@@ -0,0 +1,13 @@
1
+ import { defineHandlerCallback } from '@tanstack/start-server-core';
2
+ import { renderRouterToStream } from '@octanejs/tanstack-router/ssr/server';
3
+ import { StartServer } from './StartServer.js';
4
+
5
+ export const defaultStreamHandler = defineHandlerCallback(
6
+ async ({ request, router, responseHeaders }) =>
7
+ await renderRouterToStream({
8
+ request,
9
+ router,
10
+ responseHeaders,
11
+ App: StartServer,
12
+ }),
13
+ );
@@ -0,0 +1,11 @@
1
+ import type { Register } from '@octanejs/tanstack-start';
2
+ import type { RequestHandler } from './server.js';
3
+
4
+ export type ServerEntry = {
5
+ fetch: RequestHandler<Register>;
6
+ };
7
+
8
+ export declare function createServerEntry(entry: ServerEntry): ServerEntry;
9
+
10
+ declare const defaultEntry: ServerEntry;
11
+ export default defaultEntry;
@@ -0,0 +1,13 @@
1
+ import { createStartHandler, defaultStreamHandler } from './server.js';
2
+
3
+ const fetch = createStartHandler(defaultStreamHandler);
4
+
5
+ export function createServerEntry(entry) {
6
+ return {
7
+ async fetch(...args) {
8
+ return await entry.fetch(...args);
9
+ },
10
+ };
11
+ }
12
+
13
+ export default createServerEntry({ fetch });
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export { createServerRpc } from '@tanstack/start-server-core/createServerRpc';
@@ -0,0 +1 @@
1
+ export { createServerRpc } from '@tanstack/start-server-core/createServerRpc';
@@ -0,0 +1,6 @@
1
+ export { StartServer } from './runtime/server/StartServer.js';
2
+ export type { StartServerProps } from './runtime/server/StartServer.js';
3
+ export { defaultStreamHandler } from './runtime/server/defaultStreamHandler.js';
4
+ export { defaultRenderHandler } from './runtime/server/defaultRenderHandler.js';
5
+ export type { RequestHandler, RequestOptions } from '@tanstack/start-server-core';
6
+ export * from '@tanstack/start-server-core';
package/src/server.js ADDED
@@ -0,0 +1,4 @@
1
+ export { StartServer } from './runtime/server/StartServer.js';
2
+ export { defaultStreamHandler } from './runtime/server/defaultStreamHandler.js';
3
+ export { defaultRenderHandler } from './runtime/server/defaultRenderHandler.js';
4
+ export * from '@tanstack/start-server-core';
@@ -0,0 +1 @@
1
+ export { createSsrRpc } from '@tanstack/start-server-core/createSsrRpc';
package/src/ssr-rpc.js ADDED
@@ -0,0 +1 @@
1
+ export { createSsrRpc } from '@tanstack/start-server-core/createSsrRpc';
@@ -0,0 +1,3 @@
1
+ export declare function useServerFn<T extends (...deps: Array<any>) => Promise<any>>(
2
+ serverFn: T,
3
+ ): (...args: Parameters<T>) => ReturnType<T>;
@@ -0,0 +1,18 @@
1
+ import { isRedirect, useRouter } from '@octanejs/tanstack-router';
2
+
3
+ export function useServerFn(serverFn) {
4
+ const router = useRouter();
5
+ return async (...args) => {
6
+ try {
7
+ const response = await serverFn(...args);
8
+ if (isRedirect(response)) throw response;
9
+ return response;
10
+ } catch (error) {
11
+ if (isRedirect(error)) {
12
+ error.options._fromLocation = router.stores.location.get();
13
+ return router.navigate(router.resolveRedirect(error).options);
14
+ }
15
+ throw error;
16
+ }
17
+ };
18
+ }
@@ -0,0 +1,7 @@
1
+ export function validateOctaneCompilerOptions(octaneOptions) {
2
+ if (octaneOptions && 'ssr' in octaneOptions) {
3
+ throw new Error(
4
+ '`octane.ssr` is not supported by TanStack Start. Start compiles its client and server environments separately and selects the correct Octane compilation mode for each one.',
5
+ );
6
+ }
7
+ }