@rangojs/router 0.0.0-experimental.b9cb8739 → 0.0.0-experimental.bdaf10aa

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 (449) hide show
  1. package/AGENTS.md +8 -4
  2. package/README.md +303 -741
  3. package/dist/bin/rango.js +730 -184
  4. package/dist/testing/vitest.js +82 -0
  5. package/dist/vite/index.js +4344 -1335
  6. package/dist/vite/index.js.bak +5448 -0
  7. package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  8. package/package.json +86 -15
  9. package/skills/api-client/SKILL.md +211 -0
  10. package/skills/breadcrumbs/SKILL.md +85 -6
  11. package/skills/bundle-analysis/SKILL.md +159 -0
  12. package/skills/cache-guide/SKILL.md +251 -24
  13. package/skills/caching/SKILL.md +375 -17
  14. package/skills/catalog.json +271 -0
  15. package/skills/comparison/SKILL.md +50 -0
  16. package/skills/comparison/agents/openai.yaml +4 -0
  17. package/skills/comparison/references/framework-comparison.md +837 -0
  18. package/skills/composability/SKILL.md +110 -4
  19. package/skills/css/SKILL.md +76 -0
  20. package/skills/debug-manifest/SKILL.md +5 -3
  21. package/skills/defer-hydration/SKILL.md +235 -0
  22. package/skills/document-cache/SKILL.md +87 -56
  23. package/skills/fonts/SKILL.md +1 -1
  24. package/skills/handler-use/SKILL.md +364 -0
  25. package/skills/hooks/SKILL.md +73 -691
  26. package/skills/hooks/data.md +273 -0
  27. package/skills/hooks/handle-and-actions.md +103 -0
  28. package/skills/hooks/navigation.md +110 -0
  29. package/skills/hooks/outlets.md +41 -0
  30. package/skills/hooks/state.md +228 -0
  31. package/skills/hooks/urls.md +135 -0
  32. package/skills/host-router/SKILL.md +129 -27
  33. package/skills/i18n/SKILL.md +276 -0
  34. package/skills/intercept/SKILL.md +94 -18
  35. package/skills/layout/SKILL.md +62 -19
  36. package/skills/links/SKILL.md +249 -17
  37. package/skills/loader/SKILL.md +302 -54
  38. package/skills/middleware/SKILL.md +59 -16
  39. package/skills/migrate-nextjs/SKILL.md +745 -0
  40. package/skills/migrate-react-router/SKILL.md +153 -0
  41. package/skills/migrate-react-router/cloudflare-workers.md +129 -0
  42. package/skills/migrate-react-router/component-migration.md +196 -0
  43. package/skills/migrate-react-router/data-and-actions.md +225 -0
  44. package/skills/migrate-react-router/route-mapping.md +271 -0
  45. package/skills/mime-routes/SKILL.md +29 -2
  46. package/skills/observability/SKILL.md +202 -0
  47. package/skills/parallel/SKILL.md +225 -10
  48. package/skills/ppr/SKILL.md +622 -0
  49. package/skills/prerender/SKILL.md +178 -124
  50. package/skills/rango/SKILL.md +318 -24
  51. package/skills/react-compiler/SKILL.md +168 -0
  52. package/skills/response-routes/SKILL.md +138 -49
  53. package/skills/route/SKILL.md +172 -9
  54. package/skills/router-setup/SKILL.md +131 -11
  55. package/skills/scripts/SKILL.md +179 -0
  56. package/skills/server-actions/SKILL.md +776 -0
  57. package/skills/shell-manifest/SKILL.md +185 -0
  58. package/skills/streams-and-websockets/SKILL.md +283 -0
  59. package/skills/tailwind/SKILL.md +28 -4
  60. package/skills/testing/SKILL.md +130 -0
  61. package/skills/testing/bindings.md +103 -0
  62. package/skills/testing/cache-prerender.md +127 -0
  63. package/skills/testing/client-components.md +124 -0
  64. package/skills/testing/e2e-parity.md +125 -0
  65. package/skills/testing/flight.md +91 -0
  66. package/skills/testing/handles.md +131 -0
  67. package/skills/testing/loader.md +128 -0
  68. package/skills/testing/middleware.md +99 -0
  69. package/skills/testing/render-handler.md +122 -0
  70. package/skills/testing/response-routes.md +95 -0
  71. package/skills/testing/reverse-and-types.md +85 -0
  72. package/skills/testing/server-actions.md +107 -0
  73. package/skills/testing/server-tree.md +128 -0
  74. package/skills/testing/setup.md +123 -0
  75. package/skills/theme/SKILL.md +1 -1
  76. package/skills/typesafety/SKILL.md +45 -616
  77. package/skills/typesafety/env-and-bindings.md +254 -0
  78. package/skills/typesafety/generated-files-and-cli.md +335 -0
  79. package/skills/typesafety/params-and-search.md +153 -0
  80. package/skills/typesafety/route-types.md +209 -0
  81. package/skills/use-cache/SKILL.md +74 -15
  82. package/skills/vercel/SKILL.md +128 -0
  83. package/skills/view-transitions/SKILL.md +337 -0
  84. package/src/__augment-tests__/augment.ts +81 -0
  85. package/src/__augment-tests__/augmented.check.ts +116 -0
  86. package/src/__internal.ts +1 -66
  87. package/src/browser/action-coordinator.ts +53 -36
  88. package/src/browser/action-fence.ts +47 -0
  89. package/src/browser/app-shell.ts +39 -0
  90. package/src/browser/app-version.ts +14 -0
  91. package/src/browser/connection-warmup.ts +134 -0
  92. package/src/browser/cookie-name.ts +140 -0
  93. package/src/browser/event-controller.ts +257 -158
  94. package/src/browser/history-state.ts +21 -0
  95. package/src/browser/index.ts +3 -3
  96. package/src/browser/invalidate-client-cache.ts +52 -0
  97. package/src/browser/logging.ts +28 -0
  98. package/src/browser/merge-segment-loaders.ts +6 -4
  99. package/src/browser/navigation-bridge.ts +132 -33
  100. package/src/browser/navigation-client.ts +218 -68
  101. package/src/browser/navigation-store-handle.ts +38 -0
  102. package/src/browser/navigation-store.ts +203 -80
  103. package/src/browser/navigation-transaction.ts +18 -66
  104. package/src/browser/network-error-handler.ts +34 -7
  105. package/src/browser/partial-update.ts +241 -127
  106. package/src/browser/prefetch/cache.ts +271 -44
  107. package/src/browser/prefetch/fetch.ts +367 -40
  108. package/src/browser/prefetch/queue.ts +144 -23
  109. package/src/browser/prefetch/resource-ready.ts +77 -0
  110. package/src/browser/rango-state.ts +158 -76
  111. package/src/browser/react/Link.tsx +121 -16
  112. package/src/browser/react/NavigationProvider.tsx +240 -122
  113. package/src/browser/react/ScrollRestoration.tsx +10 -6
  114. package/src/browser/react/context.ts +7 -2
  115. package/src/browser/react/filter-segment-order.ts +66 -7
  116. package/src/browser/react/index.ts +0 -48
  117. package/src/browser/react/location-state-shared.ts +178 -8
  118. package/src/browser/react/location-state.ts +39 -14
  119. package/src/browser/react/use-action.ts +6 -15
  120. package/src/browser/react/use-handle.ts +23 -69
  121. package/src/browser/react/use-href.tsx +8 -1
  122. package/src/browser/react/use-link-status.ts +33 -8
  123. package/src/browser/react/use-navigation.ts +32 -7
  124. package/src/browser/react/use-params.ts +20 -10
  125. package/src/browser/react/use-reverse.ts +106 -0
  126. package/src/browser/react/use-router.ts +46 -11
  127. package/src/browser/react/use-search-params.ts +0 -5
  128. package/src/browser/react/use-segments.ts +11 -21
  129. package/src/browser/response-adapter.ts +99 -8
  130. package/src/browser/rsc-router.tsx +272 -80
  131. package/src/browser/scroll-restoration.ts +56 -22
  132. package/src/browser/segment-reconciler.ts +44 -7
  133. package/src/browser/segment-structure-assert.ts +2 -2
  134. package/src/browser/server-action-bridge.ts +244 -71
  135. package/src/browser/types.ts +136 -12
  136. package/src/browser/validate-redirect-origin.ts +43 -16
  137. package/src/build/collect-fallback-refs.ts +107 -0
  138. package/src/build/generate-manifest.ts +207 -158
  139. package/src/build/generate-route-types.ts +6 -1
  140. package/src/build/index.ts +11 -3
  141. package/src/build/prefix-tree-utils.ts +123 -0
  142. package/src/build/route-trie.ts +198 -41
  143. package/src/build/route-types/ast-route-extraction.ts +15 -8
  144. package/src/build/route-types/codegen.ts +16 -5
  145. package/src/build/route-types/include-resolution.ts +464 -63
  146. package/src/build/route-types/param-extraction.ts +6 -3
  147. package/src/build/route-types/per-module-writer.ts +22 -6
  148. package/src/build/route-types/router-processing.ts +336 -110
  149. package/src/build/route-types/scan-filter.ts +9 -2
  150. package/src/build/route-types/source-scan.ts +216 -0
  151. package/src/build/runtime-discovery.ts +13 -21
  152. package/src/cache/cache-error.ts +104 -0
  153. package/src/cache/cache-key-utils.ts +58 -13
  154. package/src/cache/cache-policy.ts +108 -34
  155. package/src/cache/cache-runtime.ts +454 -97
  156. package/src/cache/cache-scope.ts +235 -103
  157. package/src/cache/cache-tag.ts +149 -0
  158. package/src/cache/cf/cf-base64.ts +33 -0
  159. package/src/cache/cf/cf-cache-constants.ts +127 -0
  160. package/src/cache/cf/cf-cache-store.ts +2446 -170
  161. package/src/cache/cf/cf-cache-types.ts +349 -0
  162. package/src/cache/cf/cf-kv-utils.ts +46 -0
  163. package/src/cache/cf/cf-tag-marker-memo.ts +105 -0
  164. package/src/cache/cf/index.ts +11 -17
  165. package/src/cache/document-cache.ts +144 -49
  166. package/src/cache/handle-snapshot.ts +70 -0
  167. package/src/cache/index.ts +24 -20
  168. package/src/cache/memory-segment-store.ts +243 -37
  169. package/src/cache/profile-registry.ts +46 -31
  170. package/src/cache/read-through-swr.ts +56 -12
  171. package/src/cache/segment-codec.ts +13 -21
  172. package/src/cache/shell-snapshot.ts +417 -0
  173. package/src/cache/tag-invalidation.ts +230 -0
  174. package/src/cache/taint.ts +55 -0
  175. package/src/cache/types.ts +194 -99
  176. package/src/cache/vercel/index.ts +11 -0
  177. package/src/cache/vercel/vercel-cache-store.ts +1132 -0
  178. package/src/client.rsc.tsx +41 -21
  179. package/src/client.tsx +116 -290
  180. package/src/cloudflare/index.ts +11 -0
  181. package/src/cloudflare/tracing.ts +108 -0
  182. package/src/component-utils.ts +19 -0
  183. package/src/components/DefaultDocument.tsx +8 -2
  184. package/src/context-var.ts +84 -2
  185. package/src/debug.ts +2 -2
  186. package/src/decode-loader-results.ts +52 -0
  187. package/src/defer.ts +185 -0
  188. package/src/deps/ssr.ts +0 -1
  189. package/src/encode-kv.ts +49 -0
  190. package/src/errors.ts +30 -4
  191. package/src/escape-script.ts +52 -0
  192. package/src/handle.ts +104 -34
  193. package/src/handles/MetaTags.tsx +24 -53
  194. package/src/handles/Scripts.tsx +183 -0
  195. package/src/handles/breadcrumbs.ts +35 -8
  196. package/src/handles/deferred-resolution.ts +127 -0
  197. package/src/handles/is-thenable.ts +18 -0
  198. package/src/handles/meta.ts +14 -40
  199. package/src/handles/script.ts +244 -0
  200. package/src/host/cookie-handler.ts +9 -60
  201. package/src/host/errors.ts +13 -22
  202. package/src/host/index.ts +9 -2
  203. package/src/host/pattern-matcher.ts +23 -52
  204. package/src/host/router.ts +107 -99
  205. package/src/host/testing.ts +40 -27
  206. package/src/host/types.ts +37 -4
  207. package/src/host/utils.ts +1 -1
  208. package/src/href-client.ts +137 -22
  209. package/src/index.rsc.ts +100 -13
  210. package/src/index.ts +143 -19
  211. package/src/internal-debug.ts +11 -10
  212. package/src/loader-store.ts +500 -0
  213. package/src/loader.rsc.ts +20 -13
  214. package/src/loader.ts +12 -11
  215. package/src/missing-id-error.ts +68 -0
  216. package/src/outlet-context.ts +1 -1
  217. package/src/outlet-provider.tsx +1 -5
  218. package/src/prerender/param-hash.ts +16 -16
  219. package/src/prerender/store.ts +37 -41
  220. package/src/prerender.ts +215 -86
  221. package/src/redirect-origin.ts +114 -0
  222. package/src/regex-escape.ts +8 -0
  223. package/src/render-error-thrower.tsx +20 -0
  224. package/src/response-utils.ts +62 -0
  225. package/src/reverse.ts +65 -15
  226. package/src/root-error-boundary.tsx +1 -19
  227. package/src/route-content-wrapper.tsx +19 -77
  228. package/src/route-definition/dsl-helpers.ts +485 -303
  229. package/src/route-definition/helper-factories.ts +28 -140
  230. package/src/route-definition/helpers-types.ts +153 -77
  231. package/src/route-definition/index.ts +4 -2
  232. package/src/route-definition/redirect.ts +53 -12
  233. package/src/route-definition/resolve-handler-use.ts +160 -0
  234. package/src/route-definition/use-item-types.ts +29 -0
  235. package/src/route-map-builder.ts +48 -21
  236. package/src/route-types.ts +37 -46
  237. package/src/router/basename.ts +14 -0
  238. package/src/router/content-negotiation.ts +164 -17
  239. package/src/router/error-handling.ts +45 -18
  240. package/src/router/find-match.ts +130 -29
  241. package/src/router/handler-context.ts +83 -39
  242. package/src/router/instrument.ts +355 -0
  243. package/src/router/intercept-resolution.ts +50 -24
  244. package/src/router/lazy-includes.ts +89 -63
  245. package/src/router/loader-resolution.ts +286 -56
  246. package/src/router/logging.ts +5 -8
  247. package/src/router/manifest.ts +105 -56
  248. package/src/router/match-api.ts +178 -218
  249. package/src/router/match-context.ts +0 -22
  250. package/src/router/match-handlers.ts +211 -165
  251. package/src/router/match-middleware/background-revalidation.ts +66 -22
  252. package/src/router/match-middleware/cache-lookup.ts +214 -263
  253. package/src/router/match-middleware/cache-store.ts +105 -50
  254. package/src/router/match-middleware/intercept-resolution.ts +8 -28
  255. package/src/router/match-middleware/segment-resolution.ts +52 -18
  256. package/src/router/match-pipelines.ts +1 -42
  257. package/src/router/match-result.ts +128 -44
  258. package/src/router/metrics.ts +5 -34
  259. package/src/router/middleware-types.ts +13 -142
  260. package/src/router/middleware.ts +301 -177
  261. package/src/router/navigation-snapshot.ts +133 -0
  262. package/src/router/params-util.ts +23 -0
  263. package/src/router/parse-pattern.ts +115 -0
  264. package/src/router/pattern-matching.ts +181 -150
  265. package/src/router/prefetch-cache-ttl.ts +51 -0
  266. package/src/router/prefetch-limits.ts +37 -0
  267. package/src/router/prerender-match.ts +203 -58
  268. package/src/router/preview-match.ts +35 -103
  269. package/src/router/request-classification.ts +291 -0
  270. package/src/router/revalidation.ts +123 -73
  271. package/src/router/route-snapshot.ts +256 -0
  272. package/src/router/router-context.ts +11 -29
  273. package/src/router/router-interfaces.ts +146 -35
  274. package/src/router/router-options.ts +202 -15
  275. package/src/router/router-registry.ts +2 -5
  276. package/src/router/segment-resolution/fresh.ts +301 -78
  277. package/src/router/segment-resolution/helpers.ts +115 -30
  278. package/src/router/segment-resolution/loader-cache.ts +156 -39
  279. package/src/router/segment-resolution/loader-mask.ts +60 -0
  280. package/src/router/segment-resolution/loader-snapshot.ts +259 -0
  281. package/src/router/segment-resolution/mask-nested.ts +83 -0
  282. package/src/router/segment-resolution/revalidation.ts +477 -385
  283. package/src/router/segment-resolution/static-store.ts +19 -5
  284. package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
  285. package/src/router/segment-resolution/view-transition-default.ts +56 -0
  286. package/src/router/segment-resolution.ts +5 -1
  287. package/src/router/segment-wrappers.ts +8 -5
  288. package/src/router/state-cookie-name.ts +33 -0
  289. package/src/router/substitute-pattern-params.ts +75 -0
  290. package/src/router/telemetry-otel.ts +160 -200
  291. package/src/router/telemetry.ts +105 -20
  292. package/src/router/timeout.ts +0 -20
  293. package/src/router/tracing.ts +215 -0
  294. package/src/router/trie-matching.ts +171 -59
  295. package/src/router/types.ts +10 -63
  296. package/src/router/url-params.ts +57 -0
  297. package/src/router.ts +210 -71
  298. package/src/rsc/full-payload.ts +70 -0
  299. package/src/rsc/handler-context.ts +3 -2
  300. package/src/rsc/handler.ts +682 -508
  301. package/src/rsc/helpers.ts +168 -46
  302. package/src/rsc/index.ts +2 -5
  303. package/src/rsc/json-route-result.ts +38 -0
  304. package/src/rsc/loader-fetch.ts +127 -31
  305. package/src/rsc/manifest-init.ts +33 -42
  306. package/src/rsc/nonce.ts +10 -1
  307. package/src/rsc/origin-guard.ts +39 -25
  308. package/src/rsc/progressive-enhancement.ts +138 -15
  309. package/src/rsc/redirect-guard.ts +100 -0
  310. package/src/rsc/response-cache-serve.ts +238 -0
  311. package/src/rsc/response-error.ts +79 -12
  312. package/src/rsc/response-route-handler.ts +99 -189
  313. package/src/rsc/rsc-rendering.ts +509 -73
  314. package/src/rsc/runtime-warnings.ts +23 -10
  315. package/src/rsc/server-action.ts +287 -113
  316. package/src/rsc/shell-capture.ts +1190 -0
  317. package/src/rsc/shell-serve.ts +181 -0
  318. package/src/rsc/ssr-setup.ts +18 -2
  319. package/src/rsc/transition-gate.ts +89 -0
  320. package/src/rsc/types.ts +62 -6
  321. package/src/runtime-env.ts +18 -0
  322. package/src/search-params.ts +35 -30
  323. package/src/segment-content-promise.ts +67 -0
  324. package/src/segment-loader-promise.ts +167 -0
  325. package/src/segment-system.tsx +449 -132
  326. package/src/serialize.ts +243 -0
  327. package/src/server/context.ts +367 -61
  328. package/src/server/cookie-parse.ts +32 -0
  329. package/src/server/cookie-store.ts +152 -5
  330. package/src/server/handle-store.ts +40 -38
  331. package/src/server/loader-registry.ts +38 -46
  332. package/src/server/request-context.ts +558 -173
  333. package/src/ssr/index.tsx +491 -174
  334. package/src/ssr/inject-rsc-eager.ts +167 -0
  335. package/src/ssr/ssr-root.tsx +228 -0
  336. package/src/static-handler.ts +27 -18
  337. package/src/testing/cache-status.ts +162 -0
  338. package/src/testing/collect-handle.ts +46 -0
  339. package/src/testing/dispatch.ts +813 -0
  340. package/src/testing/dom.entry.ts +22 -0
  341. package/src/testing/e2e/fixture.ts +188 -0
  342. package/src/testing/e2e/index.ts +128 -0
  343. package/src/testing/e2e/matchers.ts +35 -0
  344. package/src/testing/e2e/page-helpers.ts +272 -0
  345. package/src/testing/e2e/parity.ts +387 -0
  346. package/src/testing/e2e/server.ts +195 -0
  347. package/src/testing/flight-matchers.ts +97 -0
  348. package/src/testing/flight-normalize.ts +11 -0
  349. package/src/testing/flight-runtime.d.ts +57 -0
  350. package/src/testing/flight-tree.ts +682 -0
  351. package/src/testing/flight.entry.ts +52 -0
  352. package/src/testing/flight.ts +257 -0
  353. package/src/testing/generated-routes.ts +199 -0
  354. package/src/testing/index.ts +105 -0
  355. package/src/testing/internal/context.ts +371 -0
  356. package/src/testing/internal/flight-client-globals.ts +30 -0
  357. package/src/testing/internal/seed-vars.ts +54 -0
  358. package/src/testing/render-handler.ts +357 -0
  359. package/src/testing/render-route.tsx +584 -0
  360. package/src/testing/run-loader.ts +385 -0
  361. package/src/testing/run-middleware.ts +205 -0
  362. package/src/testing/run-transition-when.ts +164 -0
  363. package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
  364. package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
  365. package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
  366. package/src/testing/vitest-stubs/version.ts +5 -0
  367. package/src/testing/vitest.ts +305 -0
  368. package/src/theme/ThemeProvider.tsx +56 -84
  369. package/src/theme/ThemeScript.tsx +7 -9
  370. package/src/theme/constants.ts +52 -13
  371. package/src/theme/index.ts +0 -7
  372. package/src/theme/theme-context.ts +1 -5
  373. package/src/theme/theme-script.ts +22 -21
  374. package/src/theme/use-theme.ts +0 -3
  375. package/src/types/boundaries.ts +0 -35
  376. package/src/types/cache-types.ts +17 -8
  377. package/src/types/error-types.ts +30 -90
  378. package/src/types/global-namespace.ts +54 -41
  379. package/src/types/handler-context.ts +234 -82
  380. package/src/types/index.ts +3 -10
  381. package/src/types/loader-types.ts +44 -15
  382. package/src/types/request-scope.ts +112 -0
  383. package/src/types/route-config.ts +20 -52
  384. package/src/types/route-entry.ts +19 -7
  385. package/src/types/segments.ts +137 -14
  386. package/src/urls/include-helper.ts +40 -75
  387. package/src/urls/include-provider.ts +71 -0
  388. package/src/urls/index.ts +2 -11
  389. package/src/urls/path-helper-types.ts +102 -23
  390. package/src/urls/path-helper.ts +62 -111
  391. package/src/urls/pattern-types.ts +84 -19
  392. package/src/urls/response-types.ts +25 -22
  393. package/src/urls/type-extraction.ts +98 -154
  394. package/src/urls/urls-function.ts +1 -19
  395. package/src/use-loader.tsx +346 -89
  396. package/src/vercel/index.ts +11 -0
  397. package/src/vercel/tracing.ts +88 -0
  398. package/src/vite/debug.ts +185 -0
  399. package/src/vite/discovery/bundle-postprocess.ts +36 -38
  400. package/src/vite/discovery/dev-prerender-cache.ts +117 -0
  401. package/src/vite/discovery/discover-routers.ts +130 -85
  402. package/src/vite/discovery/discovery-errors.ts +255 -0
  403. package/src/vite/discovery/gate-state.ts +171 -0
  404. package/src/vite/discovery/prerender-collection.ts +214 -132
  405. package/src/vite/discovery/route-types-writer.ts +40 -84
  406. package/src/vite/discovery/self-gen-tracking.ts +27 -1
  407. package/src/vite/discovery/state.ts +57 -6
  408. package/src/vite/discovery/virtual-module-codegen.ts +14 -34
  409. package/src/vite/index.ts +15 -0
  410. package/src/vite/inject-client-debug.ts +88 -0
  411. package/src/vite/plugin-types.ts +234 -62
  412. package/src/vite/plugins/cjs-to-esm.ts +16 -19
  413. package/src/vite/plugins/client-ref-dedup.ts +16 -11
  414. package/src/vite/plugins/client-ref-hashing.ts +28 -15
  415. package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
  416. package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
  417. package/src/vite/plugins/cloudflare-protocol-stub.ts +194 -0
  418. package/src/vite/plugins/expose-action-id.ts +49 -98
  419. package/src/vite/plugins/expose-id-utils.ts +96 -51
  420. package/src/vite/plugins/expose-ids/export-analysis.ts +101 -34
  421. package/src/vite/plugins/expose-ids/handler-transform.ts +15 -64
  422. package/src/vite/plugins/expose-ids/loader-transform.ts +14 -24
  423. package/src/vite/plugins/expose-ids/router-transform.ts +118 -29
  424. package/src/vite/plugins/expose-internal-ids.ts +553 -317
  425. package/src/vite/plugins/performance-tracks.ts +89 -0
  426. package/src/vite/plugins/refresh-cmd.ts +89 -27
  427. package/src/vite/plugins/use-cache-transform.ts +73 -83
  428. package/src/vite/plugins/vercel-output.ts +384 -0
  429. package/src/vite/plugins/version-injector.ts +40 -29
  430. package/src/vite/plugins/version-plugin.ts +46 -37
  431. package/src/vite/plugins/virtual-entries.ts +138 -27
  432. package/src/vite/rango.ts +353 -303
  433. package/src/vite/router-discovery.ts +1090 -166
  434. package/src/vite/utils/ast-handler-extract.ts +26 -35
  435. package/src/vite/utils/banner.ts +4 -4
  436. package/src/vite/utils/bundle-analysis.ts +10 -15
  437. package/src/vite/utils/client-chunks.ts +184 -0
  438. package/src/vite/utils/directive-prologue.ts +40 -0
  439. package/src/vite/utils/forward-user-plugins.ts +171 -0
  440. package/src/vite/utils/manifest-utils.ts +4 -59
  441. package/src/vite/utils/package-resolution.ts +20 -52
  442. package/src/vite/utils/prerender-utils.ts +98 -38
  443. package/src/vite/utils/shared-utils.ts +144 -44
  444. package/src/browser/action-response-classifier.ts +0 -99
  445. package/src/browser/react/use-client-cache.ts +0 -58
  446. package/src/browser/shallow.ts +0 -40
  447. package/src/handles/index.ts +0 -7
  448. package/src/network-error-thrower.tsx +0 -23
  449. package/src/router/middleware-cookies.ts +0 -55
