@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,73 @@
1
+ import { getHandleRouteUpdateCode } from './handle-route-update.js';
2
+ import * as template from '@babel/template';
3
+ //#region src/core/hmr/vite-adapter.ts
4
+ /**
5
+ * Emits HMR accept code for Vite / native ESM HMR: `import.meta.hot.accept`
6
+ * with a callback that receives the freshly re-imported module.
7
+ *
8
+ * Framework-specific component runtimes still own component body patching.
9
+ * The route signature only suppresses a redundant data invalidation when an
10
+ * Octane update changed extracted component code but not the route definition.
11
+ */
12
+ function createViteHmrStatement(stableRouteOptionKeys, opts) {
13
+ const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys);
14
+ const routeIdFallback =
15
+ typeof opts.routeId === 'string' ? JSON.stringify(opts.routeId) : 'Route.id';
16
+ const routeSignature =
17
+ typeof opts.routeSignature === 'string' ? JSON.stringify(opts.routeSignature) : 'undefined';
18
+ const shouldInvalidateCurrentRoute =
19
+ opts.targetFramework === 'octane'
20
+ ? `typeof routeSignature !== 'string' || previousRouteSignature !== routeSignature`
21
+ : 'true';
22
+ const shouldInvalidateNextRoute =
23
+ opts.targetFramework === 'octane'
24
+ ? `typeof routeSignature !== 'string' || nextRouteSignature !== routeSignature`
25
+ : 'true';
26
+ return [
27
+ template.statement(
28
+ `
29
+ if (import.meta.hot) {
30
+ const hot = import.meta.hot
31
+ const hotData = hot.data ??= {}
32
+ const handleRouteUpdate = ${handleRouteUpdateCode}
33
+ const routeSignatureKey = Symbol.for('tanstack.router.hmr.route-signature')
34
+ const routeSignature = ${routeSignature}
35
+ const previousRouteSignature = hotData['tsr-route-signature']
36
+ const shouldInvalidateCurrentRoute = ${shouldInvalidateCurrentRoute}
37
+ Route[routeSignatureKey] = routeSignature
38
+ hotData['tsr-route-signature'] = routeSignature
39
+ const initialRouteId = ${routeIdFallback} ?? hotData['tsr-route-id']
40
+ if (initialRouteId) {
41
+ hotData['tsr-route-id'] = initialRouteId
42
+ }
43
+ const existingRoute =
44
+ typeof window !== 'undefined' && initialRouteId
45
+ ? window.__TSR_ROUTER__?.routesById?.[initialRouteId]
46
+ : undefined
47
+ if (initialRouteId && existingRoute && existingRoute !== Route) {
48
+ handleRouteUpdate(initialRouteId, Route, shouldInvalidateCurrentRoute)
49
+ hotData['tsr-route-update-handled'] = Route
50
+ }
51
+ import.meta.hot.accept((newModule) => {
52
+ if (Route && newModule && newModule.Route) {
53
+ const routeId = hotData['tsr-route-id'] ?? ${routeIdFallback}
54
+ if (routeId) {
55
+ hotData['tsr-route-id'] = routeId
56
+ }
57
+ if (hotData['tsr-route-update-handled'] === newModule.Route) {
58
+ delete hotData['tsr-route-update-handled']
59
+ return
60
+ }
61
+ const nextRouteSignature = newModule.Route[routeSignatureKey]
62
+ const shouldInvalidateNextRoute = ${shouldInvalidateNextRoute}
63
+ handleRouteUpdate(routeId, newModule.Route, shouldInvalidateNextRoute)
64
+ }
65
+ })
66
+ }
67
+ `,
68
+ { syntacticPlaceholders: true },
69
+ )(),
70
+ ];
71
+ }
72
+ //#endregion
73
+ export { createViteHmrStatement };
@@ -0,0 +1,22 @@
1
+ import { Config } from '../config.js';
2
+ import type * as t from '@babel/types';
3
+ /**
4
+ * Emits HMR accept code for bundlers with webpack-compatible `module.hot`
5
+ * semantics (classic webpack via `import.meta.webpackHot`, and Rspack).
6
+ *
7
+ * Unlike Vite's `hot.accept((newModule) => {...})` — where the callback receives
8
+ * the freshly re-imported module — webpack re-executes the module factory on
9
+ * accept, so our HMR logic must live at module top level and read the previous
10
+ * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and
11
+ * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.
12
+ *
13
+ * Returns an array of statements that patches route definitions during HMR.
14
+ */
15
+ export declare function createWebpackHmrStatement(
16
+ stableRouteOptionKeys: Array<string>,
17
+ opts: {
18
+ targetFramework: Config['target'];
19
+ routeId?: string;
20
+ routeSignature?: string;
21
+ },
22
+ ): Array<t.Statement>;
@@ -0,0 +1,78 @@
1
+ import { getHandleRouteUpdateCode } from './handle-route-update.js';
2
+ import * as template from '@babel/template';
3
+ //#region src/core/hmr/webpack-adapter.ts
4
+ /**
5
+ * Emits HMR accept code for bundlers with webpack-compatible `module.hot`
6
+ * semantics (classic webpack via `import.meta.webpackHot`, and Rspack).
7
+ *
8
+ * Unlike Vite's `hot.accept((newModule) => {...})` — where the callback receives
9
+ * the freshly re-imported module — webpack re-executes the module factory on
10
+ * accept, so our HMR logic must live at module top level and read the previous
11
+ * `routeId` out of `hot.data`. `hot.dispose` stashes it for the next run, and
12
+ * `hot.accept()` (no callback) enrolls us as a self-accepting boundary.
13
+ *
14
+ * Returns an array of statements that patches route definitions during HMR.
15
+ */
16
+ function createWebpackHmrStatement(stableRouteOptionKeys, opts) {
17
+ const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys);
18
+ const staticRouteIdLiteral =
19
+ typeof opts.routeId === 'string' ? JSON.stringify(opts.routeId) : 'undefined';
20
+ const routeSignature =
21
+ typeof opts.routeSignature === 'string' ? JSON.stringify(opts.routeSignature) : 'undefined';
22
+ const shouldInvalidateRoute =
23
+ opts.targetFramework === 'octane'
24
+ ? `typeof routeSignature !== 'string' || previousRouteSignature !== routeSignature`
25
+ : 'true';
26
+ const reactRefreshCall =
27
+ opts.targetFramework === 'react'
28
+ ? `
29
+ try {
30
+ const tsrReactRefreshUtils =
31
+ typeof __react_refresh_utils__ !== 'undefined'
32
+ ? __react_refresh_utils__
33
+ : undefined
34
+ const tsrEnqueueUpdate =
35
+ tsrReactRefreshUtils && typeof tsrReactRefreshUtils.enqueueUpdate === 'function'
36
+ ? tsrReactRefreshUtils.enqueueUpdate
37
+ : undefined
38
+ if (tsrEnqueueUpdate) {
39
+ tsrEnqueueUpdate(() => {})
40
+ }
41
+ } catch (_err) { /* noop */ }`
42
+ : '';
43
+ return [
44
+ template.statement(
45
+ `
46
+ if (import.meta.webpackHot) {
47
+ const hot = import.meta.webpackHot
48
+ const hotData = hot.data ??= {}
49
+ const routeSignature = ${routeSignature}
50
+ const previousRouteSignature = hotData['tsr-route-signature']
51
+ const shouldInvalidateRoute = ${shouldInvalidateRoute}
52
+ hotData['tsr-route-signature'] = routeSignature
53
+ const routeId = hotData['tsr-route-id'] ?? Route.id ?? (Route.isRoot ? '__root__' : ${staticRouteIdLiteral})
54
+ if (routeId) {
55
+ hotData['tsr-route-id'] = routeId
56
+ }
57
+ const existingRoute =
58
+ typeof window !== 'undefined' && routeId
59
+ ? window.__TSR_ROUTER__?.routesById?.[routeId]
60
+ : undefined
61
+ if (routeId && existingRoute && existingRoute !== Route) {
62
+ (${handleRouteUpdateCode})(routeId, Route, shouldInvalidateRoute)${reactRefreshCall}
63
+ }
64
+ hot.dispose((data) => {
65
+ if (routeId) {
66
+ data['tsr-route-id'] = routeId
67
+ }
68
+ data['tsr-route-signature'] = routeSignature
69
+ })
70
+ hot.accept()
71
+ }
72
+ `,
73
+ { syntacticPlaceholders: true },
74
+ )(),
75
+ ];
76
+ }
77
+ //#endregion
78
+ export { createWebpackHmrStatement };
@@ -0,0 +1,10 @@
1
+ import { Config } from './config.js';
2
+ import { RouterPluginContext } from './router-plugin-context.js';
3
+ import { UnpluginFactory } from 'unplugin';
4
+ export declare function createRouterCodeSplitterPlugin(
5
+ options: Partial<Config | (() => Config)> | undefined,
6
+ routerPluginContext: RouterPluginContext,
7
+ ): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>>;
8
+ export declare const unpluginRouterCodeSplitterFactory: UnpluginFactory<
9
+ Partial<Config | (() => Config)> | undefined
10
+ >;
@@ -0,0 +1,244 @@
1
+ import { getConfig, splitGroupingsSchema } from './config.js';
2
+ import {
3
+ defaultCodeSplitGroupings,
4
+ splitRouteIdentNodes,
5
+ tsrShared,
6
+ tsrSplit,
7
+ } from './constants.js';
8
+ import { debug, normalizePath, routeFactoryCallCodeFilter } from './utils.js';
9
+ import {
10
+ compileCodeSplitReferenceRoute,
11
+ compileCodeSplitSharedRoute,
12
+ compileCodeSplitVirtualRoute,
13
+ computeSharedBindings,
14
+ detectCodeSplitGroupingsFromRoute,
15
+ } from './code-splitter/compilers.js';
16
+ import {
17
+ getReferenceRouteCompilerPlugins,
18
+ getVirtualRouteCompilerPlugins,
19
+ } from './code-splitter/plugins/framework-plugins.js';
20
+ import { createRouterPluginContext } from './router-plugin-context.js';
21
+ import { validateFrameworkPluginOrder } from './framework-plugin-order.js';
22
+ import { fileURLToPath, pathToFileURL } from 'node:url';
23
+ import { decodeIdentifier, logDiff } from '@tanstack/router-utils';
24
+ //#region src/core/router-code-splitter-plugin.ts
25
+ /**
26
+ * It is important to familiarize yourself with how the code-splitting works in this plugin.
27
+ * https://github.com/TanStack/router/pull/3355
28
+ */
29
+ var CODE_SPLITTER_PLUGIN_NAME = 'tanstack-router:code-splitter:compile-reference-file';
30
+ function createRouterCodeSplitterPlugin(options = {}, routerPluginContext) {
31
+ let ROOT = process.cwd();
32
+ let userConfig;
33
+ function initUserConfig() {
34
+ if (typeof options === 'function') userConfig = options();
35
+ else userConfig = getConfig(options, ROOT);
36
+ }
37
+ const isProduction = process.env.NODE_ENV === 'production';
38
+ const sharedBindingsMap = /* @__PURE__ */ new Map();
39
+ const getGlobalCodeSplitGroupings = () => {
40
+ return userConfig.codeSplittingOptions?.defaultBehavior || defaultCodeSplitGroupings;
41
+ };
42
+ const getShouldSplitFn = () => {
43
+ return userConfig.codeSplittingOptions?.splitBehavior;
44
+ };
45
+ const shouldAddHmr = () => {
46
+ return (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction;
47
+ };
48
+ const handleCompilingReferenceFile = (code, id, generatorNodeInfo) => {
49
+ if (debug) console.info('Compiling Route: ', id);
50
+ const fromCode = detectCodeSplitGroupingsFromRoute({
51
+ code,
52
+ filename: id,
53
+ });
54
+ if (fromCode.groupings !== void 0) {
55
+ const res = splitGroupingsSchema.safeParse(fromCode.groupings);
56
+ if (!res.success) {
57
+ const message = res.error.issues.map((e) => e.message).join('. ');
58
+ throw new Error(`The groupings for the route "${id}" are invalid.\n${message}`);
59
+ }
60
+ }
61
+ const pluginSplitBehavior = getShouldSplitFn()?.({ routeId: generatorNodeInfo.routeId });
62
+ if (pluginSplitBehavior) {
63
+ const res = splitGroupingsSchema.safeParse(pluginSplitBehavior);
64
+ if (!res.success) {
65
+ const message = res.error.issues.map((e) => e.message).join('. ');
66
+ throw new Error(
67
+ `The groupings returned when using \`splitBehavior\` for the route "${id}" are invalid.\n${message}`,
68
+ );
69
+ }
70
+ }
71
+ const splitGroupings =
72
+ fromCode.groupings ?? pluginSplitBehavior ?? getGlobalCodeSplitGroupings();
73
+ const sharedBindings = computeSharedBindings({
74
+ code,
75
+ filename: id,
76
+ codeSplitGroupings: splitGroupings,
77
+ });
78
+ if (sharedBindings.size > 0) sharedBindingsMap.set(id, sharedBindings);
79
+ else sharedBindingsMap.delete(id);
80
+ const addHmr = shouldAddHmr();
81
+ const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite';
82
+ const compiledReferenceRoute = compileCodeSplitReferenceRoute({
83
+ code,
84
+ codeSplitGroupings: splitGroupings,
85
+ targetFramework: userConfig.target,
86
+ filename: id,
87
+ id,
88
+ deleteNodes: userConfig.codeSplittingOptions?.deleteNodes
89
+ ? new Set(userConfig.codeSplittingOptions.deleteNodes)
90
+ : void 0,
91
+ addHmr,
92
+ hmrStyle,
93
+ hmrRouteId: generatorNodeInfo.routeId,
94
+ sharedBindings: sharedBindings.size > 0 ? sharedBindings : void 0,
95
+ compilerPlugins: [
96
+ ...(getReferenceRouteCompilerPlugins({
97
+ targetFramework: userConfig.target,
98
+ addHmr,
99
+ hmrStyle,
100
+ }) ?? []),
101
+ ...(userConfig.codeSplittingOptions?.compilerPlugins ?? []),
102
+ ],
103
+ });
104
+ if (compiledReferenceRoute === null) {
105
+ if (debug) console.info(`No changes made to route "${id}", skipping code-splitting.`);
106
+ return null;
107
+ }
108
+ if (debug) {
109
+ logDiff(code, compiledReferenceRoute.code);
110
+ console.log('Output:\n', compiledReferenceRoute.code + '\n\n');
111
+ }
112
+ return compiledReferenceRoute;
113
+ };
114
+ const handleCompilingVirtualFile = (code, id) => {
115
+ if (debug) console.info('Splitting Route: ', id);
116
+ const [_, ...pathnameParts] = id.split('?');
117
+ const splitValue = new URLSearchParams(pathnameParts.join('?')).get(tsrSplit);
118
+ if (!splitValue)
119
+ throw new Error(`The split value for the virtual route "${id}" was not found.`);
120
+ const rawGrouping = decodeIdentifier(splitValue);
121
+ const grouping = [...new Set(rawGrouping)].filter((p) => splitRouteIdentNodes.includes(p));
122
+ const baseId = id.split('?')[0];
123
+ const result = compileCodeSplitVirtualRoute({
124
+ code,
125
+ filename: id,
126
+ splitTargets: grouping,
127
+ sharedBindings: sharedBindingsMap.get(baseId),
128
+ compilerPlugins: getVirtualRouteCompilerPlugins({
129
+ targetFramework: userConfig.target,
130
+ addHmr: shouldAddHmr(),
131
+ hmrStyle: userConfig.plugin?.hmr?.style ?? 'vite',
132
+ }),
133
+ });
134
+ if (debug) {
135
+ logDiff(code, result.code);
136
+ console.log('Output:\n', result.code + '\n\n');
137
+ }
138
+ return result;
139
+ };
140
+ return [
141
+ {
142
+ name: 'tanstack-router:code-splitter:compile-reference-file',
143
+ enforce: 'pre',
144
+ transform: {
145
+ filter: {
146
+ id: {
147
+ exclude: [tsrSplit, tsrShared],
148
+ include: [/\.(m|c)?(j|t)sx?$/, /\.tsrx(?:$|\?)/],
149
+ },
150
+ code: { include: routeFactoryCallCodeFilter },
151
+ },
152
+ handler(code, id) {
153
+ const normalizedId = normalizePath(id);
154
+ const generatorFileInfo = routerPluginContext.routesByFile.get(normalizedId);
155
+ if (generatorFileInfo)
156
+ return handleCompilingReferenceFile(code, normalizedId, generatorFileInfo);
157
+ return null;
158
+ },
159
+ },
160
+ vite: {
161
+ configResolved(config) {
162
+ ROOT = config.root;
163
+ initUserConfig();
164
+ validateFrameworkPluginOrder({
165
+ framework: userConfig.target,
166
+ plugins: config.plugins,
167
+ routerPluginName: CODE_SPLITTER_PLUGIN_NAME,
168
+ });
169
+ },
170
+ applyToEnvironment(environment) {
171
+ if (userConfig.plugin?.vite?.environmentName)
172
+ return userConfig.plugin.vite.environmentName === environment.name;
173
+ return true;
174
+ },
175
+ },
176
+ rspack() {
177
+ ROOT = process.cwd();
178
+ initUserConfig();
179
+ },
180
+ webpack() {
181
+ ROOT = process.cwd();
182
+ initUserConfig();
183
+ },
184
+ },
185
+ {
186
+ name: 'tanstack-router:code-splitter:compile-virtual-file',
187
+ enforce: 'pre',
188
+ transform: {
189
+ filter: { id: /tsr-split/ },
190
+ handler(code, id) {
191
+ const url = pathToFileURL(id);
192
+ url.searchParams.delete('v');
193
+ return handleCompilingVirtualFile(code, normalizePath(fileURLToPath(url)));
194
+ },
195
+ },
196
+ vite: {
197
+ applyToEnvironment(environment) {
198
+ if (userConfig.plugin?.vite?.environmentName)
199
+ return userConfig.plugin.vite.environmentName === environment.name;
200
+ return true;
201
+ },
202
+ },
203
+ },
204
+ {
205
+ name: 'tanstack-router:code-splitter:compile-shared-file',
206
+ enforce: 'pre',
207
+ transform: {
208
+ filter: { id: /tsr-shared/ },
209
+ handler(code, id) {
210
+ const url = pathToFileURL(id);
211
+ url.searchParams.delete('v');
212
+ const normalizedId = normalizePath(fileURLToPath(url));
213
+ const [baseId] = normalizedId.split('?');
214
+ if (!baseId) return null;
215
+ const sharedBindings = sharedBindingsMap.get(baseId);
216
+ if (!sharedBindings || sharedBindings.size === 0) return null;
217
+ if (debug) console.info('Compiling Shared Module: ', id);
218
+ const result = compileCodeSplitSharedRoute({
219
+ code,
220
+ sharedBindings,
221
+ filename: normalizedId,
222
+ });
223
+ if (debug) {
224
+ logDiff(code, result.code);
225
+ console.log('Output:\n', result.code + '\n\n');
226
+ }
227
+ return result;
228
+ },
229
+ },
230
+ vite: {
231
+ applyToEnvironment(environment) {
232
+ if (userConfig.plugin?.vite?.environmentName)
233
+ return userConfig.plugin.vite.environmentName === environment.name;
234
+ return true;
235
+ },
236
+ },
237
+ },
238
+ ];
239
+ }
240
+ var unpluginRouterCodeSplitterFactory = (options = {}) => {
241
+ return createRouterCodeSplitterPlugin(options, createRouterPluginContext());
242
+ };
243
+ //#endregion
244
+ export { createRouterCodeSplitterPlugin, unpluginRouterCodeSplitterFactory };
@@ -0,0 +1,5 @@
1
+ import { Config } from './config.js';
2
+ import { UnpluginFactory } from 'unplugin';
3
+ export declare const unpluginRouterComposedFactory: UnpluginFactory<
4
+ Partial<Config | (() => Config)> | undefined
5
+ >;
@@ -0,0 +1,62 @@
1
+ import { createRouterPluginContext } from './router-plugin-context.js';
2
+ import { createRouterCodeSplitterPlugin } from './router-code-splitter-plugin.js';
3
+ import { createRouterGeneratorPlugin } from './router-generator-plugin.js';
4
+ import { createRouterHmrPlugin } from './router-hmr-plugin.js';
5
+ import { getConfig } from '#tanstack-start/router-generator';
6
+ //#region src/core/router-composed-plugin.ts
7
+ var INLINE_CSS_DEFAULT_DEFINES = {
8
+ 'process.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),
9
+ 'import.meta.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),
10
+ };
11
+ function applyWebpackInlineCssDefaultDefinePlugin(compiler) {
12
+ new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
13
+ }
14
+ function applyRspackInlineCssDefaultDefinePlugin(compiler) {
15
+ new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
16
+ }
17
+ var unpluginRouterComposedFactory = (options = {}, _meta) => {
18
+ const ROOT = process.cwd();
19
+ const userConfig = getConfig(typeof options === 'function' ? options() : options, ROOT);
20
+ const routerPluginContext = createRouterPluginContext();
21
+ const getPlugin = (plugin) => {
22
+ if (!Array.isArray(plugin)) return [plugin];
23
+ return plugin;
24
+ };
25
+ const routerGenerator = getPlugin(createRouterGeneratorPlugin(options, routerPluginContext));
26
+ const routerCodeSplitter = getPlugin(
27
+ createRouterCodeSplitterPlugin(options, routerPluginContext),
28
+ );
29
+ const result = [
30
+ {
31
+ name: 'tanstack:router-inline-css-defaults',
32
+ vite: {
33
+ config() {
34
+ return { define: { ...INLINE_CSS_DEFAULT_DEFINES } };
35
+ },
36
+ },
37
+ webpack(compiler) {
38
+ applyWebpackInlineCssDefaultDefinePlugin(compiler);
39
+ },
40
+ rspack(compiler) {
41
+ applyRspackInlineCssDefaultDefinePlugin(compiler);
42
+ },
43
+ esbuild: {
44
+ config(options) {
45
+ options.define = {
46
+ ...INLINE_CSS_DEFAULT_DEFINES,
47
+ ...options.define,
48
+ };
49
+ },
50
+ },
51
+ },
52
+ ...routerGenerator,
53
+ ];
54
+ if (userConfig.autoCodeSplitting) result.push(...routerCodeSplitter);
55
+ if (!(process.env.NODE_ENV === 'production') && !userConfig.autoCodeSplitting) {
56
+ const routerHmr = getPlugin(createRouterHmrPlugin(options, routerPluginContext));
57
+ result.push(...routerHmr);
58
+ }
59
+ return result;
60
+ };
61
+ //#endregion
62
+ export { unpluginRouterComposedFactory };
@@ -0,0 +1,10 @@
1
+ import { UnpluginFactory } from 'unplugin';
2
+ import { Config } from './config.js';
3
+ import { RouterPluginContext } from './router-plugin-context.js';
4
+ export declare function createRouterGeneratorPlugin(
5
+ options: Partial<Config | (() => Config)> | undefined,
6
+ routerPluginContext: RouterPluginContext,
7
+ ): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>>;
8
+ export declare const unpluginRouterGeneratorFactory: UnpluginFactory<
9
+ Partial<Config | (() => Config)> | undefined
10
+ >;
@@ -0,0 +1,125 @@
1
+ import { getConfig as getConfig$1 } from './config.js';
2
+ import { createRouterPluginContext } from './router-plugin-context.js';
3
+ import { validateFrameworkPluginOrder } from './framework-plugin-order.js';
4
+ import { Generator, resolveConfigPath } from '#tanstack-start/router-generator';
5
+ import { isAbsolute, join, normalize } from 'node:path';
6
+ //#region src/core/router-generator-plugin.ts
7
+ var PLUGIN_NAME = 'unplugin:router-generator';
8
+ function createRouterGeneratorPlugin(options = {}, routerPluginContext) {
9
+ let ROOT = process.cwd();
10
+ let userConfig;
11
+ let generator;
12
+ const routeGenerationDisabled = () => userConfig.enableRouteGeneration === false;
13
+ const getRoutesDirectoryPath = () => {
14
+ return isAbsolute(userConfig.routesDirectory)
15
+ ? userConfig.routesDirectory
16
+ : join(ROOT, userConfig.routesDirectory);
17
+ };
18
+ const initConfigAndGenerator = (opts) => {
19
+ if (opts?.root) ROOT = opts.root;
20
+ if (typeof options === 'function') userConfig = options();
21
+ else userConfig = getConfig$1(options, ROOT);
22
+ generator = new Generator({
23
+ config: userConfig,
24
+ root: ROOT,
25
+ });
26
+ };
27
+ const generate = async (opts) => {
28
+ if (routeGenerationDisabled()) return;
29
+ let generatorEvent = void 0;
30
+ if (opts) {
31
+ const filePath = normalize(opts.file);
32
+ if (filePath === resolveConfigPath({ configDirectory: ROOT })) {
33
+ initConfigAndGenerator();
34
+ return;
35
+ }
36
+ generatorEvent = {
37
+ path: filePath,
38
+ type: opts.event,
39
+ };
40
+ }
41
+ try {
42
+ await generator.run(generatorEvent);
43
+ routerPluginContext.routesByFile = generator.getRoutesByFileMap();
44
+ } catch (e) {
45
+ console.error(e);
46
+ }
47
+ };
48
+ return {
49
+ name: 'tanstack:router-generator',
50
+ enforce: 'pre',
51
+ async watchChange(id, { event }) {
52
+ await generate({
53
+ file: id,
54
+ event,
55
+ });
56
+ },
57
+ vite: {
58
+ async configResolved(config) {
59
+ initConfigAndGenerator({ root: config.root });
60
+ if (userConfig.target === 'octane')
61
+ validateFrameworkPluginOrder({
62
+ framework: userConfig.target,
63
+ plugins: config.plugins,
64
+ routerPluginName: 'tanstack:router-generator',
65
+ });
66
+ await generate();
67
+ },
68
+ },
69
+ rspack(compiler) {
70
+ initConfigAndGenerator();
71
+ let handle = null;
72
+ compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate());
73
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
74
+ if (handle) return;
75
+ const routesDirectoryPath = getRoutesDirectoryPath();
76
+ handle = (await import('chokidar'))
77
+ .watch(routesDirectoryPath, { ignoreInitial: true })
78
+ .on('add', (file) =>
79
+ generate({
80
+ file,
81
+ event: 'create',
82
+ }),
83
+ );
84
+ await generate();
85
+ });
86
+ compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
87
+ if (handle) await handle.close();
88
+ });
89
+ },
90
+ webpack(compiler) {
91
+ initConfigAndGenerator();
92
+ let handle = null;
93
+ compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate());
94
+ compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
95
+ if (handle) return;
96
+ const routesDirectoryPath = getRoutesDirectoryPath();
97
+ handle = (await import('chokidar'))
98
+ .watch(routesDirectoryPath, { ignoreInitial: true })
99
+ .on('add', (file) =>
100
+ generate({
101
+ file,
102
+ event: 'create',
103
+ }),
104
+ );
105
+ await generate();
106
+ });
107
+ compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {
108
+ if (handle) await handle.close();
109
+ });
110
+ compiler.hooks.done.tap(PLUGIN_NAME, () => {
111
+ console.info('✅ unplugin:router-generator: route-tree generation done');
112
+ });
113
+ },
114
+ esbuild: {
115
+ config() {
116
+ initConfigAndGenerator();
117
+ },
118
+ },
119
+ };
120
+ }
121
+ var unpluginRouterGeneratorFactory = (options = {}) => {
122
+ return createRouterGeneratorPlugin(options, createRouterPluginContext());
123
+ };
124
+ //#endregion
125
+ export { createRouterGeneratorPlugin, unpluginRouterGeneratorFactory };
@@ -0,0 +1,13 @@
1
+ import { UnpluginFactory } from 'unplugin';
2
+ import { Config } from './config.js';
3
+ import { RouterPluginContext } from './router-plugin-context.js';
4
+ /**
5
+ * This plugin adds HMR support for file routes.
6
+ * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
7
+ * handles HMR for code-split routes itself.
8
+ */
9
+ export declare function createRouterHmrPlugin(
10
+ options: Partial<Config | (() => Config)> | undefined,
11
+ routerPluginContext: RouterPluginContext,
12
+ ): ReturnType<UnpluginFactory<Partial<Config> | undefined>>;
13
+ export declare const unpluginRouterHmrFactory: UnpluginFactory<Partial<Config> | undefined>;