@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,75 @@
1
+ import { StartCompiler, getLookupKindsForEnv } from './compiler.js';
2
+ import { getLookupConfigurationsForEnv } from './config.js';
3
+ //#region src/start-compiler/host.ts
4
+ function createStartCompiler(options) {
5
+ return new StartCompiler({
6
+ env: options.env,
7
+ envName: options.envName,
8
+ root: options.root,
9
+ lookupKinds: getLookupKindsForEnv(options.env, {
10
+ compilerTransforms: options.compilerTransforms,
11
+ }),
12
+ lookupConfigurations: getLookupConfigurationsForEnv(options.env, options.framework, {
13
+ compilerTransforms: options.compilerTransforms,
14
+ }),
15
+ mode: options.mode,
16
+ framework: options.framework,
17
+ providerEnvName: options.providerEnvName,
18
+ generateFunctionId: options.generateFunctionId,
19
+ onServerFnsById: options.onServerFnsById,
20
+ compilerTransforms: options.compilerTransforms,
21
+ compilerPlugins: options.compilerPlugins,
22
+ serverFnProviderModuleDirectives: options.serverFnProviderModuleDirectives,
23
+ warn: options.warn,
24
+ getKnownServerFns: options.getKnownServerFns,
25
+ devServerFnModuleSpecifierEncoder: options.encodeModuleSpecifierInDev,
26
+ loadModule: options.loadModule,
27
+ resolveId: options.resolveId,
28
+ });
29
+ }
30
+ function mergeServerFnsById(current, next) {
31
+ for (const [id, fn] of Object.entries(next)) {
32
+ const existing = current[id];
33
+ if (existing) {
34
+ current[id] = {
35
+ ...fn,
36
+ isClientReferenced: existing.isClientReferenced || fn.isClientReferenced,
37
+ };
38
+ continue;
39
+ }
40
+ current[id] = fn;
41
+ }
42
+ }
43
+ function matchesCodeFilters(code, filters) {
44
+ for (const pattern of filters) {
45
+ pattern.lastIndex = 0;
46
+ if (pattern.test(code)) return true;
47
+ }
48
+ return false;
49
+ }
50
+ function createCompilerVirtualModuleIdPattern(compilerPlugins) {
51
+ const patterns = compilerPlugins
52
+ .map((plugin) => plugin.virtualModuleIdPattern)
53
+ .filter((pattern) => !!pattern);
54
+ if (patterns.length === 0) return;
55
+ return new RegExp(patterns.map((pattern) => `(?:${pattern.source})`).join('|'));
56
+ }
57
+ function loadCompilerVirtualModule(compilerPlugins, context) {
58
+ for (const compilerPlugin of compilerPlugins) {
59
+ const pattern = compilerPlugin.virtualModuleIdPattern;
60
+ if (!pattern) continue;
61
+ pattern.lastIndex = 0;
62
+ if (!pattern.test(context.id)) continue;
63
+ const result = compilerPlugin.loadVirtualModule?.(context);
64
+ if (result) return result;
65
+ }
66
+ return null;
67
+ }
68
+ //#endregion
69
+ export {
70
+ createCompilerVirtualModuleIdPattern,
71
+ createStartCompiler,
72
+ loadCompilerVirtualModule,
73
+ matchesCodeFilters,
74
+ mergeServerFnsById,
75
+ };
@@ -0,0 +1,10 @@
1
+ import { ServerFn } from './types.js';
2
+ interface GenerateServerFnResolverModuleOptions {
3
+ serverFnsById: Record<string, ServerFn>;
4
+ includeClientReferencedCheck: boolean;
5
+ useStaticImports?: boolean;
6
+ }
7
+ export declare function generateServerFnResolverModule(
8
+ opts: GenerateServerFnResolverModuleOptions,
9
+ ): string;
10
+ export {};
@@ -0,0 +1,87 @@
1
+ //#region src/start-compiler/server-fn-resolver-module.ts
2
+ function getResolverManifestEntries(serverFnsById) {
3
+ return Object.entries(serverFnsById)
4
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
5
+ .map(([id, fn]) => ({
6
+ id,
7
+ functionName: fn.functionName,
8
+ extractedFilename: fn.extractedFilename,
9
+ isClientReferenced: fn.isClientReferenced ?? true,
10
+ }));
11
+ }
12
+ function getClientReferencedCheck(includeClientReferencedCheck) {
13
+ if (!includeClientReferencedCheck) return '';
14
+ return `
15
+ if (access.origin === 'client' && !serverFnInfo.isClientReferenced) {
16
+ throw new Error('Server function not accessible from client: ' + id)
17
+ }
18
+ `;
19
+ }
20
+ function getResolverBody() {
21
+ return `
22
+ export async function getServerFnById(id, access) {
23
+ const serverFnInfo = manifest[id]
24
+ if (!serverFnInfo) {
25
+ throw new Error('Server function info not found for ' + id)
26
+ }
27
+ __CLIENT_REFERENCED_CHECK__
28
+ const fnModule = serverFnInfo.module ?? (await serverFnInfo.importer())
29
+ if (!fnModule) {
30
+ throw new Error('Server function module not resolved for ' + id)
31
+ }
32
+ const action = fnModule[serverFnInfo.functionName]
33
+ if (!action) {
34
+ throw new Error('Server function module export not resolved for serverFn ID: ' + id)
35
+ }
36
+ return action
37
+ }
38
+ `;
39
+ }
40
+ function getResolverManifestModuleAccess(opts) {
41
+ if (opts.useStaticImports) return `module: ${opts.moduleRef}`;
42
+ return `importer: () => import(${JSON.stringify(opts.extractedFilename)})`;
43
+ }
44
+ function getResolverManifestEntry(opts) {
45
+ const clientReferenced = opts.includeClientReferencedCheck
46
+ ? `,\n isClientReferenced: ${opts.entry.isClientReferenced}`
47
+ : '';
48
+ return `'${opts.entry.id}': {
49
+ functionName: '${opts.entry.functionName}',
50
+ ${opts.moduleAccess}${clientReferenced}
51
+ }`;
52
+ }
53
+ function generateServerFnResolverModule(opts) {
54
+ const manifestEntries = getResolverManifestEntries(opts.serverFnsById);
55
+ const staticImports = [];
56
+ const manifest = manifestEntries
57
+ .map((entry, index) => {
58
+ const moduleRef = `serverFnModule${index}`;
59
+ if (opts.useStaticImports)
60
+ staticImports.push(
61
+ `import * as ${moduleRef} from ${JSON.stringify(entry.extractedFilename)}`,
62
+ );
63
+ return getResolverManifestEntry({
64
+ entry,
65
+ moduleAccess: getResolverManifestModuleAccess({
66
+ useStaticImports: opts.useStaticImports,
67
+ extractedFilename: entry.extractedFilename,
68
+ moduleRef,
69
+ }),
70
+ includeClientReferencedCheck: opts.includeClientReferencedCheck,
71
+ });
72
+ })
73
+ .join(',\n ');
74
+ const body = getResolverBody().replace(
75
+ '__CLIENT_REFERENCED_CHECK__',
76
+ getClientReferencedCheck(opts.includeClientReferencedCheck),
77
+ );
78
+ return `
79
+ ${staticImports.join('\n')}
80
+ const manifest = {
81
+ ${manifest}
82
+ }
83
+ ${body}
84
+ `;
85
+ }
86
+ //#endregion
87
+ export { generateServerFnResolverModule };
@@ -0,0 +1,119 @@
1
+ import { StartCompilerTransformContext } from '../types.js';
2
+ import type * as babel from '@babel/core';
3
+ import type * as t from '@babel/types';
4
+ /**
5
+ * Context passed to all plugin handlers during compilation.
6
+ * Contains both read-only input data and mutable state that handlers update.
7
+ */
8
+ export interface CompilationContext extends StartCompilerTransformContext {
9
+ /** Generate a unique function ID */
10
+ generateFunctionId: GenerateFunctionIdFn;
11
+ /** Get known server functions from previous builds (e.g., client build) */
12
+ getKnownServerFns: () => Record<string, ServerFn>;
13
+ /** Module-level directives to add to extracted server function provider files. */
14
+ serverFnProviderModuleDirectives: ReadonlyArray<string> | undefined;
15
+ /**
16
+ * Callback when server functions are discovered.
17
+ * Called after each file is compiled with its new functions.
18
+ */
19
+ onServerFnsById: ((d: Record<string, ServerFn>) => void) | undefined;
20
+ }
21
+ /**
22
+ * Batched plugin handler signature.
23
+ * Receives ALL candidates of a specific kind in one call.
24
+ * Mutates the CompilationContext directly.
25
+ */
26
+ export type BatchedPluginHandler<TOpts = unknown> = (
27
+ candidates: Array<RewriteCandidate>,
28
+ context: CompilationContext,
29
+ opts: TOpts,
30
+ ) => void;
31
+ /**
32
+ * Info about a method call in the chain, including the call expression path
33
+ * and the path to its first argument (if any).
34
+ */
35
+ export interface MethodCallInfo {
36
+ callPath: babel.NodePath<t.CallExpression>;
37
+ /** Path to the first argument, or null if no arguments */
38
+ firstArgPath: babel.NodePath | null;
39
+ }
40
+ /**
41
+ * Pre-collected method chain paths for a root call expression.
42
+ * This avoids needing to traverse the AST again in handlers.
43
+ */
44
+ export interface MethodChainPaths {
45
+ middleware: MethodCallInfo | null;
46
+ validator: MethodCallInfo | null;
47
+ inputValidator: MethodCallInfo | null;
48
+ handler: MethodCallInfo | null;
49
+ server: MethodCallInfo | null;
50
+ client: MethodCallInfo | null;
51
+ }
52
+ export type MethodChainKey = keyof MethodChainPaths;
53
+ /**
54
+ * Information about a candidate that needs to be rewritten.
55
+ */
56
+ export interface RewriteCandidate {
57
+ path: babel.NodePath<t.CallExpression>;
58
+ methodChain: MethodChainPaths;
59
+ }
60
+ /**
61
+ * Represents an extracted server function that has been registered.
62
+ * Used for manifest generation and tracking function metadata.
63
+ */
64
+ export interface ServerFn {
65
+ /** The unique name used to export this function */
66
+ functionName: string;
67
+ /** The unique ID for this function (used in RPC calls) */
68
+ functionId: string;
69
+ /** The filename with query param where the extracted implementation lives */
70
+ extractedFilename: string;
71
+ /** The original source filename */
72
+ filename: string;
73
+ /**
74
+ * True when this function was discovered by the client build.
75
+ * Used to restrict HTTP access to only client-referenced functions.
76
+ */
77
+ isClientReferenced?: boolean;
78
+ }
79
+ /**
80
+ * Function type for generating unique function IDs.
81
+ */
82
+ export type GenerateFunctionIdFn = (opts: {
83
+ filename: string;
84
+ functionName: string;
85
+ extractedFilename: string;
86
+ }) => string;
87
+ /**
88
+ * Optional version that allows returning undefined to use default ID generation.
89
+ */
90
+ export type GenerateFunctionIdFnOptional = (
91
+ opts: Omit<Parameters<GenerateFunctionIdFn>[0], 'extractedFilename'>,
92
+ ) => string | undefined;
93
+ /**
94
+ * Function type for generating replacement code for server functions.
95
+ * Used internally by handleCreateServerFn.
96
+ */
97
+ export type DevServerFnModuleSpecifierEncoder = (opts: {
98
+ extractedFilename: string;
99
+ root: string;
100
+ }) => string;
101
+ export type ReplacerFn = (opts: {
102
+ /** Placeholder for the original function expression */
103
+ fn: string;
104
+ /** The filename where the extracted implementation lives */
105
+ extractedFilename: string;
106
+ /** The original source filename */
107
+ filename: string;
108
+ /** The unique function ID */
109
+ functionId: string;
110
+ /** The export name for this function */
111
+ functionName: string;
112
+ /** True if this is the source/provider file (has the implementation) */
113
+ isSourceFn: boolean;
114
+ /**
115
+ * True when this function was already discovered by a previous build (e.g., client).
116
+ * For SSR callers, this means the function is in the manifest.
117
+ */
118
+ isClientReferenced: boolean;
119
+ }) => string;
@@ -0,0 +1,27 @@
1
+ import { default as babel } from '@babel/core';
2
+ import * as t from '@babel/types';
3
+ export declare function codeFrameError(
4
+ code: string,
5
+ loc: {
6
+ start: {
7
+ line: number;
8
+ column: number;
9
+ };
10
+ end: {
11
+ line: number;
12
+ column: number;
13
+ };
14
+ },
15
+ message: string,
16
+ ): Error;
17
+ export declare function cleanId(id: string): string;
18
+ /**
19
+ * Strips a method call by replacing it with its callee object.
20
+ * E.g., `foo().bar()` -> `foo()`
21
+ *
22
+ * This is a common pattern used when removing method calls from chains
23
+ * (e.g., removing .server() from middleware on client, or .validator() on client).
24
+ *
25
+ * @param callPath - The path to the CallExpression to strip
26
+ */
27
+ export declare function stripMethodCall(callPath: babel.NodePath<t.CallExpression>): void;
@@ -0,0 +1,36 @@
1
+ import * as t from '@babel/types';
2
+ import { codeFrameColumns } from '@babel/code-frame';
3
+ //#region src/start-compiler/utils.ts
4
+ function codeFrameError(code, loc, message) {
5
+ const frame = codeFrameColumns(
6
+ code,
7
+ {
8
+ start: loc.start,
9
+ end: loc.end,
10
+ },
11
+ {
12
+ highlightCode: true,
13
+ message,
14
+ },
15
+ );
16
+ return new Error(frame);
17
+ }
18
+ function cleanId(id) {
19
+ if (id.startsWith('\0')) id = id.slice(1);
20
+ const queryIndex = id.indexOf('?');
21
+ return queryIndex === -1 ? id : id.substring(0, queryIndex);
22
+ }
23
+ /**
24
+ * Strips a method call by replacing it with its callee object.
25
+ * E.g., `foo().bar()` -> `foo()`
26
+ *
27
+ * This is a common pattern used when removing method calls from chains
28
+ * (e.g., removing .server() from middleware on client, or .validator() on client).
29
+ *
30
+ * @param callPath - The path to the CallExpression to strip
31
+ */
32
+ function stripMethodCall(callPath) {
33
+ if (t.isMemberExpression(callPath.node.callee)) callPath.replaceWith(callPath.node.callee.object);
34
+ }
35
+ //#endregion
36
+ export { cleanId, codeFrameError, stripMethodCall };
@@ -0,0 +1,16 @@
1
+ export interface InlineCssTemplate {
2
+ strings: Array<string>;
3
+ urls: Array<string>;
4
+ }
5
+ export interface InlineCssResult {
6
+ css: string;
7
+ template?: InlineCssTemplate;
8
+ }
9
+ export declare function shouldRebaseInlineCssUrls(css: string): boolean;
10
+ export declare function rebaseInlineCssUrls(options: { css: string; cssHref: string }): string;
11
+ export declare function processInlineCssUrls(options: {
12
+ css: string;
13
+ cssHref: string;
14
+ templates?: boolean;
15
+ }): InlineCssResult;
16
+ export declare function getCssAssetSource(source: unknown): string | undefined;
@@ -0,0 +1,131 @@
1
+ import { transform } from 'lightningcss';
2
+ //#region src/start-manifest-plugin/inlineCss.ts
3
+ var cssUrlPattern =
4
+ /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)"']*?))\s*\)|@import\s+(?:url\(\s*(?:"([^"]*)"|'([^']*)'|([^)"']*?))\s*\)|"([^"]*)"|'([^']*)')/gi;
5
+ function createInlineCssUrlPlaceholder(index) {
6
+ return `__TSS INLINE CSS URL ${index}__`;
7
+ }
8
+ function isRelativeCssUrl(url) {
9
+ if (!url) return false;
10
+ if (url.startsWith('#')) return false;
11
+ if (url.startsWith('/')) return false;
12
+ if (/^[a-z][a-z\d+.-]*:/i.test(url)) return false;
13
+ return true;
14
+ }
15
+ function shouldTransformInlineCssUrl(url) {
16
+ if (!url) return false;
17
+ if (url.startsWith('#')) return false;
18
+ if (url.startsWith('//')) return false;
19
+ if (/^[a-z][a-z\d+.-]*:/i.test(url)) return false;
20
+ return true;
21
+ }
22
+ function shouldProcessInlineCssUrls(css, templates) {
23
+ cssUrlPattern.lastIndex = 0;
24
+ for (const match of css.matchAll(cssUrlPattern)) {
25
+ const url = (
26
+ match[1] ??
27
+ match[2] ??
28
+ match[3] ??
29
+ match[4] ??
30
+ match[5] ??
31
+ match[6] ??
32
+ match[7] ??
33
+ match[8] ??
34
+ ''
35
+ ).trim();
36
+ if (templates ? shouldTransformInlineCssUrl(url) : isRelativeCssUrl(url)) return true;
37
+ }
38
+ return false;
39
+ }
40
+ function rebaseCssUrl(url, cssHref) {
41
+ if (!isRelativeCssUrl(url)) return url;
42
+ const fakeOrigin = 'http://tanstack.local';
43
+ const resolved = new URL(url, new URL(cssHref, fakeOrigin));
44
+ if (resolved.origin === fakeOrigin)
45
+ return `${resolved.pathname}${resolved.search}${resolved.hash}`;
46
+ return resolved.href;
47
+ }
48
+ function processInlineCssUrls(options) {
49
+ const css = options.css.trim();
50
+ const templates = options.templates === true;
51
+ if (!shouldProcessInlineCssUrls(css, templates)) return { css };
52
+ const urls = [];
53
+ const result = transform({
54
+ filename: options.cssHref,
55
+ code: Buffer.from(css),
56
+ minify: true,
57
+ visitor: {
58
+ Url(url) {
59
+ if (!shouldTransformInlineCssUrl(url.url)) return url;
60
+ const rebasedUrl = rebaseCssUrl(url.url, options.cssHref);
61
+ if (templates) {
62
+ urls.push(rebasedUrl);
63
+ return {
64
+ ...url,
65
+ url: createInlineCssUrlPlaceholder(urls.length - 1),
66
+ };
67
+ }
68
+ return {
69
+ ...url,
70
+ url: rebasedUrl,
71
+ };
72
+ },
73
+ Rule: {
74
+ import(rule) {
75
+ if (!shouldTransformInlineCssUrl(rule.value.url)) return rule;
76
+ const rebasedUrl = rebaseCssUrl(rule.value.url, options.cssHref);
77
+ if (templates) urls.push(rebasedUrl);
78
+ const value = {
79
+ url: templates ? createInlineCssUrlPlaceholder(urls.length - 1) : rebasedUrl,
80
+ loc: rule.value.loc,
81
+ ...(rule.value.media ? { media: rule.value.media } : {}),
82
+ ...(rule.value.layer ? { layer: rule.value.layer } : {}),
83
+ ...(rule.value.supports ? { supports: rule.value.supports } : {}),
84
+ };
85
+ return {
86
+ ...rule,
87
+ value,
88
+ };
89
+ },
90
+ },
91
+ },
92
+ });
93
+ const transformedCss = Buffer.from(result.code).toString('utf8');
94
+ if (!templates || urls.length === 0) return { css: transformedCss };
95
+ return createInlineCssTemplate(transformedCss, urls);
96
+ }
97
+ function createInlineCssTemplate(cssWithPlaceholders, urls) {
98
+ const strings = [];
99
+ let css = '';
100
+ let cursor = 0;
101
+ for (let index = 0; index < urls.length; index++) {
102
+ const placeholder = createInlineCssUrlPlaceholder(index);
103
+ const placeholderIndex = cssWithPlaceholders.indexOf(placeholder, cursor);
104
+ if (placeholderIndex === -1)
105
+ throw new Error(
106
+ `TanStack Start inlineCss could not find CSS URL placeholder: ${placeholder}`,
107
+ );
108
+ const staticPart = cssWithPlaceholders.slice(cursor, placeholderIndex);
109
+ strings.push(staticPart);
110
+ css += staticPart + urls[index];
111
+ cursor = placeholderIndex + placeholder.length;
112
+ }
113
+ const finalStaticPart = cssWithPlaceholders.slice(cursor);
114
+ strings.push(finalStaticPart);
115
+ css += finalStaticPart;
116
+ return {
117
+ css,
118
+ template: {
119
+ strings,
120
+ urls,
121
+ },
122
+ };
123
+ }
124
+ function getCssAssetSource(source) {
125
+ if (typeof source === 'string') return source;
126
+ if (source instanceof Uint8Array) return Buffer.from(source).toString('utf8');
127
+ if (source == null) return void 0;
128
+ return String(source);
129
+ }
130
+ //#endregion
131
+ export { getCssAssetSource, processInlineCssUrls };
@@ -0,0 +1,64 @@
1
+ import { ManifestCssLink, ManifestScript, ScriptFormat } from '@tanstack/router-core';
2
+ import { InlineCssTemplate } from './inlineCss.js';
3
+ import { NormalizedClientBuild, NormalizedClientChunk } from '../types.js';
4
+ type RouteTreeRoute = {
5
+ filePath?: string;
6
+ preloads?: Array<string>;
7
+ scripts?: Array<ManifestScript>;
8
+ css?: Array<ManifestCssLink>;
9
+ children?: Array<string>;
10
+ };
11
+ type RouteTreeRoutes = Record<string, RouteTreeRoute>;
12
+ type AdditionalRouteManifestEntry = ManifestCssLink | ManifestScript;
13
+ interface ScannedClientChunks {
14
+ entryChunk: NormalizedClientChunk;
15
+ chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>;
16
+ routeChunksByFilePath: ReadonlyMap<string, Array<NormalizedClientChunk>>;
17
+ }
18
+ interface ManifestAssetResolvers {
19
+ getAssetPath: (fileName: string) => string;
20
+ getChunkPreloads: (chunk: NormalizedClientChunk) => Array<string>;
21
+ getStylesheetLink: (cssFile: string) => ManifestCssLink;
22
+ }
23
+ export interface StartManifest {
24
+ scriptFormat?: ScriptFormat;
25
+ routes: Record<string, RouteTreeRoute>;
26
+ inlineCss?: {
27
+ styles: Record<string, string>;
28
+ templates?: Record<string, InlineCssTemplate>;
29
+ };
30
+ }
31
+ export interface InlineCssOptions {
32
+ enabled: boolean;
33
+ transformAssets: boolean;
34
+ }
35
+ export declare function appendUniqueStrings(
36
+ target: Array<string> | undefined,
37
+ source: Array<string>,
38
+ ): string[] | undefined;
39
+ export declare function buildStartManifest(options: {
40
+ clientBuild: NormalizedClientBuild;
41
+ routeTreeRoutes: RouteTreeRoutes;
42
+ basePath: string;
43
+ inlineCss?: InlineCssOptions;
44
+ scriptFormat?: ScriptFormat;
45
+ additionalRouteAssets?: Partial<Record<string, ReadonlyArray<AdditionalRouteManifestEntry>>>;
46
+ }): StartManifest;
47
+ export declare function serializeStartManifest(startManifest: StartManifest): string;
48
+ export declare function scanClientChunks(clientBuild: NormalizedClientBuild): ScannedClientChunks;
49
+ export declare function createManifestAssetResolvers(basePath: string): ManifestAssetResolvers;
50
+ export declare function createChunkCssAssetCollector(options: {
51
+ chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>;
52
+ getStylesheetLink: (cssFile: string) => ManifestCssLink;
53
+ }): {
54
+ getChunkCssAssets: (chunk: NormalizedClientChunk) => Array<ManifestCssLink>;
55
+ };
56
+ export declare function buildRouteManifestRoutes(options: {
57
+ routeTreeRoutes: RouteTreeRoutes;
58
+ routeChunksByFilePath: ReadonlyMap<string, ReadonlyArray<NormalizedClientChunk>>;
59
+ chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>;
60
+ entryChunk: NormalizedClientChunk;
61
+ assetResolvers: ManifestAssetResolvers;
62
+ additionalRouteAssets?: Partial<Record<string, ReadonlyArray<AdditionalRouteManifestEntry>>>;
63
+ }): Record<string, RouteTreeRoute>;
64
+ export {};