package/dist/bin/rango.js CHANGED
@@ -1,8 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __esm = (fn, res) => function __init() {
5
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
+ var __esm = (fn, res, err) => function __init() {
5
+ if (err) throw err[0];
6
+ try {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ } catch (e) {
9
+ throw err = [e], e;
10
+ }
6
11
  };
7
12
  var __export = (target, all) => {
8
13
  for (var name in all)
@@ -22,10 +27,10 @@ function extractParamsFromPattern(pattern) {
22
27
  function formatRouteEntry(key, pattern, _params, search) {
23
28
  const hasSearch = search && Object.keys(search).length > 0;
24
29
  if (!hasSearch) {
25
- return ` ${key}: "${pattern}",`;
30
+ return ` ${key}: ${JSON.stringify(pattern)},`;
26
31
  }
27
- const searchBody = Object.entries(search).map(([k, v]) => `${k}: "${v}"`).join(", ");
28
- return ` ${key}: { path: "${pattern}", search: { ${searchBody} } },`;
32
+ const searchBody = Object.entries(search).map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join(", ");
33
+ return ` ${key}: { path: ${JSON.stringify(pattern)}, search: { ${searchBody} } },`;
29
34
  }
30
35
  var init_param_extraction = __esm({
31
36
  "src/build/route-types/param-extraction.ts"() {
@@ -59,8 +64,8 @@ var init_ast_helpers = __esm({
59
64
 
60
65
  // src/build/route-types/ast-route-extraction.ts
61
66
  import ts2 from "typescript";
62
- function extractRoutesFromSource(code) {
63
- const sourceFile = ts2.createSourceFile(
67
+ function extractRoutesFromSource(code, sourceFileArg) {
68
+ const sourceFile = sourceFileArg ?? ts2.createSourceFile(
64
69
  "input.tsx",
65
70
  code,
66
71
  ts2.ScriptTarget.Latest,
@@ -139,7 +144,7 @@ function generatePerModuleTypesSource(routes) {
139
144
  const valid = routes.filter(({ name }) => {
140
145
  if (!name || /["'\\`\n\r]/.test(name)) {
141
146
  console.warn(
142
- `[rsc-router] Skipping route with invalid name: ${JSON.stringify(name)}`
147
+ `[rango] Skipping route with invalid name: ${JSON.stringify(name)}`
143
148
  );
144
149
  return false;
145
150
  }
@@ -149,7 +154,7 @@ function generatePerModuleTypesSource(routes) {
149
154
  for (const { name, pattern, params, search } of valid) {
150
155
  if (deduped.has(name)) {
151
156
  console.warn(
152
- `[rsc-router] Duplicate route name "${name}" \u2014 keeping first definition`
157
+ `[rango] Duplicate route name "${name}" \u2014 keeping first definition`
153
158
  );
154
159
  continue;
155
160
  }
@@ -185,9 +190,13 @@ export const NamedRoutes = {
185
190
  ${objectBody}
186
191
  } as const;
187
192
 
193
+ // Aliased so the augmentation below does not pay a homomorphic mapped-type
194
+ // instantiation per route; \`as const\` already makes the members readonly.
195
+ type NamedRoutesShape = typeof NamedRoutes;
196
+
188
197
  declare global {
189
- namespace RSCRouter {
190
- interface GeneratedRouteMap extends Readonly<typeof NamedRoutes> {}
198
+ namespace Rango {
199
+ interface GeneratedRouteMap extends NamedRoutesShape {}
191
200
  }
192
201
  }
193
202
  `;
@@ -211,14 +220,15 @@ function findTsFiles(dir, filter) {
211
220
  entries = readdirSync(dir, { withFileTypes: true });
212
221
  } catch (err) {
213
222
  console.warn(
214
- `[rsc-router] Failed to scan directory ${dir}: ${err.message}`
223
+ `[rango] Failed to scan directory ${dir}: ${err.message}`
215
224
  );
216
225
  return results;
217
226
  }
218
227
  for (const entry of entries) {
219
228
  const fullPath = join(dir, entry.name);
220
229
  if (entry.isDirectory()) {
221
- if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
230
+ if (entry.name === "node_modules" || entry.name.startsWith(".") || entry.name === "dist" || entry.name === "build" || entry.name === "coverage")
231
+ continue;
222
232
  results.push(...findTsFiles(fullPath, filter));
223
233
  } else if ((entry.name.endsWith(".ts") || entry.name.endsWith(".tsx") || entry.name.endsWith(".js") || entry.name.endsWith(".jsx")) && !entry.name.includes(".gen.")) {
224
234
  if (filter && !filter(fullPath)) continue;
@@ -237,6 +247,33 @@ var init_scan_filter = __esm({
237
247
  import { readFileSync, existsSync } from "node:fs";
238
248
  import { dirname, resolve } from "node:path";
239
249
  import ts3 from "typescript";
250
+ function createScanMemo() {
251
+ return { files: /* @__PURE__ */ new Map(), blockSourceFiles: /* @__PURE__ */ new Map() };
252
+ }
253
+ function parseBlock(memo, block) {
254
+ if (memo) {
255
+ const cached = memo.blockSourceFiles.get(block);
256
+ if (cached) return cached;
257
+ }
258
+ const sf = ts3.createSourceFile(
259
+ "input.tsx",
260
+ block,
261
+ ts3.ScriptTarget.Latest,
262
+ true,
263
+ ts3.ScriptKind.TSX
264
+ );
265
+ if (memo) memo.blockSourceFiles.set(block, sf);
266
+ return sf;
267
+ }
268
+ function readSourceMemoized(memo, realPath) {
269
+ if (memo) {
270
+ const cached = memo.files.get(realPath);
271
+ if (cached !== void 0) return cached;
272
+ }
273
+ const source = readFileSync(realPath, "utf-8");
274
+ if (memo) memo.files.set(realPath, source);
275
+ return source;
276
+ }
240
277
  function extractNamePrefixFromInclude(node) {
241
278
  if (node.arguments.length >= 3) {
242
279
  const thirdArg = node.arguments[2];
@@ -252,8 +289,98 @@ function extractNamePrefixFromInclude(node) {
252
289
  }
253
290
  return null;
254
291
  }
255
- function extractIncludesWithDiagnostics(code) {
256
- const sourceFile = ts3.createSourceFile(
292
+ function thenSelectsNonDefaultMember(expr) {
293
+ const findThenCall = (e) => {
294
+ if (ts3.isCallExpression(e) && ts3.isPropertyAccessExpression(e.expression) && e.expression.name.text === "then") {
295
+ return e;
296
+ }
297
+ if (ts3.isCallExpression(e) && ts3.isPropertyAccessExpression(e.expression)) {
298
+ return findThenCall(e.expression.expression);
299
+ }
300
+ if (ts3.isPropertyAccessExpression(e)) return findThenCall(e.expression);
301
+ if (ts3.isParenthesizedExpression(e)) return findThenCall(e.expression);
302
+ if (ts3.isAwaitExpression(e)) return findThenCall(e.expression);
303
+ return null;
304
+ };
305
+ const thenCall = findThenCall(expr);
306
+ if (!thenCall || thenCall.arguments.length === 0) return false;
307
+ const cb = thenCall.arguments[0];
308
+ if (!ts3.isArrowFunction(cb) && !ts3.isFunctionExpression(cb)) return false;
309
+ let ret;
310
+ if (ts3.isBlock(cb.body)) {
311
+ for (const stmt of cb.body.statements) {
312
+ if (ts3.isReturnStatement(stmt) && stmt.expression) {
313
+ ret = stmt.expression;
314
+ break;
315
+ }
316
+ }
317
+ } else {
318
+ ret = cb.body;
319
+ }
320
+ if (!ret) return false;
321
+ if (ts3.isPropertyAccessExpression(ret)) {
322
+ return ret.name.text !== "default";
323
+ }
324
+ return false;
325
+ }
326
+ function extractDynamicImportSpecifier(node) {
327
+ let body;
328
+ if (ts3.isArrowFunction(node) || ts3.isFunctionExpression(node)) {
329
+ body = node.body;
330
+ }
331
+ if (!body) return null;
332
+ let expr;
333
+ if (ts3.isBlock(body)) {
334
+ for (const stmt of body.statements) {
335
+ if (ts3.isReturnStatement(stmt) && stmt.expression) {
336
+ expr = stmt.expression;
337
+ break;
338
+ }
339
+ }
340
+ } else {
341
+ expr = body;
342
+ }
343
+ if (!expr) return null;
344
+ const findImportCall = (e) => {
345
+ if (ts3.isCallExpression(e) && e.expression.kind === ts3.SyntaxKind.ImportKeyword) {
346
+ return e;
347
+ }
348
+ if (ts3.isCallExpression(e) && ts3.isPropertyAccessExpression(e.expression)) {
349
+ return findImportCall(e.expression.expression);
350
+ }
351
+ if (ts3.isPropertyAccessExpression(e)) return findImportCall(e.expression);
352
+ if (ts3.isParenthesizedExpression(e)) return findImportCall(e.expression);
353
+ if (ts3.isAwaitExpression(e)) return findImportCall(e.expression);
354
+ return null;
355
+ };
356
+ const importCall = findImportCall(expr);
357
+ if (!importCall || importCall.arguments.length === 0) return null;
358
+ if (thenSelectsNonDefaultMember(expr)) return null;
359
+ return getStringValue(importCall.arguments[0]);
360
+ }
361
+ function resolveDefaultExportTarget(code, sourceFile) {
362
+ let result = null;
363
+ function visit(node) {
364
+ if (result) return;
365
+ if (ts3.isExportAssignment(node) && !node.isExportEquals) {
366
+ const expr = node.expression;
367
+ if (ts3.isIdentifier(expr)) {
368
+ result = { variableName: expr.text };
369
+ } else if (ts3.isCallExpression(expr)) {
370
+ const callee = expr.expression;
371
+ if (ts3.isIdentifier(callee) && callee.text === "urls") {
372
+ result = { inlineBlock: expr.getText(sourceFile) };
373
+ }
374
+ }
375
+ return;
376
+ }
377
+ ts3.forEachChild(node, visit);
378
+ }
379
+ visit(sourceFile);
380
+ return result;
381
+ }
382
+ function extractIncludesWithDiagnostics(code, sourceFileArg) {
383
+ const sourceFile = sourceFileArg ?? ts3.createSourceFile(
257
384
  "input.tsx",
258
385
  code,
259
386
  ts3.ScriptTarget.Latest,
@@ -277,12 +404,19 @@ function extractIncludesWithDiagnostics(code) {
277
404
  }
278
405
  const secondArg = node.arguments[1];
279
406
  const namePrefix = extractNamePrefixFromInclude(node);
407
+ const dynamicImportSpec = extractDynamicImportSpecifier(secondArg);
280
408
  if (ts3.isIdentifier(secondArg)) {
281
409
  resolved.push({
282
410
  pathPrefix,
283
411
  variableName: secondArg.text,
284
412
  namePrefix
285
413
  });
414
+ } else if (dynamicImportSpec !== null) {
415
+ resolved.push({
416
+ pathPrefix,
417
+ moduleSpecifier: dynamicImportSpec,
418
+ namePrefix
419
+ });
286
420
  } else if (ts3.isCallExpression(secondArg)) {
287
421
  const callText = secondArg.expression.getText(sourceFile);
288
422
  unresolvable.push({
@@ -307,7 +441,7 @@ function extractIncludesWithDiagnostics(code) {
307
441
  return { resolved, unresolvable };
308
442
  }
309
443
  function resolveImportedVariable(code, localName) {
310
- const importRegex = /import\s*\{([^}]+)\}\s*from\s*["']([^"']+)["']/g;
444
+ const importRegex = /import\s*(?:[\w$]+\s*,\s*)?\{([^}]+)\}\s*from\s*["']([^"']+)["']/g;
311
445
  let match;
312
446
  while ((match = importRegex.exec(code)) !== null) {
313
447
  const imports = match[1];
@@ -344,8 +478,8 @@ function resolveImportPath(importSpec, fromFile) {
344
478
  }
345
479
  return null;
346
480
  }
347
- function extractUrlsBlockForVariable(code, varName) {
348
- const sourceFile = ts3.createSourceFile(
481
+ function extractUrlsBlockForVariable(code, varName, sourceFileArg) {
482
+ const sourceFile = sourceFileArg ?? ts3.createSourceFile(
349
483
  "input.tsx",
350
484
  code,
351
485
  ts3.ScriptTarget.Latest,
@@ -367,67 +501,113 @@ function extractUrlsBlockForVariable(code, varName) {
367
501
  visit(sourceFile);
368
502
  return result;
369
503
  }
370
- function buildRouteMapFromBlock(block, fullSource, filePath, visited, searchSchemasOut, diagnosticsOut) {
504
+ function buildRouteMapFromBlock(block, fullSource, filePath, visited, searchSchemasOut, diagnosticsOut, memo) {
371
505
  const routeMap = {};
372
- const localRoutes = extractRoutesFromSource(block);
506
+ const blockSourceFile = parseBlock(memo, block);
507
+ const localRoutes = extractRoutesFromSource(block, blockSourceFile);
373
508
  for (const { name, pattern, search } of localRoutes) {
374
509
  routeMap[name] = pattern;
375
510
  if (search && searchSchemasOut) {
376
511
  searchSchemasOut[name] = search;
377
512
  }
378
513
  }
379
- const { resolved: includes, unresolvable } = extractIncludesWithDiagnostics(block);
514
+ const { resolved: includes, unresolvable } = extractIncludesWithDiagnostics(
515
+ block,
516
+ blockSourceFile
517
+ );
380
518
  if (diagnosticsOut) {
381
519
  for (const entry of unresolvable) {
382
520
  diagnosticsOut.push({ ...entry, sourceFile: filePath });
383
521
  }
384
522
  }
385
- for (const { pathPrefix, variableName, namePrefix } of includes) {
523
+ for (const inc of includes) {
524
+ const { pathPrefix, namePrefix } = inc;
386
525
  let childResult;
387
- const imported = resolveImportedVariable(fullSource, variableName);
388
- if (imported) {
389
- const targetFile = resolveImportPath(imported.specifier, filePath);
526
+ if (inc.moduleSpecifier) {
527
+ const targetFile = resolveImportPath(inc.moduleSpecifier, filePath);
390
528
  if (!targetFile) {
391
- if (diagnosticsOut) {
392
- diagnosticsOut.push({
393
- pathPrefix,
394
- namePrefix,
395
- reason: "file-not-found",
396
- sourceFile: filePath,
397
- detail: `import "${imported.specifier}" resolved to no file`
398
- });
399
- }
529
+ diagnosticsOut?.push({
530
+ pathPrefix,
531
+ namePrefix,
532
+ reason: "file-not-found",
533
+ sourceFile: filePath,
534
+ detail: `import("${inc.moduleSpecifier}") resolved to no file`
535
+ });
400
536
  continue;
401
537
  }
402
- childResult = buildCombinedRouteMapWithSearch(
403
- targetFile,
404
- imported.exportedName,
405
- visited,
406
- diagnosticsOut
407
- );
408
- } else {
409
- const sameFileBlock = extractUrlsBlockForVariable(
410
- fullSource,
411
- variableName
538
+ let targetSource;
539
+ try {
540
+ targetSource = readSourceMemoized(memo, resolve(targetFile));
541
+ } catch (err) {
542
+ diagnosticsOut?.push({
543
+ pathPrefix,
544
+ namePrefix,
545
+ reason: "file-not-found",
546
+ sourceFile: filePath,
547
+ detail: `import("${inc.moduleSpecifier}") resolved to "${targetFile}" but reading it failed: ${err?.message ?? String(err)}`
548
+ });
549
+ continue;
550
+ }
551
+ const def = resolveDefaultExportTarget(
552
+ targetSource,
553
+ parseBlock(memo, targetSource)
412
554
  );
413
- if (!sameFileBlock) {
414
- if (diagnosticsOut) {
415
- diagnosticsOut.push({
416
- pathPrefix,
417
- namePrefix,
418
- reason: "unresolvable-import",
419
- sourceFile: filePath,
420
- detail: `variable "${variableName}" not found in imports or same-file scope`
421
- });
422
- }
555
+ if (!def) {
556
+ diagnosticsOut?.push({
557
+ pathPrefix,
558
+ namePrefix,
559
+ reason: "unresolvable-import",
560
+ sourceFile: filePath,
561
+ detail: `import("${inc.moduleSpecifier}") has no resolvable \`export default urls(...)\``
562
+ });
423
563
  continue;
424
564
  }
425
- childResult = buildCombinedRouteMapWithSearch(
426
- filePath,
565
+ if (def.inlineBlock) {
566
+ childResult = buildCombinedRouteMapWithSearch(
567
+ targetFile,
568
+ void 0,
569
+ visited,
570
+ diagnosticsOut,
571
+ def.inlineBlock,
572
+ memo
573
+ );
574
+ } else {
575
+ const variableName = def.variableName;
576
+ const resolved = resolveIncludedVariable({
577
+ variableName,
578
+ resolutionFile: targetFile,
579
+ resolutionSource: targetSource,
580
+ reportFile: filePath,
581
+ memo,
582
+ visited,
583
+ diagnosticsOut,
584
+ pathPrefix,
585
+ namePrefix,
586
+ fileNotFoundDetail: (specifier) => `import("${inc.moduleSpecifier}") default re-exports "${variableName}" from "${specifier}", which resolved to no file`,
587
+ notFoundDetail: () => `import("${inc.moduleSpecifier}") default "${variableName}" not found in its imports or same-file scope`
588
+ });
589
+ if (!resolved) continue;
590
+ childResult = resolved;
591
+ }
592
+ } else if (inc.variableName) {
593
+ const variableName = inc.variableName;
594
+ const resolved = resolveIncludedVariable({
427
595
  variableName,
596
+ resolutionFile: filePath,
597
+ resolutionSource: fullSource,
598
+ reportFile: filePath,
599
+ memo,
428
600
  visited,
429
- diagnosticsOut
430
- );
601
+ diagnosticsOut,
602
+ pathPrefix,
603
+ namePrefix,
604
+ fileNotFoundDetail: (specifier) => `import "${specifier}" resolved to no file`,
605
+ notFoundDetail: () => `variable "${variableName}" not found in imports or same-file scope`
606
+ });
607
+ if (!resolved) continue;
608
+ childResult = resolved;
609
+ } else {
610
+ continue;
431
611
  }
432
612
  if (namePrefix === null) {
433
613
  continue;
@@ -450,24 +630,89 @@ function buildRouteMapFromBlock(block, fullSource, filePath, visited, searchSche
450
630
  }
451
631
  return routeMap;
452
632
  }
453
- function buildCombinedRouteMapWithSearch(filePath, variableName, visited, diagnosticsOut) {
633
+ function resolveIncludedVariable(opts) {
634
+ const {
635
+ variableName,
636
+ resolutionFile,
637
+ resolutionSource,
638
+ reportFile,
639
+ memo,
640
+ visited,
641
+ diagnosticsOut,
642
+ pathPrefix,
643
+ namePrefix
644
+ } = opts;
645
+ const imported = resolveImportedVariable(resolutionSource, variableName);
646
+ if (imported) {
647
+ const targetFile = resolveImportPath(imported.specifier, resolutionFile);
648
+ if (!targetFile) {
649
+ diagnosticsOut?.push({
650
+ pathPrefix,
651
+ namePrefix,
652
+ reason: "file-not-found",
653
+ sourceFile: reportFile,
654
+ detail: opts.fileNotFoundDetail(imported.specifier)
655
+ });
656
+ return null;
657
+ }
658
+ return buildCombinedRouteMapWithSearch(
659
+ targetFile,
660
+ imported.exportedName,
661
+ visited,
662
+ diagnosticsOut,
663
+ void 0,
664
+ memo
665
+ );
666
+ }
667
+ const sameFileBlock = extractUrlsBlockForVariable(
668
+ resolutionSource,
669
+ variableName,
670
+ parseBlock(memo, resolutionSource)
671
+ );
672
+ if (!sameFileBlock) {
673
+ diagnosticsOut?.push({
674
+ pathPrefix,
675
+ namePrefix,
676
+ reason: "unresolvable-import",
677
+ sourceFile: reportFile,
678
+ detail: opts.notFoundDetail()
679
+ });
680
+ return null;
681
+ }
682
+ return buildCombinedRouteMapWithSearch(
683
+ resolutionFile,
684
+ variableName,
685
+ visited,
686
+ diagnosticsOut,
687
+ void 0,
688
+ memo
689
+ );
690
+ }
691
+ function buildCombinedRouteMapWithSearch(filePath, variableName, visited, diagnosticsOut, inlineBlock, memo) {
454
692
  visited = visited ?? /* @__PURE__ */ new Set();
693
+ memo = memo ?? createScanMemo();
455
694
  const realPath = resolve(filePath);
456
695
  const key = variableName ? `${realPath}:${variableName}` : realPath;
457
696
  if (visited.has(key)) {
458
- console.warn(`[rsc-router] Circular include detected, skipping: ${key}`);
697
+ console.warn(`[rango] Circular include detected, skipping: ${key}`);
459
698
  return { routes: {}, searchSchemas: {} };
460
699
  }
461
700
  visited.add(key);
462
701
  let source;
463
702
  try {
464
- source = readFileSync(realPath, "utf-8");
703
+ source = readSourceMemoized(memo, realPath);
465
704
  } catch {
466
705
  return { routes: {}, searchSchemas: {} };
467
706
  }
468
707
  let block;
469
- if (variableName) {
470
- const extracted = extractUrlsBlockForVariable(source, variableName);
708
+ if (inlineBlock) {
709
+ block = inlineBlock;
710
+ } else if (variableName) {
711
+ const extracted = extractUrlsBlockForVariable(
712
+ source,
713
+ variableName,
714
+ parseBlock(memo, source)
715
+ );
471
716
  if (!extracted) return { routes: {}, searchSchemas: {} };
472
717
  block = extracted;
473
718
  } else {
@@ -480,7 +725,8 @@ function buildCombinedRouteMapWithSearch(filePath, variableName, visited, diagno
480
725
  realPath,
481
726
  visited,
482
727
  searchSchemas,
483
- diagnosticsOut
728
+ diagnosticsOut,
729
+ memo
484
730
  );
485
731
  visited.delete(key);
486
732
  return { routes, searchSchemas };
@@ -525,8 +771,16 @@ function writePerModuleRouteTypesForFile(filePath) {
525
771
  let routes;
526
772
  if (varNames.length > 0) {
527
773
  routes = [];
774
+ const memo = createScanMemo();
528
775
  for (const varName of varNames) {
529
- const { routes: routeMap, searchSchemas } = buildCombinedRouteMapWithSearch(filePath, varName);
776
+ const { routes: routeMap, searchSchemas } = buildCombinedRouteMapWithSearch(
777
+ filePath,
778
+ varName,
779
+ void 0,
780
+ void 0,
781
+ void 0,
782
+ memo
783
+ );
530
784
  for (const [name, pattern] of Object.entries(routeMap)) {
531
785
  const params = extractParamsFromPattern(pattern);
532
786
  routes.push({
@@ -540,12 +794,12 @@ function writePerModuleRouteTypesForFile(filePath) {
540
794
  } else {
541
795
  routes = extractRoutesFromSource(source);
542
796
  }
543
- const genPath = filePath.replace(/\.(tsx?)$/, ".gen.ts");
797
+ const genPath = filePath.replace(/\.(tsx?|jsx?)$/, ".gen.ts");
544
798
  if (routes.length === 0) {
545
799
  if (varNames.length > 0 && !existsSync2(genPath)) {
546
800
  writeFileSync(genPath, generatePerModuleTypesSource([]));
547
801
  console.log(
548
- `[rsc-router] Generated route types (placeholder) -> ${genPath}`
802
+ `[rango] Generated route types (placeholder) -> ${genPath}`
549
803
  );
550
804
  }
551
805
  return;
@@ -554,11 +808,11 @@ function writePerModuleRouteTypesForFile(filePath) {
554
808
  const existing = existsSync2(genPath) ? readFileSync2(genPath, "utf-8") : null;
555
809
  if (existing !== genSource) {
556
810
  writeFileSync(genPath, genSource);
557
- console.log(`[rsc-router] Generated route types -> ${genPath}`);
811
+ console.log(`[rango] Generated route types -> ${genPath}`);
558
812
  }
559
813
  } catch (err) {
560
814
  console.warn(
561
- `[rsc-router] Failed to generate route types for ${filePath}: ${err.message}`
815
+ `[rango] Failed to generate route types for ${filePath}: ${err.message}`
562
816
  );
563
817
  }
564
818
  }
@@ -573,6 +827,131 @@ var init_per_module_writer = __esm({
573
827
  }
574
828
  });
575
829
 
830
+ // src/build/route-types/source-scan.ts
831
+ function isLineTerminator(ch) {
832
+ const c = ch.charCodeAt(0);
833
+ return c === 10 || c === 13 || c === 8232 || c === 8233;
834
+ }
835
+ function isRegexPositionAt(code, slashPos, prevChar) {
836
+ if (prevChar === void 0) return true;
837
+ if (prevChar === ")" || prevChar === "]" || prevChar === "}") return false;
838
+ if (!/[\w$]/.test(prevChar)) return true;
839
+ let k = slashPos - 1;
840
+ while (k >= 0 && /\s/.test(code[k])) k--;
841
+ const wordEnd = k + 1;
842
+ while (k >= 0 && /[\w$]/.test(code[k])) k--;
843
+ return REGEX_PRECEDING_KEYWORDS.has(code.slice(k + 1, wordEnd));
844
+ }
845
+ function makeCodeClassifier(code) {
846
+ const n = code.length;
847
+ let i = 0;
848
+ let skipStart = -1;
849
+ let skipEnd = -1;
850
+ let lastSig;
851
+ return (q) => {
852
+ if (q >= skipStart && q < skipEnd) return false;
853
+ while (i < n && i <= q) {
854
+ const c = code[i];
855
+ const d = i + 1 < n ? code[i + 1] : "";
856
+ let end = -1;
857
+ let transparent = false;
858
+ if (c === "/" && d === "/") {
859
+ let j = i + 2;
860
+ while (j < n && !isLineTerminator(code[j])) j++;
861
+ end = j;
862
+ transparent = true;
863
+ } else if (c === "/" && d === "*") {
864
+ let j = i + 2;
865
+ while (j < n && !(code[j] === "*" && code[j + 1] === "/")) j++;
866
+ end = Math.min(n, j + 2);
867
+ transparent = true;
868
+ } else if (c === '"' || c === "'" || c === "`") {
869
+ let j = i + 1;
870
+ while (j < n) {
871
+ if (code[j] === "\\") {
872
+ j += 2;
873
+ continue;
874
+ }
875
+ if (code[j] === c) {
876
+ j++;
877
+ break;
878
+ }
879
+ j++;
880
+ }
881
+ end = j;
882
+ } else if (c === "/" && d !== "/" && d !== "*" && isRegexPositionAt(code, i, lastSig)) {
883
+ let j = i + 1;
884
+ let inClass = false;
885
+ let closed = false;
886
+ while (j < n && !isLineTerminator(code[j])) {
887
+ const r = code[j];
888
+ if (r === "\\") {
889
+ j += 2;
890
+ continue;
891
+ }
892
+ if (r === "[") inClass = true;
893
+ else if (r === "]") inClass = false;
894
+ else if (r === "/" && !inClass) {
895
+ j++;
896
+ closed = true;
897
+ break;
898
+ }
899
+ j++;
900
+ }
901
+ if (closed) {
902
+ while (j < n && /[a-z]/.test(code[j])) j++;
903
+ end = j;
904
+ }
905
+ }
906
+ if (end >= 0) {
907
+ if (q < end) {
908
+ skipStart = i;
909
+ skipEnd = end;
910
+ return false;
911
+ }
912
+ i = end;
913
+ if (!transparent) lastSig = "x";
914
+ } else {
915
+ if (!/\s/.test(c)) lastSig = c;
916
+ i++;
917
+ }
918
+ }
919
+ return true;
920
+ };
921
+ }
922
+ function firstCodeMatchIndex(code, pattern) {
923
+ const inCode = makeCodeClassifier(code);
924
+ pattern.lastIndex = 0;
925
+ let m;
926
+ while ((m = pattern.exec(code)) !== null) {
927
+ if (inCode(m.index)) return m.index;
928
+ if (pattern.lastIndex <= m.index) pattern.lastIndex = m.index + 1;
929
+ }
930
+ return -1;
931
+ }
932
+ var REGEX_PRECEDING_KEYWORDS;
933
+ var init_source_scan = __esm({
934
+ "src/build/route-types/source-scan.ts"() {
935
+ "use strict";
936
+ REGEX_PRECEDING_KEYWORDS = /* @__PURE__ */ new Set([
937
+ "return",
938
+ "typeof",
939
+ "instanceof",
940
+ "in",
941
+ "of",
942
+ "new",
943
+ "delete",
944
+ "void",
945
+ "do",
946
+ "else",
947
+ "yield",
948
+ "await",
949
+ "case",
950
+ "throw"
951
+ ]);
952
+ }
953
+ });
954
+
576
955
  // src/build/route-types/router-processing.ts
577
956
  import {
578
957
  readFileSync as readFileSync3,
@@ -601,44 +980,52 @@ function countPublicRouteEntries(source) {
601
980
  return count;
602
981
  }
603
982
  function isRoutableSourceFile(name) {
604
- return (name.endsWith(".ts") || name.endsWith(".tsx") || name.endsWith(".js") || name.endsWith(".jsx")) && !name.includes(".gen.");
983
+ return (name.endsWith(".ts") || name.endsWith(".tsx") || name.endsWith(".js") || name.endsWith(".jsx")) && !name.includes(".gen.") && !name.includes(".test.") && !name.includes(".spec.");
984
+ }
985
+ function isExcludedScanDir(name) {
986
+ return name === "node_modules" || name === "dist" || name === "coverage" || name === "__tests__" || name === "__mocks__" || name.startsWith(".");
605
987
  }
606
- function findRouterFilesRecursive(dir, filter, results) {
988
+ function findCallSiteFilesRecursive(dir, pattern, patternG, stopAtMatchDir, filter, results) {
607
989
  let entries;
608
990
  try {
609
991
  entries = readdirSync2(dir, { withFileTypes: true });
610
992
  } catch (err) {
611
993
  console.warn(
612
- `[rsc-router] Failed to scan directory ${dir}: ${err.message}`
994
+ `[rango] Failed to scan directory ${dir}: ${err.message}`
613
995
  );
614
996
  return;
615
997
  }
616
998
  const childDirs = [];
617
- const routerFilesInDir = [];
999
+ const matchesInDir = [];
618
1000
  for (const entry of entries) {
619
1001
  const fullPath = join2(dir, entry.name);
620
1002
  if (entry.isDirectory()) {
621
- if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
622
- childDirs.push(fullPath);
1003
+ if (!isExcludedScanDir(entry.name)) childDirs.push(fullPath);
623
1004
  continue;
624
1005
  }
625
1006
  if (!isRoutableSourceFile(entry.name)) continue;
626
1007
  if (filter && !filter(fullPath)) continue;
627
1008
  try {
628
1009
  const source = readFileSync3(fullPath, "utf-8");
629
- if (ROUTER_CALL_PATTERN.test(source)) {
630
- routerFilesInDir.push(fullPath);
1010
+ if (pattern.test(source) && firstCodeMatchIndex(source, patternG) >= 0) {
1011
+ matchesInDir.push(fullPath);
631
1012
  }
632
1013
  } catch {
633
1014
  continue;
634
1015
  }
635
1016
  }
636
- if (routerFilesInDir.length > 0) {
637
- results.push(...routerFilesInDir);
638
- return;
639
- }
640
- for (const childDir of childDirs) {
641
- findRouterFilesRecursive(childDir, filter, results);
1017
+ results.push(...matchesInDir);
1018
+ if (!stopAtMatchDir || matchesInDir.length === 0) {
1019
+ for (const childDir of childDirs) {
1020
+ findCallSiteFilesRecursive(
1021
+ childDir,
1022
+ pattern,
1023
+ patternG,
1024
+ stopAtMatchDir,
1025
+ filter,
1026
+ results
1027
+ );
1028
+ }
642
1029
  }
643
1030
  }
644
1031
  function findNestedRouterConflict(routerFiles) {
@@ -664,13 +1051,13 @@ function findNestedRouterConflict(routerFiles) {
664
1051
  }
665
1052
  return null;
666
1053
  }
667
- function formatNestedRouterConflictError(conflict, prefix = "[rsc-router]") {
1054
+ function formatNestedRouterConflictError(conflict, prefix = "[rango]") {
668
1055
  return `${prefix} Nested router roots are not supported.
669
1056
  Router root: ${conflict.ancestor}
670
1057
  Nested router: ${conflict.nested}
671
1058
  Move the nested router into a sibling directory or configure it as a separate app root.`;
672
1059
  }
673
- function extractUrlsVariableFromRouter(code) {
1060
+ function extractUrlsFromRouter(code) {
674
1061
  const sourceFile = ts5.createSourceFile(
675
1062
  "router.tsx",
676
1063
  code,
@@ -684,24 +1071,70 @@ function extractUrlsVariableFromRouter(code) {
684
1071
  const callee = node.expression;
685
1072
  return ts5.isIdentifier(callee) && callee.text === "createRouter";
686
1073
  }
1074
+ function isInlineBuilder(node) {
1075
+ return ts5.isArrowFunction(node) || ts5.isFunctionExpression(node);
1076
+ }
1077
+ function isRoutesOnCreateRouter(node) {
1078
+ if (!ts5.isPropertyAccessExpression(node.expression) || node.expression.name.text !== "routes")
1079
+ return false;
1080
+ let inner = node.expression.expression;
1081
+ while (ts5.isCallExpression(inner) && ts5.isPropertyAccessExpression(inner.expression)) {
1082
+ inner = inner.expression.expression;
1083
+ }
1084
+ return isCreateRouterCall(inner);
1085
+ }
687
1086
  function visit(node) {
688
1087
  if (result) return;
689
- if (ts5.isCallExpression(node) && ts5.isPropertyAccessExpression(node.expression) && node.expression.name.text === "routes" && node.arguments.length >= 1 && ts5.isIdentifier(node.arguments[0])) {
690
- let inner = node.expression.expression;
691
- while (ts5.isCallExpression(inner) && ts5.isPropertyAccessExpression(inner.expression)) {
692
- inner = inner.expression.expression;
693
- }
694
- if (isCreateRouterCall(inner)) {
695
- result = node.arguments[0].text;
696
- return;
1088
+ if (ts5.isCallExpression(node) && node.arguments.length >= 1 && isRoutesOnCreateRouter(node)) {
1089
+ const arg = node.arguments[0];
1090
+ if (ts5.isIdentifier(arg)) {
1091
+ result = { kind: "variable", name: arg.text };
1092
+ } else if (isInlineBuilder(arg)) {
1093
+ result = { kind: "inline", block: arg.getText(sourceFile) };
697
1094
  }
1095
+ return;
698
1096
  }
699
1097
  if (isCreateRouterCall(node)) {
700
1098
  const callExpr = node;
701
- for (const arg of callExpr.arguments) {
1099
+ for (const callArg of callExpr.arguments) {
1100
+ if (ts5.isObjectLiteralExpression(callArg)) {
1101
+ for (const prop of callArg.properties) {
1102
+ if (ts5.isPropertyAssignment(prop) && ts5.isIdentifier(prop.name) && prop.name.text === "urls") {
1103
+ if (ts5.isIdentifier(prop.initializer)) {
1104
+ result = { kind: "variable", name: prop.initializer.text };
1105
+ } else if (isInlineBuilder(prop.initializer)) {
1106
+ result = {
1107
+ kind: "inline",
1108
+ block: prop.initializer.getText(sourceFile)
1109
+ };
1110
+ }
1111
+ return;
1112
+ }
1113
+ }
1114
+ }
1115
+ }
1116
+ }
1117
+ ts5.forEachChild(node, visit);
1118
+ }
1119
+ visit(sourceFile);
1120
+ return result;
1121
+ }
1122
+ function extractBasenameFromRouter(code) {
1123
+ const sourceFile = ts5.createSourceFile(
1124
+ "router.tsx",
1125
+ code,
1126
+ ts5.ScriptTarget.Latest,
1127
+ true,
1128
+ ts5.ScriptKind.TSX
1129
+ );
1130
+ let result;
1131
+ function visit(node) {
1132
+ if (result !== void 0) return;
1133
+ if (ts5.isCallExpression(node) && ts5.isIdentifier(node.expression) && node.expression.text === "createRouter") {
1134
+ for (const arg of node.arguments) {
702
1135
  if (ts5.isObjectLiteralExpression(arg)) {
703
1136
  for (const prop of arg.properties) {
704
- if (ts5.isPropertyAssignment(prop) && ts5.isIdentifier(prop.name) && prop.name.text === "urls" && ts5.isIdentifier(prop.initializer)) {
1137
+ if (ts5.isPropertyAssignment(prop) && ts5.isIdentifier(prop.name) && prop.name.text === "basename" && ts5.isStringLiteral(prop.initializer)) {
705
1138
  result = prop.initializer.text;
706
1139
  return;
707
1140
  }
@@ -714,6 +1147,38 @@ function extractUrlsVariableFromRouter(code) {
714
1147
  visit(sourceFile);
715
1148
  return result;
716
1149
  }
1150
+ function applyBasenameToRoutes(result, basename) {
1151
+ const prefixed = {};
1152
+ for (const [name, pattern] of Object.entries(result.routes)) {
1153
+ if (pattern === "/") {
1154
+ prefixed[name] = basename;
1155
+ } else if (basename.endsWith("/") && pattern.startsWith("/")) {
1156
+ prefixed[name] = basename + pattern.slice(1);
1157
+ } else {
1158
+ prefixed[name] = basename + pattern;
1159
+ }
1160
+ }
1161
+ return { routes: prefixed, searchSchemas: result.searchSchemas };
1162
+ }
1163
+ function genFileTsPath(sourceFile) {
1164
+ const base = pathBasename(sourceFile).replace(/\.(tsx?|jsx?)$/, "");
1165
+ return join2(dirname2(sourceFile), `${base}.named-routes.gen.ts`);
1166
+ }
1167
+ function resolveSearchSchemas(publicRouteNames, runtimeSchemas, sourceFile) {
1168
+ if (runtimeSchemas && Object.keys(runtimeSchemas).length > 0) {
1169
+ return runtimeSchemas;
1170
+ }
1171
+ const staticParsed = buildCombinedRouteMapForRouterFile(sourceFile);
1172
+ if (Object.keys(staticParsed.searchSchemas).length === 0) {
1173
+ return runtimeSchemas;
1174
+ }
1175
+ const filtered = {};
1176
+ for (const name of publicRouteNames) {
1177
+ const schema = staticParsed.searchSchemas[name];
1178
+ if (schema) filtered[name] = schema;
1179
+ }
1180
+ return Object.keys(filtered).length > 0 ? filtered : runtimeSchemas;
1181
+ }
717
1182
  function buildCombinedRouteMapForRouterFile(routerFilePath) {
718
1183
  let routerSource;
719
1184
  try {
@@ -721,19 +1186,40 @@ function buildCombinedRouteMapForRouterFile(routerFilePath) {
721
1186
  } catch {
722
1187
  return { routes: {}, searchSchemas: {} };
723
1188
  }
724
- const urlsVarName = extractUrlsVariableFromRouter(routerSource);
725
- if (!urlsVarName) {
1189
+ const extraction = extractUrlsFromRouter(routerSource);
1190
+ if (!extraction) {
726
1191
  return { routes: {}, searchSchemas: {} };
727
1192
  }
728
- const imported = resolveImportedVariable(routerSource, urlsVarName);
729
- if (imported) {
730
- const targetFile = resolveImportPath(imported.specifier, routerFilePath);
731
- if (!targetFile) {
732
- return { routes: {}, searchSchemas: {} };
1193
+ const rawBasename = extractBasenameFromRouter(routerSource);
1194
+ const basename = rawBasename ? ("/" + rawBasename.replace(/^\/+|\/+$/g, "")).replace(/^\/$/, "") : void 0;
1195
+ let result;
1196
+ if (extraction.kind === "inline") {
1197
+ result = buildCombinedRouteMapWithSearch(
1198
+ routerFilePath,
1199
+ void 0,
1200
+ void 0,
1201
+ void 0,
1202
+ extraction.block
1203
+ );
1204
+ } else {
1205
+ const imported = resolveImportedVariable(routerSource, extraction.name);
1206
+ if (imported) {
1207
+ const targetFile = resolveImportPath(imported.specifier, routerFilePath);
1208
+ if (!targetFile) {
1209
+ return { routes: {}, searchSchemas: {} };
1210
+ }
1211
+ result = buildCombinedRouteMapWithSearch(
1212
+ targetFile,
1213
+ imported.exportedName
1214
+ );
1215
+ } else {
1216
+ result = buildCombinedRouteMapWithSearch(routerFilePath, extraction.name);
733
1217
  }
734
- return buildCombinedRouteMapWithSearch(targetFile, imported.exportedName);
735
1218
  }
736
- return buildCombinedRouteMapWithSearch(routerFilePath, urlsVarName);
1219
+ if (basename) {
1220
+ result = applyBasenameToRoutes(result, basename);
1221
+ }
1222
+ return result;
737
1223
  }
738
1224
  function detectUnresolvableIncludes(routerFilePath) {
739
1225
  const realPath = resolve2(routerFilePath);
@@ -743,9 +1229,20 @@ function detectUnresolvableIncludes(routerFilePath) {
743
1229
  } catch {
744
1230
  return [];
745
1231
  }
746
- const urlsVarName = extractUrlsVariableFromRouter(source);
747
- if (!urlsVarName) return [];
748
- const imported = resolveImportedVariable(source, urlsVarName);
1232
+ const extraction = extractUrlsFromRouter(source);
1233
+ if (!extraction) return [];
1234
+ const diagnostics = [];
1235
+ if (extraction.kind === "inline") {
1236
+ buildCombinedRouteMapWithSearch(
1237
+ realPath,
1238
+ void 0,
1239
+ /* @__PURE__ */ new Set(),
1240
+ diagnostics,
1241
+ extraction.block
1242
+ );
1243
+ return diagnostics;
1244
+ }
1245
+ const imported = resolveImportedVariable(source, extraction.name);
749
1246
  let targetFile;
750
1247
  let exportedName;
751
1248
  if (imported) {
@@ -765,9 +1262,8 @@ function detectUnresolvableIncludes(routerFilePath) {
765
1262
  exportedName = imported.exportedName;
766
1263
  } else {
767
1264
  targetFile = realPath;
768
- exportedName = urlsVarName;
1265
+ exportedName = extraction.name;
769
1266
  }
770
- const diagnostics = [];
771
1267
  buildCombinedRouteMapWithSearch(
772
1268
  targetFile,
773
1269
  exportedName,
@@ -794,7 +1290,14 @@ function detectUnresolvableIncludesForUrlsFile(filePath) {
794
1290
  }
795
1291
  function findRouterFiles(root, filter) {
796
1292
  const result = [];
797
- findRouterFilesRecursive(root, filter, result);
1293
+ findCallSiteFilesRecursive(
1294
+ root,
1295
+ ROUTER_CALL_PATTERN,
1296
+ ROUTER_CALL_PATTERN_G,
1297
+ true,
1298
+ filter,
1299
+ result
1300
+ );
798
1301
  return result;
799
1302
  }
800
1303
  function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
@@ -803,7 +1306,7 @@ function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
803
1306
  if (existsSync3(oldCombinedPath)) {
804
1307
  unlinkSync(oldCombinedPath);
805
1308
  console.log(
806
- `[rsc-router] Removed stale combined route types: ${oldCombinedPath}`
1309
+ `[rango] Removed stale combined route types: ${oldCombinedPath}`
807
1310
  );
808
1311
  }
809
1312
  } catch {
@@ -815,38 +1318,22 @@ function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
815
1318
  throw new Error(formatNestedRouterConflictError(nestedRouterConflict));
816
1319
  }
817
1320
  for (const routerFilePath of routerFilePaths) {
818
- let routerSource;
819
- try {
820
- routerSource = readFileSync3(routerFilePath, "utf-8");
821
- } catch {
822
- continue;
823
- }
824
- const urlsVarName = extractUrlsVariableFromRouter(routerSource);
825
- if (!urlsVarName) continue;
826
- let result;
827
- const imported = resolveImportedVariable(routerSource, urlsVarName);
828
- if (imported) {
829
- const targetFile = resolveImportPath(imported.specifier, routerFilePath);
830
- if (!targetFile) continue;
831
- result = buildCombinedRouteMapWithSearch(
832
- targetFile,
833
- imported.exportedName
834
- );
835
- } else {
836
- result = buildCombinedRouteMapWithSearch(routerFilePath, urlsVarName);
1321
+ const result = buildCombinedRouteMapForRouterFile(routerFilePath);
1322
+ if (Object.keys(result.routes).length === 0 && Object.keys(result.searchSchemas).length === 0) {
1323
+ let routerSource;
1324
+ try {
1325
+ routerSource = readFileSync3(routerFilePath, "utf-8");
1326
+ } catch {
1327
+ continue;
1328
+ }
1329
+ if (!extractUrlsFromRouter(routerSource)) continue;
837
1330
  }
838
- const routerBasename = pathBasename(routerFilePath).replace(
839
- /\.(tsx?|jsx?)$/,
840
- ""
841
- );
842
- const outPath = join2(
843
- dirname2(routerFilePath),
844
- `${routerBasename}.named-routes.gen.ts`
845
- );
1331
+ const outPath = genFileTsPath(routerFilePath);
846
1332
  const existing = existsSync3(outPath) ? readFileSync3(outPath, "utf-8") : null;
847
1333
  if (Object.keys(result.routes).length === 0) {
848
1334
  if (!existing) {
849
1335
  const emptySource = generateRouteTypesSource({});
1336
+ opts?.onWrite?.(outPath, emptySource);
850
1337
  writeFileSync2(outPath, emptySource);
851
1338
  }
852
1339
  continue;
@@ -866,22 +1353,25 @@ function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
866
1353
  continue;
867
1354
  }
868
1355
  }
1356
+ opts?.onWrite?.(outPath, source);
869
1357
  writeFileSync2(outPath, source);
870
1358
  console.log(
871
- `[rsc-router] Generated route types (${Object.keys(result.routes).length} routes) -> ${outPath}`
1359
+ `[rango] Generated route types (${Object.keys(result.routes).length} routes) -> ${outPath}`
872
1360
  );
873
1361
  }
874
1362
  }
875
1363
  }
876
- var ROUTER_CALL_PATTERN;
1364
+ var ROUTER_CALL_PATTERN, ROUTER_CALL_PATTERN_G;
877
1365
  var init_router_processing = __esm({
878
1366
  "src/build/route-types/router-processing.ts"() {
879
1367
  "use strict";
880
1368
  init_codegen();
1369
+ init_source_scan();
881
1370
  init_include_resolution();
882
1371
  init_per_module_writer();
883
1372
  init_route_name();
884
1373
  ROUTER_CALL_PATTERN = /\bcreateRouter\s*[<(]/;
1374
+ ROUTER_CALL_PATTERN_G = /\bcreateRouter\s*[<(]/g;
885
1375
  }
886
1376
  });
887
1377
 
@@ -919,7 +1409,7 @@ import {
919
1409
  import { createElement, StrictMode } from "react";
920
1410
  import { hydrateRoot } from "react-dom/client";
921
1411
  import { rscStream } from "@rangojs/router/internal/deps/html-stream-client";
922
- import { initBrowserApp, RSCRouter } from "@rangojs/router/browser";
1412
+ import { initBrowserApp, Rango } from "@rangojs/router/browser";
923
1413
 
924
1414
  async function initializeApp() {
925
1415
  const deps = {
@@ -930,11 +1420,16 @@ async function initializeApp() {
930
1420
  createTemporaryReferenceSet,
931
1421
  };
932
1422
 
933
- await initBrowserApp({ rscStream, deps });
1423
+ // initBrowserApp resolves the initial payload and returns the browser app
1424
+ // context, including strictMode (default true) from createRouter. StrictMode
1425
+ // is the default; createRouter({ strictMode: false }) ships the opt-out in the
1426
+ // payload metadata. StrictMode emits no DOM, so toggling never changes markup.
1427
+ const { strictMode } = await initBrowserApp({ rscStream, deps });
934
1428
 
1429
+ const app = createElement(Rango);
935
1430
  hydrateRoot(
936
1431
  document,
937
- createElement(StrictMode, null, createElement(RSCRouter))
1432
+ strictMode === false ? app : createElement(StrictMode, null, app)
938
1433
  );
939
1434
  }
940
1435
 
@@ -942,9 +1437,14 @@ initializeApp().catch(console.error);
942
1437
  `.trim();
943
1438
  VIRTUAL_ENTRY_SSR = `
944
1439
  import { createFromReadableStream } from "@rangojs/router/internal/deps/ssr";
945
- import { renderToReadableStream } from "react-dom/server.edge";
1440
+ import { renderToReadableStream, resume } from "react-dom/server.edge";
1441
+ import { prerender } from "react-dom/static.edge";
946
1442
  import { injectRSCPayload } from "@rangojs/router/internal/deps/html-stream-server";
947
- import { createSSRHandler } from "@rangojs/router/ssr";
1443
+ import {
1444
+ createSSRHandler,
1445
+ createShellCaptureHandler,
1446
+ createShellResumeHandler,
1447
+ } from "@rangojs/router/ssr";
948
1448
 
949
1449
  export const renderHTML = createSSRHandler({
950
1450
  createFromReadableStream,
@@ -953,6 +1453,26 @@ export const renderHTML = createSSRHandler({
953
1453
  loadBootstrapScriptContent: () =>
954
1454
  import.meta.viteRsc.loadBootstrapScriptContent("index"),
955
1455
  });
1456
+
1457
+ export const captureShellHTML = createShellCaptureHandler({
1458
+ createFromReadableStream,
1459
+ renderToReadableStream,
1460
+ injectRSCPayload,
1461
+ prerender,
1462
+ resume,
1463
+ loadBootstrapScriptContent: () =>
1464
+ import.meta.viteRsc.loadBootstrapScriptContent("index"),
1465
+ });
1466
+
1467
+ export const resumeShellHTML = createShellResumeHandler({
1468
+ createFromReadableStream,
1469
+ renderToReadableStream,
1470
+ injectRSCPayload,
1471
+ prerender,
1472
+ resume,
1473
+ loadBootstrapScriptContent: () =>
1474
+ import.meta.viteRsc.loadBootstrapScriptContent("index"),
1475
+ });
956
1476
  `.trim();
957
1477
  VIRTUAL_IDS = {
958
1478
  browser: "virtual:rsc-router/entry.browser.js",
@@ -963,12 +1483,37 @@ export const renderHTML = createSSRHandler({
963
1483
  }
964
1484
  });
965
1485
 
1486
+ // src/vite/utils/directive-prologue.ts
1487
+ import { parseAst } from "vite";
1488
+ function hasUseClientDirective(source) {
1489
+ let program;
1490
+ try {
1491
+ program = parseAst(source, { lang: "tsx" });
1492
+ } catch {
1493
+ return false;
1494
+ }
1495
+ for (const node of program.body ?? []) {
1496
+ if (node?.type === "ExpressionStatement" && node.expression?.type === "Literal" && typeof node.expression.value === "string") {
1497
+ if (node.expression.value === "use client") return true;
1498
+ continue;
1499
+ }
1500
+ break;
1501
+ }
1502
+ return false;
1503
+ }
1504
+ var init_directive_prologue = __esm({
1505
+ "src/vite/utils/directive-prologue.ts"() {
1506
+ "use strict";
1507
+ }
1508
+ });
1509
+
966
1510
  // src/vite/plugins/version-plugin.ts
967
1511
  var version_plugin_exports = {};
968
1512
  __export(version_plugin_exports, {
969
- createVersionPlugin: () => createVersionPlugin
1513
+ createVersionPlugin: () => createVersionPlugin,
1514
+ isViteDepCachePath: () => isViteDepCachePath
970
1515
  });
971
- import { parseAst } from "vite";
1516
+ import { parseAst as parseAst2 } from "vite";
972
1517
  function isCodeModule(id) {
973
1518
  return /\.(tsx?|jsx?)($|\?)/.test(id);
974
1519
  }
@@ -976,23 +1521,13 @@ function normalizeModuleId(id) {
976
1521
  return id.split("?", 1)[0];
977
1522
  }
978
1523
  function getClientModuleSignature(source) {
1524
+ if (!hasUseClientDirective(source)) return void 0;
979
1525
  let program;
980
1526
  try {
981
- program = parseAst(source, { jsx: true });
1527
+ program = parseAst2(source, { lang: "tsx" });
982
1528
  } catch {
983
1529
  return void 0;
984
1530
  }
985
- let isUseClient = false;
986
- for (const node of program.body ?? []) {
987
- if (node?.type === "ExpressionStatement" && node.expression?.type === "Literal" && typeof node.expression.value === "string") {
988
- if (node.expression.value === "use client") {
989
- isUseClient = true;
990
- }
991
- continue;
992
- }
993
- break;
994
- }
995
- if (!isUseClient) return void 0;
996
1531
  const exports = /* @__PURE__ */ new Set();
997
1532
  let hasDefault = false;
998
1533
  let hasExportAll = false;
@@ -1061,10 +1596,12 @@ function createVersionPlugin() {
1061
1596
  let currentVersion = buildVersion;
1062
1597
  let isDev = false;
1063
1598
  let server = null;
1599
+ let resolvedCacheDir;
1064
1600
  const clientModuleSignatures = /* @__PURE__ */ new Map();
1601
+ let versionCounter = 0;
1065
1602
  const bumpVersion = (reason) => {
1066
- currentVersion = Date.now().toString(16);
1067
- console.log(`[rsc-router] ${reason}, version updated: ${currentVersion}`);
1603
+ currentVersion = Date.now().toString(16) + String(++versionCounter);
1604
+ console.log(`[rango] ${reason}, version updated: ${currentVersion}`);
1068
1605
  const rscEnv = server?.environments?.rsc;
1069
1606
  const versionMod = rscEnv?.moduleGraph?.getModuleById(
1070
1607
  "\0" + VIRTUAL_IDS.version
@@ -1078,6 +1615,7 @@ function createVersionPlugin() {
1078
1615
  enforce: "pre",
1079
1616
  configResolved(config) {
1080
1617
  isDev = config.command === "serve";
1618
+ resolvedCacheDir = config.cacheDir ? String(config.cacheDir).replace(/\\/g, "/") : void 0;
1081
1619
  },
1082
1620
  configureServer(devServer) {
1083
1621
  server = devServer;
@@ -1114,11 +1652,14 @@ function createVersionPlugin() {
1114
1652
  }
1115
1653
  return null;
1116
1654
  },
1117
- // Track RSC module changes and update version
1118
1655
  async hotUpdate(ctx) {
1119
1656
  if (!isDev) return;
1120
1657
  const isRscModule = this.environment?.name === "rsc";
1121
1658
  if (!isRscModule) return;
1659
+ if (isViteDepCachePath(ctx.file, resolvedCacheDir)) return;
1660
+ if (ctx.modules.length === 1 && ctx.modules[0].id === "\0" + VIRTUAL_IDS.version) {
1661
+ return;
1662
+ }
1122
1663
  if (isCodeModule(ctx.file)) {
1123
1664
  const filePath = normalizeModuleId(ctx.file);
1124
1665
  const previousSignature = clientModuleSignatures.get(filePath);
@@ -1145,10 +1686,22 @@ function createVersionPlugin() {
1145
1686
  }
1146
1687
  };
1147
1688
  }
1689
+ function isViteDepCachePath(filePath, cacheDir) {
1690
+ if (!filePath) return false;
1691
+ const normalized = filePath.replace(/\\/g, "/");
1692
+ if (cacheDir) {
1693
+ const normalizedCacheDir = cacheDir.replace(/\\/g, "/").replace(/\/+$/, "");
1694
+ if (normalized === normalizedCacheDir || normalized.startsWith(normalizedCacheDir + "/")) {
1695
+ return true;
1696
+ }
1697
+ }
1698
+ return /\/node_modules\/\.vite[^/]*\//.test(normalized) || normalized.includes("/.vite-isolated/");
1699
+ }
1148
1700
  var init_version_plugin = __esm({
1149
1701
  "src/vite/plugins/version-plugin.ts"() {
1150
1702
  "use strict";
1151
1703
  init_virtual_entries();
1704
+ init_directive_prologue();
1152
1705
  }
1153
1706
  });
1154
1707
 
@@ -1190,7 +1743,7 @@ var runtime_discovery_exports = {};
1190
1743
  __export(runtime_discovery_exports, {
1191
1744
  discoverAndWriteRouteTypes: () => discoverAndWriteRouteTypes
1192
1745
  });
1193
- import { dirname as dirname3, join as join3, basename, resolve as resolve3 } from "node:path";
1746
+ import { resolve as resolve3 } from "node:path";
1194
1747
  import { existsSync as existsSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
1195
1748
  async function discoverAndWriteRouteTypes(opts) {
1196
1749
  let createViteServer;
@@ -1276,7 +1829,10 @@ async function discoverAndWriteRouteTypes(opts) {
1276
1829
  let routerMountIndex = 0;
1277
1830
  for (const [id, router] of registry) {
1278
1831
  if (!router.urlpatterns) continue;
1279
- const manifest = generateManifest(router.urlpatterns, routerMountIndex);
1832
+ const manifest = await generateManifest(
1833
+ router.urlpatterns,
1834
+ routerMountIndex
1835
+ );
1280
1836
  routerMountIndex++;
1281
1837
  const rawManifest = manifest.routeManifest;
1282
1838
  const routeManifest = {};
@@ -1300,22 +1856,12 @@ This means createRouter() stack trace parsing matched an internal frame.
1300
1856
  Set an explicit \`id\` on createRouter() or check the call site.`
1301
1857
  );
1302
1858
  }
1303
- if (!routeSearchSchemas || Object.keys(routeSearchSchemas).length === 0) {
1304
- const staticParsed = buildCombinedRouteMapForRouterFile(sourceFile);
1305
- if (Object.keys(staticParsed.searchSchemas).length > 0) {
1306
- const filtered = {};
1307
- for (const name of Object.keys(routeManifest)) {
1308
- const schema = staticParsed.searchSchemas[name];
1309
- if (schema) filtered[name] = schema;
1310
- }
1311
- if (Object.keys(filtered).length > 0) {
1312
- routeSearchSchemas = filtered;
1313
- }
1314
- }
1315
- }
1316
- const routerDir = dirname3(sourceFile);
1317
- const routerBasename = basename(sourceFile).replace(/\.(tsx?|jsx?)$/, "");
1318
- const outPath = join3(routerDir, `${routerBasename}.named-routes.gen.ts`);
1859
+ routeSearchSchemas = resolveSearchSchemas(
1860
+ Object.keys(routeManifest),
1861
+ routeSearchSchemas,
1862
+ sourceFile
1863
+ );
1864
+ const outPath = genFileTsPath(sourceFile);
1319
1865
  const source = generateRouteTypesSource(
1320
1866
  routeManifest,
1321
1867
  routeSearchSchemas && Object.keys(routeSearchSchemas).length > 0 ? routeSearchSchemas : void 0
@@ -1352,7 +1898,7 @@ var init_runtime_discovery = __esm({
1352
1898
 
1353
1899
  // src/bin/rango.ts
1354
1900
  init_generate_route_types();
1355
- import { resolve as resolve4, dirname as dirname4 } from "node:path";
1901
+ import { resolve as resolve4, dirname as dirname3 } from "node:path";
1356
1902
  import { readFileSync as readFileSync5, statSync, existsSync as existsSync5 } from "node:fs";
1357
1903
  var [command, ...rawArgs] = process.argv.slice(2);
1358
1904
  if (command === "generate") {
@@ -1423,12 +1969,12 @@ Examples:
1423
1969
  );
1424
1970
  }
1425
1971
  function findProjectRoot(fromPath) {
1426
- let dir = dirname4(resolve4(fromPath));
1427
- while (dir !== dirname4(dir)) {
1972
+ let dir = dirname3(resolve4(fromPath));
1973
+ while (dir !== dirname3(dir)) {
1428
1974
  if (existsSync5(resolve4(dir, "package.json")) || existsSync5(resolve4(dir, "vite.config.ts")) || existsSync5(resolve4(dir, "vite.config.js"))) {
1429
1975
  return dir;
1430
1976
  }
1431
- dir = dirname4(dir);
1977
+ dir = dirname3(dir);
1432
1978
  }
1433
1979
  return process.cwd();
1434
1980
  }