@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,864 @@
1
+ import './filesystem/physical/rootPathId.js';
2
+ import path from 'node:path';
3
+ import * as fsp from 'node:fs/promises';
4
+ import * as prettier from 'prettier';
5
+ //#region src/utils.ts
6
+ /**
7
+ * Prefix map for O(1) parent route lookups.
8
+ * Maps each route path prefix to the route node that owns that prefix.
9
+ * Enables finding longest matching parent without linear search.
10
+ */
11
+ var RoutePrefixMap = class {
12
+ constructor(routes) {
13
+ this.prefixToRoute = /* @__PURE__ */ new Map();
14
+ for (const route of routes) {
15
+ if (!route.routePath || route.routePath === `/__root`) continue;
16
+ if (
17
+ route._fsRouteType === 'lazy' ||
18
+ route._fsRouteType === 'loader' ||
19
+ route._fsRouteType === 'component' ||
20
+ route._fsRouteType === 'pendingComponent' ||
21
+ route._fsRouteType === 'errorComponent' ||
22
+ route._fsRouteType === 'notFoundComponent'
23
+ )
24
+ continue;
25
+ this.prefixToRoute.set(route.routePath, route);
26
+ }
27
+ }
28
+ /**
29
+ * Find the longest matching parent route for a given path.
30
+ * O(k) where k is the number of path segments, not O(n) routes.
31
+ */
32
+ findParent(routePath) {
33
+ if (!routePath || routePath === '/') return null;
34
+ let searchPath = routePath;
35
+ while (searchPath.length > 0) {
36
+ const lastSlash = searchPath.lastIndexOf('/');
37
+ if (lastSlash <= 0) break;
38
+ searchPath = searchPath.substring(0, lastSlash);
39
+ const parent = this.prefixToRoute.get(searchPath);
40
+ if (parent && parent.routePath !== routePath) return parent;
41
+ }
42
+ return null;
43
+ }
44
+ /**
45
+ * Check if a route exists at the given path.
46
+ */
47
+ has(routePath) {
48
+ return this.prefixToRoute.has(routePath);
49
+ }
50
+ /**
51
+ * Get a route by exact path.
52
+ */
53
+ get(routePath) {
54
+ return this.prefixToRoute.get(routePath);
55
+ }
56
+ };
57
+ function multiSortBy(arr, accessors = [(d) => d]) {
58
+ const len = arr.length;
59
+ const indexed = new Array(len);
60
+ for (let i = 0; i < len; i++) {
61
+ const item = arr[i];
62
+ const keys = new Array(accessors.length);
63
+ for (let j = 0; j < accessors.length; j++) keys[j] = accessors[j](item);
64
+ indexed[i] = {
65
+ item,
66
+ index: i,
67
+ keys,
68
+ };
69
+ }
70
+ indexed.sort((a, b) => {
71
+ for (let j = 0; j < accessors.length; j++) {
72
+ const ao = a.keys[j];
73
+ const bo = b.keys[j];
74
+ if (typeof ao === 'undefined') {
75
+ if (typeof bo === 'undefined') continue;
76
+ return 1;
77
+ }
78
+ if (ao === bo) continue;
79
+ return ao > bo ? 1 : -1;
80
+ }
81
+ return a.index - b.index;
82
+ });
83
+ const result = new Array(len);
84
+ for (let i = 0; i < len; i++) result[i] = indexed[i].item;
85
+ return result;
86
+ }
87
+ /**
88
+ * Sorts route nodes by root, path depth, index status, and finally `routePath`.
89
+ * The `routePath` comparison keeps the output consistent when the earlier
90
+ * values are the same.
91
+ */
92
+ function sortRouteNodes(routeNodes, indexTokenSegmentRegex) {
93
+ return multiSortBy(routeNodes, [
94
+ (d) => (d.routePath?.includes(`/__root`) ? -1 : 1),
95
+ (d) => (d.routePath === void 0 ? void 0 : countSlashSeparatedParts(d.routePath)),
96
+ (d) => {
97
+ const segments = d.routePath?.split('/').filter(Boolean) ?? [];
98
+ const last = segments[segments.length - 1] ?? '';
99
+ return indexTokenSegmentRegex.test(last) ? -1 : 1;
100
+ },
101
+ (d) => d.routePath,
102
+ ]);
103
+ }
104
+ function cleanPath(path) {
105
+ return path.replace(/\/{2,}/g, '/');
106
+ }
107
+ function trimPathLeft(path) {
108
+ return path === '/' ? path : path.replace(/^\/{1,}/, '');
109
+ }
110
+ function removeLeadingSlash(path) {
111
+ return path.replace(/^\//, '');
112
+ }
113
+ function removeTrailingSlash(s) {
114
+ return s.replace(/\/$/, '');
115
+ }
116
+ var BRACKET_CONTENT_RE = /\[(.*?)\]/g;
117
+ var SPLIT_REGEX = /(?<!\[)\.(?!\])/g;
118
+ /**
119
+ * Characters that cannot be escaped in square brackets.
120
+ * These are characters that would cause issues in URLs or file systems.
121
+ */
122
+ var DISALLOWED_ESCAPE_CHARS = new Set([
123
+ '/',
124
+ '\\',
125
+ '?',
126
+ '#',
127
+ ':',
128
+ '*',
129
+ '<',
130
+ '>',
131
+ '|',
132
+ '!',
133
+ '$',
134
+ '%',
135
+ ]);
136
+ function determineInitialRoutePathFromParts(routePath, parts) {
137
+ const originalRoutePath = cleanPath(`/${cleanPath(parts.join('/')) || ''}`) || '';
138
+ return {
139
+ routePath:
140
+ cleanPath(
141
+ `/${parts
142
+ .map((part) => {
143
+ let match;
144
+ while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {
145
+ const character = match[1];
146
+ if (character === void 0) continue;
147
+ if (DISALLOWED_ESCAPE_CHARS.has(character)) {
148
+ console.error(
149
+ `Error: Disallowed character "${character}" found in square brackets in route path "${routePath}".\nYou cannot use any of the following characters in square brackets: ${Array.from(DISALLOWED_ESCAPE_CHARS).join(', ')}\nPlease remove and/or replace them.`,
150
+ );
151
+ process.exit(1);
152
+ }
153
+ }
154
+ return part.replace(BRACKET_CONTENT_RE, '$1');
155
+ })
156
+ .join('/')}`,
157
+ ) || '',
158
+ originalRoutePath,
159
+ };
160
+ }
161
+ function determineInitialRoutePath(routePath) {
162
+ return determineInitialRoutePathFromParts(routePath, routePath.split(SPLIT_REGEX));
163
+ }
164
+ /**
165
+ * Resolves bracket escapes in an explicit route path or ID without applying
166
+ * the dot-delimited flat-file route convention.
167
+ */
168
+ function determineInitialRoutePathFromExplicitPath(routePath) {
169
+ return determineInitialRoutePathFromParts(routePath, [routePath]);
170
+ }
171
+ /**
172
+ * Checks if a segment is fully escaped (entirely wrapped in brackets with no nested brackets).
173
+ * E.g., "[index]" -> true, "[_layout]" -> true, "foo[.]bar" -> false, "index" -> false
174
+ */
175
+ function isFullyEscapedSegment(originalSegment) {
176
+ return (
177
+ originalSegment.startsWith('[') &&
178
+ originalSegment.endsWith(']') &&
179
+ !originalSegment.slice(1, -1).includes('[') &&
180
+ !originalSegment.slice(1, -1).includes(']')
181
+ );
182
+ }
183
+ /**
184
+ * Checks if the leading underscore in a segment is escaped.
185
+ * Returns true if:
186
+ * - Segment starts with [_] pattern: "[_]layout" -> "_layout"
187
+ * - Segment is fully escaped and content starts with _: "[_1nd3x]" -> "_1nd3x"
188
+ */
189
+ function hasEscapedLeadingUnderscore(originalSegment) {
190
+ return (
191
+ originalSegment.startsWith('[_]') ||
192
+ (originalSegment.startsWith('[_') && isFullyEscapedSegment(originalSegment))
193
+ );
194
+ }
195
+ /**
196
+ * Checks if the trailing underscore in a segment is escaped.
197
+ * Returns true if:
198
+ * - Segment ends with [_] pattern: "blog[_]" -> "blog_"
199
+ * - Segment is fully escaped and content ends with _: "[_r0ut3_]" -> "_r0ut3_"
200
+ */
201
+ function hasEscapedTrailingUnderscore(originalSegment) {
202
+ return (
203
+ originalSegment.endsWith('[_]') ||
204
+ (originalSegment.endsWith('_]') && isFullyEscapedSegment(originalSegment))
205
+ );
206
+ }
207
+ function countRoutePathSegments(routePath) {
208
+ const path = routePath ?? '';
209
+ let count = 0;
210
+ let inSegment = false;
211
+ for (let i = 0; i < path.length; i++) {
212
+ if (path[i] === '/') {
213
+ inSegment = false;
214
+ continue;
215
+ }
216
+ if (!inSegment) {
217
+ count++;
218
+ inSegment = true;
219
+ }
220
+ }
221
+ return count;
222
+ }
223
+ function countSlashSeparatedParts(path) {
224
+ let count = 1;
225
+ for (let i = 0; i < path.length; i++) if (path[i] === '/') count++;
226
+ return count;
227
+ }
228
+ function hasRoutePathSegmentMetadata(metadata) {
229
+ return !!(metadata?.literalLeadingUnderscore || metadata?.literalTrailingUnderscore);
230
+ }
231
+ function mergeRoutePathSegmentMetadata(current, incoming) {
232
+ const hasCurrent = hasRoutePathSegmentMetadata(current);
233
+ const hasIncoming = hasRoutePathSegmentMetadata(incoming);
234
+ if (!hasCurrent) return hasIncoming ? incoming : void 0;
235
+ if (!hasIncoming) return current;
236
+ return {
237
+ literalLeadingUnderscore: current.literalLeadingUnderscore || incoming.literalLeadingUnderscore,
238
+ literalTrailingUnderscore:
239
+ current.literalTrailingUnderscore || incoming.literalTrailingUnderscore,
240
+ };
241
+ }
242
+ function createRoutePathSegmentMetadata(routePath = '/', originalPath) {
243
+ if (!originalPath) return void 0;
244
+ const routeSegments = routePath.split('/');
245
+ const originalSegments = originalPath.split('/');
246
+ const metadata = new Array(routeSegments.length);
247
+ let hasMetadata = false;
248
+ for (let i = 0; i < routeSegments.length; i++) {
249
+ const segment = routeSegments[i];
250
+ const originalSegment = originalSegments[i] || '';
251
+ const literalLeadingUnderscore =
252
+ segment.startsWith('_') && hasEscapedLeadingUnderscore(originalSegment);
253
+ const literalTrailingUnderscore =
254
+ segment.endsWith('_') && hasEscapedTrailingUnderscore(originalSegment);
255
+ if (!literalLeadingUnderscore && !literalTrailingUnderscore) continue;
256
+ hasMetadata = true;
257
+ metadata[i] = {
258
+ literalLeadingUnderscore: literalLeadingUnderscore || void 0,
259
+ literalTrailingUnderscore: literalTrailingUnderscore || void 0,
260
+ };
261
+ }
262
+ return hasMetadata ? metadata : void 0;
263
+ }
264
+ function createLiteralRoutePathSegmentMetadata(routePath, parent, literalNewSegments = false) {
265
+ const routeSegments = routePath.split('/');
266
+ const metadata = new Array(routeSegments.length);
267
+ const parentDepth = countRoutePathSegments(parent?.routePath);
268
+ let hasMetadata = false;
269
+ let depth = 0;
270
+ for (let i = 0; i < routeSegments.length; i++) {
271
+ const segment = routeSegments[i];
272
+ metadata[i] = parent?._routePathSegmentMetadata?.[i];
273
+ hasMetadata ||= hasRoutePathSegmentMetadata(metadata[i]);
274
+ if (!segment) continue;
275
+ if (literalNewSegments && depth >= parentDepth) {
276
+ const literalLeadingUnderscore = segment.startsWith('_');
277
+ const literalTrailingUnderscore = segment.endsWith('_');
278
+ if (literalLeadingUnderscore || literalTrailingUnderscore) {
279
+ metadata[i] = mergeRoutePathSegmentMetadata(metadata[i], {
280
+ literalLeadingUnderscore: literalLeadingUnderscore || void 0,
281
+ literalTrailingUnderscore: literalTrailingUnderscore || void 0,
282
+ });
283
+ hasMetadata = true;
284
+ }
285
+ }
286
+ depth++;
287
+ }
288
+ return hasMetadata ? metadata : void 0;
289
+ }
290
+ function joinRoutePathSegmentMetadata(routePath, prefixPath, prefixMetadata, childMetadata) {
291
+ const metadata = new Array(countSlashSeparatedParts(routePath));
292
+ let hasMetadata = false;
293
+ if (prefixMetadata)
294
+ for (let i = 0; i < prefixMetadata.length && i < metadata.length; i++) {
295
+ metadata[i] = prefixMetadata[i];
296
+ hasMetadata ||= hasRoutePathSegmentMetadata(metadata[i]);
297
+ }
298
+ const offset = countRoutePathSegments(prefixPath);
299
+ if (childMetadata)
300
+ for (let i = 1; i < childMetadata.length; i++) {
301
+ const targetIndex = offset + i;
302
+ if (targetIndex >= metadata.length) break;
303
+ metadata[targetIndex] = mergeRoutePathSegmentMetadata(
304
+ metadata[targetIndex],
305
+ childMetadata[i],
306
+ );
307
+ hasMetadata ||= hasRoutePathSegmentMetadata(metadata[targetIndex]);
308
+ }
309
+ return hasMetadata ? metadata : void 0;
310
+ }
311
+ var backslashRegex = /\\/g;
312
+ function replaceBackslash(s) {
313
+ return s.replace(backslashRegex, '/');
314
+ }
315
+ var alphanumericRegex = /[a-zA-Z0-9_]/;
316
+ var splatSlashRegex = /\/\$\//g;
317
+ var trailingSplatRegex = /\$$/g;
318
+ var bracketSplatRegex = /\$\{\$\}/g;
319
+ var dollarSignRegex = /\$/g;
320
+ var splitPathRegex = /[/-]/g;
321
+ var leadingDigitRegex = /^(\d)/g;
322
+ var toVariableSafeChar = (char) => {
323
+ if (alphanumericRegex.test(char)) return char;
324
+ switch (char) {
325
+ case '.':
326
+ return 'Dot';
327
+ case '-':
328
+ return 'Dash';
329
+ case '@':
330
+ return 'At';
331
+ case '(':
332
+ return '';
333
+ case ')':
334
+ return '';
335
+ case ' ':
336
+ return '';
337
+ default:
338
+ return `Char${char.charCodeAt(0)}`;
339
+ }
340
+ };
341
+ function routePathToVariable(routePath) {
342
+ const cleaned = removeUnderscores(routePath);
343
+ if (!cleaned) return '';
344
+ const parts = cleaned
345
+ .replace(splatSlashRegex, '/splat/')
346
+ .replace(trailingSplatRegex, 'splat')
347
+ .replace(bracketSplatRegex, 'splat')
348
+ .replace(dollarSignRegex, '')
349
+ .split(splitPathRegex);
350
+ let result = '';
351
+ for (let i = 0; i < parts.length; i++) {
352
+ const part = parts[i];
353
+ const segment = i > 0 ? capitalize(part) : part;
354
+ for (let j = 0; j < segment.length; j++) result += toVariableSafeChar(segment[j]);
355
+ }
356
+ return result.replace(leadingDigitRegex, 'R$1');
357
+ }
358
+ var underscoreStartEndRegex = /(^_|_$)/gi;
359
+ var underscoreSlashRegex = /(\/_|_\/)/gi;
360
+ function removeUnderscores(s) {
361
+ return s?.replace(underscoreStartEndRegex, '').replace(underscoreSlashRegex, '/');
362
+ }
363
+ function removeUnderscoresFromSegment(segment, metadata) {
364
+ let result = segment;
365
+ if (result.startsWith('_') && !metadata?.literalLeadingUnderscore) result = result.slice(1);
366
+ if (result.endsWith('_') && !metadata?.literalTrailingUnderscore) result = result.slice(0, -1);
367
+ return result;
368
+ }
369
+ function removeLayoutSegmentsAndUnderscoresWithEscape(
370
+ routePath = '/',
371
+ originalPath,
372
+ routePathSegmentMetadata,
373
+ ) {
374
+ if (!originalPath) return removeUnderscores(removeLayoutSegments(routePath)) ?? '';
375
+ const metadata =
376
+ routePathSegmentMetadata ?? createRoutePathSegmentMetadata(routePath, originalPath);
377
+ const routeSegments = routePath.split('/');
378
+ const originalSegments = originalPath.split('/');
379
+ const newSegments = [];
380
+ for (let i = 0; i < routeSegments.length; i++) {
381
+ const segment = routeSegments[i];
382
+ const originalSegment = originalSegments[i] || '';
383
+ const segmentMetadata = metadata?.[i];
384
+ if (!segmentMetadata?.literalLeadingUnderscore && isSegmentPathless(segment, originalSegment))
385
+ continue;
386
+ newSegments.push(removeUnderscoresFromSegment(segment, segmentMetadata));
387
+ }
388
+ return newSegments.join('/');
389
+ }
390
+ /**
391
+ * Checks if a segment should be treated as a pathless/layout segment.
392
+ * A segment is pathless if it starts with underscore and the underscore is not escaped.
393
+ *
394
+ * @param segment - The segment from routePath (brackets removed)
395
+ * @param originalSegment - The segment from originalRoutePath (may contain brackets)
396
+ * @returns true if the segment is pathless (has non-escaped leading underscore)
397
+ */
398
+ function isSegmentPathless(segment, originalSegment) {
399
+ if (!segment.startsWith('_')) return false;
400
+ return !hasEscapedLeadingUnderscore(originalSegment);
401
+ }
402
+ function escapeRegExp(s) {
403
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
404
+ }
405
+ function sanitizeTokenFlags(flags) {
406
+ if (!flags) return flags;
407
+ return flags.replace(/[gy]/g, '');
408
+ }
409
+ function createTokenRegex(token, opts) {
410
+ if (token === void 0 || token === null)
411
+ throw new Error(
412
+ `createTokenRegex: token is ${token}. This usually means the config was not properly parsed with defaults.`,
413
+ );
414
+ try {
415
+ if (typeof token === 'string')
416
+ return opts.type === 'segment'
417
+ ? new RegExp(`^${escapeRegExp(token)}$`)
418
+ : new RegExp(`[./]${escapeRegExp(token)}[.]`);
419
+ if (token instanceof RegExp) {
420
+ const flags = sanitizeTokenFlags(token.flags);
421
+ return opts.type === 'segment'
422
+ ? new RegExp(`^(?:${token.source})$`, flags)
423
+ : new RegExp(`[./](?:${token.source})[.]`, flags);
424
+ }
425
+ if (typeof token === 'object' && 'regex' in token) {
426
+ const flags = sanitizeTokenFlags(token.flags);
427
+ return opts.type === 'segment'
428
+ ? new RegExp(`^(?:${token.regex})$`, flags)
429
+ : new RegExp(`[./](?:${token.regex})[.]`, flags);
430
+ }
431
+ throw new Error(
432
+ `createTokenRegex: invalid token type. Expected string, RegExp, or { regex, flags } object, got: ${typeof token}`,
433
+ );
434
+ } catch (e) {
435
+ if (e instanceof SyntaxError) {
436
+ const pattern =
437
+ typeof token === 'string' ? token : token instanceof RegExp ? token.source : token.regex;
438
+ throw new Error(`Invalid regex pattern in token config: "${pattern}". ${e.message}`);
439
+ }
440
+ throw e;
441
+ }
442
+ }
443
+ function isBracketWrappedSegment(segment) {
444
+ return segment.startsWith('[') && segment.endsWith(']');
445
+ }
446
+ function unwrapBracketWrappedSegment(segment) {
447
+ return isBracketWrappedSegment(segment) ? segment.slice(1, -1) : segment;
448
+ }
449
+ function capitalize(s) {
450
+ if (typeof s !== 'string') return '';
451
+ return s.charAt(0).toUpperCase() + s.slice(1);
452
+ }
453
+ function removeExt(d, addExtensions = false) {
454
+ if (typeof addExtensions === 'string') {
455
+ const dotIndex = d.lastIndexOf('.');
456
+ if (dotIndex === -1) return d;
457
+ return d.substring(0, dotIndex) + addExtensions;
458
+ }
459
+ return addExtensions ? d : d.substring(0, d.lastIndexOf('.')) || d;
460
+ }
461
+ /**
462
+ * This function writes to a file if the content is different.
463
+ *
464
+ * @param filepath The path to the file
465
+ * @param content Original content
466
+ * @param incomingContent New content
467
+ * @param callbacks Callbacks to run before and after writing
468
+ * @returns Whether the file was written
469
+ */
470
+ async function writeIfDifferent(filepath, content, incomingContent, callbacks) {
471
+ if (content !== incomingContent) {
472
+ callbacks?.beforeWrite?.();
473
+ await fsp.writeFile(filepath, incomingContent);
474
+ callbacks?.afterWrite?.();
475
+ return true;
476
+ }
477
+ return false;
478
+ }
479
+ /**
480
+ * This function formats the source code using the default formatter (Prettier).
481
+ *
482
+ * @param source The content to format
483
+ * @param config The configuration object
484
+ * @returns The formatted content
485
+ */
486
+ async function format(source, config) {
487
+ const prettierOptions = {
488
+ semi: config.semicolons,
489
+ singleQuote: config.quoteStyle === 'single',
490
+ parser: 'typescript',
491
+ };
492
+ return prettier.format(source, prettierOptions);
493
+ }
494
+ /**
495
+ * This function resets the regex index to 0 so that it can be reused
496
+ * without having to create a new regex object or worry about the last
497
+ * state when using the global flag.
498
+ *
499
+ * @param regex The regex object to reset
500
+ * @returns
501
+ */
502
+ function resetRegex(regex) {
503
+ regex.lastIndex = 0;
504
+ }
505
+ /**
506
+ * This function checks if a file exists.
507
+ *
508
+ * @param file The path to the file
509
+ * @returns Whether the file exists
510
+ */
511
+ async function checkFileExists(file) {
512
+ try {
513
+ await fsp.access(file, fsp.constants.F_OK);
514
+ return true;
515
+ } catch {
516
+ return false;
517
+ }
518
+ }
519
+ var possiblyNestedRouteGroupPatternRegex = /\([^/]+\)\/?/g;
520
+ function removeGroups(s) {
521
+ return s.replace(possiblyNestedRouteGroupPatternRegex, '');
522
+ }
523
+ /**
524
+ * Removes all segments from a given path that start with an underscore ('_').
525
+ *
526
+ * @param {string} routePath - The path from which to remove segments. Defaults to '/'.
527
+ * @returns {string} The path with all underscore-prefixed segments removed.
528
+ * @example
529
+ * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'
530
+ */
531
+ function removeLayoutSegments(routePath = '/') {
532
+ return routePath
533
+ .split('/')
534
+ .filter((segment) => !segment.startsWith('_'))
535
+ .join('/');
536
+ }
537
+ /**
538
+ * The `node.path` is used as the `id` in the route definition.
539
+ * This function checks if the given node has a parent and if so, it determines the correct path for the given node.
540
+ * @param node - The node to determine the path for.
541
+ * @returns The correct path for the given node.
542
+ */
543
+ function determineNodePath(node) {
544
+ return (node.path = node.parent
545
+ ? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'
546
+ : node.routePath);
547
+ }
548
+ /**
549
+ * Removes the last segment from a given path. Segments are considered to be separated by a '/'.
550
+ *
551
+ * @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.
552
+ * @returns {string} The path with the last segment removed.
553
+ * @example
554
+ * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'
555
+ */
556
+ function removeLastSegmentFromPath(routePath = '/') {
557
+ const segments = routePath.split('/');
558
+ segments.pop();
559
+ return segments.join('/');
560
+ }
561
+ /**
562
+ * Find parent route using RoutePrefixMap for O(k) lookups instead of O(n).
563
+ */
564
+ function hasParentRoute(prefixMap, node, routePathToCheck) {
565
+ if (!routePathToCheck || routePathToCheck === '/') return null;
566
+ return prefixMap.findParent(routePathToCheck);
567
+ }
568
+ /**
569
+ * Gets the final variable name for a route
570
+ */
571
+ var getResolvedRouteNodeVariableName = (routeNode) => {
572
+ return routeNode.children?.length
573
+ ? `${routeNode.variableName}RouteWithChildren`
574
+ : `${routeNode.variableName}Route`;
575
+ };
576
+ /**
577
+ * Infers the path for use by TS
578
+ */
579
+ var inferPath = (routeNode) => {
580
+ if (routeNode.cleanedPath === '/') return routeNode.cleanedPath ?? '';
581
+ return routeNode.cleanedPath?.replace(/\/$/, '') ?? '';
582
+ };
583
+ /**
584
+ * Infers the full path for use by TS
585
+ */
586
+ var inferFullPath = (routeNode) => {
587
+ const fullPath = removeGroups(
588
+ removeLayoutSegmentsAndUnderscoresWithEscape(
589
+ routeNode.routePath,
590
+ routeNode.originalRoutePath,
591
+ routeNode._routePathSegmentMetadata,
592
+ ),
593
+ );
594
+ if (fullPath === '') return '/';
595
+ if (routeNode.routePath?.endsWith('/')) return fullPath;
596
+ return fullPath.replace(/\/$/, '');
597
+ };
598
+ var shouldPreferIndexRoute = (current, existing) => {
599
+ return existing.cleanedPath === '/' && current.cleanedPath !== '/';
600
+ };
601
+ var isIndexRouteNode = (routeNode) => {
602
+ return routeNode.routePath?.endsWith('/') ?? false;
603
+ };
604
+ var isPathlessRouteNode = (routeNode) => {
605
+ return routeNode._fsRouteType === 'pathless_layout';
606
+ };
607
+ var shouldReplaceRouteNodeForTo = (current, existing) => {
608
+ const currentIsIndex = isIndexRouteNode(current);
609
+ if (currentIsIndex !== isIndexRouteNode(existing)) return currentIsIndex;
610
+ const currentIsPathless = isPathlessRouteNode(current);
611
+ if (currentIsPathless !== isPathlessRouteNode(existing)) return !currentIsPathless;
612
+ return true;
613
+ };
614
+ var shouldReplaceRouteNodeForFullPath = (current, existing) => {
615
+ const currentIsPathless = isPathlessRouteNode(current);
616
+ if (currentIsPathless !== isPathlessRouteNode(existing)) return !currentIsPathless;
617
+ return true;
618
+ };
619
+ /**
620
+ * Creates a map from fullPath to routeNode
621
+ */
622
+ var createRouteNodesByFullPath = (routeNodes) => {
623
+ const map = /* @__PURE__ */ new Map();
624
+ for (const routeNode of routeNodes) {
625
+ const fullPath = inferFullPath(routeNode);
626
+ if (fullPath === '/' && map.has('/')) {
627
+ if (shouldPreferIndexRoute(routeNode, map.get('/'))) continue;
628
+ }
629
+ const existing = map.get(fullPath);
630
+ if (existing && !shouldReplaceRouteNodeForFullPath(routeNode, existing)) continue;
631
+ map.set(fullPath, routeNode);
632
+ }
633
+ return map;
634
+ };
635
+ /**
636
+ * Create a map from 'to' to a routeNode
637
+ */
638
+ var createRouteNodesByTo = (routeNodes) => {
639
+ const map = /* @__PURE__ */ new Map();
640
+ for (const routeNode of dedupeBranchesAndIndexRoutes(routeNodes)) {
641
+ const to = inferTo(routeNode);
642
+ const existing = map.get(to);
643
+ if (existing && !shouldReplaceRouteNodeForTo(routeNode, existing)) continue;
644
+ map.set(to, routeNode);
645
+ }
646
+ return map;
647
+ };
648
+ /**
649
+ * Create a map from 'id' to a routeNode
650
+ */
651
+ var createRouteNodesById = (routeNodes) => {
652
+ return new Map(
653
+ routeNodes.map((routeNode) => {
654
+ return [routeNode.routePath ?? '', routeNode];
655
+ }),
656
+ );
657
+ };
658
+ /**
659
+ * Infers to path
660
+ */
661
+ var inferTo = (routeNode) => {
662
+ const fullPath = inferFullPath(routeNode);
663
+ if (fullPath === '/') return fullPath;
664
+ return fullPath.replace(/\/$/, '');
665
+ };
666
+ /**
667
+ * Dedupes branches and index routes
668
+ */
669
+ var dedupeBranchesAndIndexRoutes = (routes) => {
670
+ return routes.filter((route) => {
671
+ if (route.children?.find((child) => child.cleanedPath === '/')) return false;
672
+ return true;
673
+ });
674
+ };
675
+ function checkUnique(routes, key) {
676
+ const keys = routes.map((d) => d[key]);
677
+ const uniqueKeys = new Set(keys);
678
+ if (keys.length !== uniqueKeys.size) {
679
+ const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i);
680
+ return routes.filter((d) => duplicateKeys.includes(d[key]));
681
+ }
682
+ }
683
+ function checkRouteFullPathUniqueness(_routes, config) {
684
+ const emptyPathRoutes = _routes.filter((d) => d.routePath === '');
685
+ if (emptyPathRoutes.length) {
686
+ const errorMessage = `Invalid route path "" was found. Root routes must be defined via __root.tsx (createRootRoute), not createFileRoute('') or a route file that resolves to an empty path.
687
+ Conflicting files: \n ${emptyPathRoutes.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\n ')}\n`;
688
+ throw new Error(errorMessage);
689
+ }
690
+ const conflictingFiles = checkUnique(
691
+ _routes.map((d) => {
692
+ const inferredFullPath = inferFullPath(d);
693
+ return {
694
+ ...d,
695
+ inferredFullPath,
696
+ };
697
+ }),
698
+ 'inferredFullPath',
699
+ );
700
+ if (conflictingFiles !== void 0) {
701
+ const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? 's' : ''}: ${conflictingFiles.map((p) => `"${p.inferredFullPath}"`).join(', ')}.
702
+ Please ensure each Route has a unique full path.
703
+ Conflicting files: \n ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\n ')}\n`;
704
+ throw new Error(errorMessage);
705
+ }
706
+ }
707
+ function buildRouteTreeConfig(nodes, disableTypes, depth = 1) {
708
+ return nodes
709
+ .map((node) => {
710
+ if (node._fsRouteType === '__root') return;
711
+ if (node._fsRouteType === 'pathless_layout' && !node.children?.length) return;
712
+ const route = `${node.variableName}`;
713
+ if (node.children?.length) {
714
+ const childConfigs = buildRouteTreeConfig(node.children, disableTypes, depth + 1);
715
+ const childrenDeclaration = disableTypes
716
+ ? ''
717
+ : `interface ${route}RouteChildren {
718
+ ${node.children.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}
719
+ }`;
720
+ const children = `const ${route}RouteChildren${disableTypes ? '' : `: ${route}RouteChildren`} = {
721
+ ${node.children.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}
722
+ }`;
723
+ const routeWithChildren = `const ${route}RouteWithChildren = ${route}Route._addFileChildren(${route}RouteChildren)`;
724
+ return [childConfigs.join('\n'), childrenDeclaration, children, routeWithChildren].join(
725
+ '\n\n',
726
+ );
727
+ }
728
+ })
729
+ .filter((x) => x !== void 0);
730
+ }
731
+ function buildImportString(importDeclaration) {
732
+ const { source, specifiers, importKind } = importDeclaration;
733
+ return specifiers.length
734
+ ? `import ${importKind === 'type' ? 'type ' : ''}{ ${specifiers.map((s) => (s.local ? `${s.imported} as ${s.local}` : s.imported)).join(', ')} } from '${source}'`
735
+ : '';
736
+ }
737
+ function mergeImportDeclarations(imports) {
738
+ const merged = /* @__PURE__ */ new Map();
739
+ for (const imp of imports) {
740
+ const key = `${imp.source}-${imp.importKind ?? ''}`;
741
+ let existing = merged.get(key);
742
+ if (!existing) {
743
+ existing = {
744
+ ...imp,
745
+ specifiers: [],
746
+ };
747
+ merged.set(key, existing);
748
+ }
749
+ const existingSpecs = existing.specifiers;
750
+ for (const specifier of imp.specifiers) {
751
+ let found = false;
752
+ for (let i = 0; i < existingSpecs.length; i++) {
753
+ const e = existingSpecs[i];
754
+ if (e.imported === specifier.imported && e.local === specifier.local) {
755
+ found = true;
756
+ break;
757
+ }
758
+ }
759
+ if (!found) existingSpecs.push(specifier);
760
+ }
761
+ }
762
+ return [...merged.values()];
763
+ }
764
+ var findParent = (node) => {
765
+ if (!node) return `rootRouteImport`;
766
+ if (node.parent) return `${node.parent.variableName}Route`;
767
+ return findParent(node.parent);
768
+ };
769
+ function buildFileRoutesByPathInterface(opts) {
770
+ return `declare module '${opts.module}' {
771
+ interface ${opts.interfaceName} {
772
+ ${opts.routeNodes
773
+ .map((routeNode) => {
774
+ const filePathId = routeNode.routePath;
775
+ const preloaderRoute = `typeof ${routeNode.variableName}RouteImport`;
776
+ const parent = findParent(routeNode);
777
+ return `'${filePathId}': {
778
+ id: '${filePathId}'
779
+ path: '${inferPath(routeNode)}'
780
+ fullPath: '${inferFullPath(routeNode)}'
781
+ preLoaderRoute: ${preloaderRoute}
782
+ parentRoute: typeof ${parent}
783
+ }`;
784
+ })
785
+ .join('\n')}
786
+ }
787
+ }`;
788
+ }
789
+ function getImportPath(node, config, generatedRouteTreePath) {
790
+ return replaceBackslash(
791
+ removeExt(
792
+ path.relative(
793
+ path.dirname(generatedRouteTreePath),
794
+ path.resolve(config.routesDirectory, node.filePath),
795
+ ),
796
+ config.addExtensions,
797
+ ),
798
+ );
799
+ }
800
+ function getImportForRouteNode(node, config, generatedRouteTreePath, root) {
801
+ let source = '';
802
+ if (config.importRoutesUsingAbsolutePaths)
803
+ source = replaceBackslash(
804
+ removeExt(path.resolve(root, config.routesDirectory, node.filePath), config.addExtensions),
805
+ );
806
+ else source = `./${getImportPath(node, config, generatedRouteTreePath)}`;
807
+ return {
808
+ source,
809
+ specifiers: [
810
+ {
811
+ imported: 'Route',
812
+ local: `${node.variableName}RouteImport`,
813
+ },
814
+ ],
815
+ };
816
+ }
817
+ //#endregion
818
+ export {
819
+ RoutePrefixMap,
820
+ buildFileRoutesByPathInterface,
821
+ buildImportString,
822
+ buildRouteTreeConfig,
823
+ capitalize,
824
+ checkFileExists,
825
+ checkRouteFullPathUniqueness,
826
+ cleanPath,
827
+ countRoutePathSegments,
828
+ countSlashSeparatedParts,
829
+ createLiteralRoutePathSegmentMetadata,
830
+ createRouteNodesByFullPath,
831
+ createRouteNodesById,
832
+ createRouteNodesByTo,
833
+ createRoutePathSegmentMetadata,
834
+ createTokenRegex,
835
+ determineInitialRoutePath,
836
+ determineInitialRoutePathFromExplicitPath,
837
+ determineNodePath,
838
+ escapeRegExp,
839
+ findParent,
840
+ format,
841
+ getImportForRouteNode,
842
+ getResolvedRouteNodeVariableName,
843
+ hasEscapedLeadingUnderscore,
844
+ hasParentRoute,
845
+ inferFullPath,
846
+ isSegmentPathless,
847
+ joinRoutePathSegmentMetadata,
848
+ mergeImportDeclarations,
849
+ multiSortBy,
850
+ removeExt,
851
+ removeGroups,
852
+ removeLastSegmentFromPath,
853
+ removeLayoutSegmentsAndUnderscoresWithEscape,
854
+ removeLeadingSlash,
855
+ removeTrailingSlash,
856
+ removeUnderscores,
857
+ replaceBackslash,
858
+ resetRegex,
859
+ routePathToVariable,
860
+ sortRouteNodes,
861
+ trimPathLeft,
862
+ unwrapBracketWrappedSegment,
863
+ writeIfDifferent,
864
+ };