@rangojs/router 0.0.0-experimental.bd6e11bc → 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.
- package/AGENTS.md +8 -4
- package/README.md +296 -887
- package/dist/bin/rango.js +459 -91
- package/dist/testing/vitest.js +36 -2
- package/dist/vite/index.js +1708 -414
- package/package.json +35 -10
- package/skills/api-client/SKILL.md +211 -0
- package/skills/breadcrumbs/SKILL.md +82 -5
- package/skills/bundle-analysis/SKILL.md +2 -2
- package/skills/cache-guide/SKILL.md +14 -9
- package/skills/caching/SKILL.md +221 -12
- package/skills/catalog.json +271 -0
- package/skills/comparison/SKILL.md +50 -0
- package/skills/comparison/agents/openai.yaml +4 -0
- package/skills/comparison/references/framework-comparison.md +837 -0
- package/skills/composability/SKILL.md +83 -2
- package/skills/css/SKILL.md +76 -0
- package/skills/debug-manifest/SKILL.md +5 -3
- package/skills/defer-hydration/SKILL.md +235 -0
- package/skills/document-cache/SKILL.md +11 -3
- package/skills/fonts/SKILL.md +1 -1
- package/skills/handler-use/SKILL.md +9 -9
- package/skills/hooks/SKILL.md +73 -900
- package/skills/hooks/data.md +273 -0
- package/skills/hooks/handle-and-actions.md +103 -0
- package/skills/hooks/navigation.md +110 -0
- package/skills/hooks/outlets.md +41 -0
- package/skills/hooks/state.md +228 -0
- package/skills/hooks/urls.md +135 -0
- package/skills/host-router/SKILL.md +84 -7
- package/skills/i18n/SKILL.md +1 -1
- package/skills/intercept/SKILL.md +51 -17
- package/skills/layout/SKILL.md +38 -16
- package/skills/links/SKILL.md +1 -1
- package/skills/loader/SKILL.md +48 -20
- package/skills/middleware/SKILL.md +11 -5
- package/skills/migrate-nextjs/SKILL.md +203 -20
- package/skills/migrate-react-router/SKILL.md +59 -675
- package/skills/migrate-react-router/cloudflare-workers.md +129 -0
- package/skills/migrate-react-router/component-migration.md +196 -0
- package/skills/migrate-react-router/data-and-actions.md +225 -0
- package/skills/migrate-react-router/route-mapping.md +271 -0
- package/skills/mime-routes/SKILL.md +3 -3
- package/skills/observability/SKILL.md +70 -5
- package/skills/parallel/SKILL.md +32 -8
- package/skills/ppr/SKILL.md +622 -0
- package/skills/prerender/SKILL.md +59 -28
- package/skills/rango/SKILL.md +124 -50
- package/skills/response-routes/SKILL.md +78 -46
- package/skills/route/SKILL.md +85 -6
- package/skills/router-setup/SKILL.md +41 -6
- package/skills/scripts/SKILL.md +179 -0
- package/skills/server-actions/SKILL.md +28 -3
- package/skills/shell-manifest/SKILL.md +185 -0
- package/skills/streams-and-websockets/SKILL.md +1 -1
- package/skills/tailwind/SKILL.md +28 -4
- package/skills/testing/SKILL.md +68 -654
- package/skills/testing/bindings.md +103 -0
- package/skills/testing/cache-prerender.md +127 -0
- package/skills/testing/client-components.md +124 -0
- package/skills/testing/e2e-parity.md +125 -0
- package/skills/testing/flight.md +91 -0
- package/skills/testing/handles.md +131 -0
- package/skills/testing/loader.md +128 -0
- package/skills/testing/middleware.md +99 -0
- package/skills/testing/render-handler.md +122 -0
- package/skills/testing/response-routes.md +95 -0
- package/skills/testing/reverse-and-types.md +85 -0
- package/skills/testing/server-actions.md +107 -0
- package/skills/testing/server-tree.md +128 -0
- package/skills/testing/setup.md +123 -0
- package/skills/theme/SKILL.md +1 -1
- package/skills/typesafety/SKILL.md +45 -918
- package/skills/typesafety/env-and-bindings.md +254 -0
- package/skills/typesafety/generated-files-and-cli.md +335 -0
- package/skills/typesafety/params-and-search.md +153 -0
- package/skills/typesafety/route-types.md +209 -0
- package/skills/use-cache/SKILL.md +47 -17
- package/skills/vercel/SKILL.md +128 -0
- package/skills/view-transitions/SKILL.md +44 -1
- package/src/__augment-tests__/augmented.check.ts +2 -3
- package/src/__internal.ts +0 -65
- package/src/browser/action-coordinator.ts +1 -1
- package/src/browser/action-fence.ts +47 -0
- package/src/browser/app-shell.ts +14 -27
- package/src/browser/connection-warmup.ts +134 -0
- package/src/browser/cookie-name.ts +140 -0
- package/src/browser/event-controller.ts +178 -100
- package/src/browser/invalidate-client-cache.ts +52 -0
- package/src/browser/logging.ts +28 -0
- package/src/browser/merge-segment-loaders.ts +6 -4
- package/src/browser/navigation-bridge.ts +81 -68
- package/src/browser/navigation-client.ts +115 -70
- package/src/browser/navigation-store-handle.ts +38 -0
- package/src/browser/navigation-store.ts +153 -88
- package/src/browser/navigation-transaction.ts +0 -32
- package/src/browser/network-error-handler.ts +34 -7
- package/src/browser/partial-update.ts +157 -144
- package/src/browser/prefetch/cache.ts +148 -81
- package/src/browser/prefetch/fetch.ts +231 -51
- package/src/browser/prefetch/queue.ts +25 -7
- package/src/browser/rango-state.ts +157 -115
- package/src/browser/react/Link.tsx +40 -7
- package/src/browser/react/NavigationProvider.tsx +140 -99
- package/src/browser/react/ScrollRestoration.tsx +10 -6
- package/src/browser/react/filter-segment-order.ts +17 -2
- package/src/browser/react/index.ts +0 -51
- package/src/browser/react/location-state-shared.ts +14 -15
- package/src/browser/react/location-state.ts +0 -1
- package/src/browser/react/use-action.ts +6 -15
- package/src/browser/react/use-handle.ts +0 -5
- package/src/browser/react/use-href.tsx +8 -1
- package/src/browser/react/use-link-status.ts +33 -8
- package/src/browser/react/use-navigation.ts +10 -5
- package/src/browser/react/use-params.ts +0 -2
- package/src/browser/react/use-router.ts +6 -4
- package/src/browser/react/use-search-params.ts +0 -5
- package/src/browser/react/use-segments.ts +0 -13
- package/src/browser/response-adapter.ts +74 -8
- package/src/browser/rsc-router.tsx +97 -22
- package/src/browser/scroll-restoration.ts +15 -8
- package/src/browser/segment-reconciler.ts +31 -21
- package/src/browser/server-action-bridge.ts +216 -38
- package/src/browser/types.ts +94 -22
- package/src/browser/validate-redirect-origin.ts +43 -16
- package/src/build/generate-manifest.ts +155 -131
- package/src/build/generate-route-types.ts +1 -1
- package/src/build/index.ts +11 -5
- package/src/build/prefix-tree-utils.ts +123 -0
- package/src/build/route-trie.ts +152 -22
- package/src/build/route-types/ast-route-extraction.ts +15 -8
- package/src/build/route-types/codegen.ts +12 -1
- package/src/build/route-types/include-resolution.ts +455 -61
- package/src/build/route-types/param-extraction.ts +6 -3
- package/src/build/route-types/per-module-writer.ts +15 -2
- package/src/build/route-types/router-processing.ts +77 -41
- package/src/build/route-types/source-scan.ts +105 -7
- package/src/build/runtime-discovery.ts +4 -1
- package/src/cache/cache-error.ts +104 -0
- package/src/cache/cache-key-utils.ts +58 -13
- package/src/cache/cache-policy.ts +108 -34
- package/src/cache/cache-runtime.ts +454 -101
- package/src/cache/cache-scope.ts +159 -54
- package/src/cache/cache-tag.ts +149 -0
- package/src/cache/cf/cf-base64.ts +33 -0
- package/src/cache/cf/cf-cache-constants.ts +127 -0
- package/src/cache/cf/cf-cache-store.ts +2170 -377
- package/src/cache/cf/cf-cache-types.ts +349 -0
- package/src/cache/cf/cf-kv-utils.ts +46 -0
- package/src/cache/cf/cf-tag-marker-memo.ts +105 -0
- package/src/cache/cf/index.ts +6 -16
- package/src/cache/document-cache.ts +126 -41
- package/src/cache/handle-snapshot.ts +70 -0
- package/src/cache/index.ts +23 -20
- package/src/cache/memory-segment-store.ts +243 -37
- package/src/cache/profile-registry.ts +46 -31
- package/src/cache/read-through-swr.ts +56 -12
- package/src/cache/segment-codec.ts +13 -21
- package/src/cache/shell-snapshot.ts +417 -0
- package/src/cache/tag-invalidation.ts +230 -0
- package/src/cache/types.ts +194 -99
- package/src/cache/vercel/index.ts +11 -0
- package/src/cache/vercel/vercel-cache-store.ts +1132 -0
- package/src/client.rsc.tsx +39 -22
- package/src/client.tsx +28 -58
- package/src/cloudflare/index.ts +11 -0
- package/src/cloudflare/tracing.ts +108 -0
- package/src/component-utils.ts +19 -0
- package/src/components/DefaultDocument.tsx +8 -2
- package/src/context-var.ts +13 -1
- package/src/decode-loader-results.ts +18 -2
- package/src/defer.ts +185 -0
- package/src/deps/ssr.ts +0 -1
- package/src/encode-kv.ts +49 -0
- package/src/errors.ts +0 -3
- package/src/escape-script.ts +52 -0
- package/src/handle.ts +57 -40
- package/src/handles/MetaTags.tsx +24 -53
- package/src/handles/Scripts.tsx +183 -0
- package/src/handles/breadcrumbs.ts +35 -8
- package/src/handles/deferred-resolution.ts +127 -0
- package/src/handles/is-thenable.ts +18 -0
- package/src/handles/meta.ts +14 -40
- package/src/handles/script.ts +244 -0
- package/src/host/cookie-handler.ts +9 -60
- package/src/host/errors.ts +13 -22
- package/src/host/index.ts +7 -0
- package/src/host/pattern-matcher.ts +23 -52
- package/src/host/router.ts +1 -65
- package/src/host/testing.ts +40 -27
- package/src/host/types.ts +6 -2
- package/src/href-client.ts +7 -12
- package/src/index.rsc.ts +88 -8
- package/src/index.ts +90 -16
- package/src/internal-debug.ts +11 -10
- package/src/loader.rsc.ts +19 -9
- package/src/loader.ts +12 -4
- package/src/outlet-provider.tsx +1 -5
- package/src/prerender/param-hash.ts +16 -16
- package/src/prerender/store.ts +32 -37
- package/src/prerender.ts +75 -7
- package/src/redirect-origin.ts +114 -0
- package/src/regex-escape.ts +8 -0
- package/src/render-error-thrower.tsx +20 -0
- package/src/response-utils.ts +25 -0
- package/src/root-error-boundary.tsx +1 -19
- package/src/route-content-wrapper.tsx +13 -49
- package/src/route-definition/dsl-helpers.ts +60 -53
- package/src/route-definition/helper-factories.ts +0 -2
- package/src/route-definition/helpers-types.ts +46 -46
- package/src/route-definition/index.ts +1 -2
- package/src/route-definition/redirect.ts +44 -11
- package/src/route-definition/resolve-handler-use.ts +6 -1
- package/src/route-definition/use-item-types.ts +3 -6
- package/src/route-map-builder.ts +41 -20
- package/src/route-types.ts +0 -5
- package/src/router/content-negotiation.ts +58 -23
- package/src/router/error-handling.ts +44 -17
- package/src/router/find-match.ts +129 -30
- package/src/router/handler-context.ts +6 -1
- package/src/router/instrument.ts +355 -0
- package/src/router/intercept-resolution.ts +35 -2
- package/src/router/lazy-includes.ts +79 -56
- package/src/router/loader-resolution.ts +151 -73
- package/src/router/logging.ts +0 -6
- package/src/router/manifest.ts +74 -40
- package/src/router/match-api.ts +76 -52
- package/src/router/match-context.ts +0 -22
- package/src/router/match-handlers.ts +181 -178
- package/src/router/match-middleware/background-revalidation.ts +40 -24
- package/src/router/match-middleware/cache-lookup.ts +115 -194
- package/src/router/match-middleware/cache-store.ts +61 -50
- package/src/router/match-middleware/intercept-resolution.ts +0 -22
- package/src/router/match-middleware/segment-resolution.ts +0 -22
- package/src/router/match-pipelines.ts +1 -42
- package/src/router/match-result.ts +36 -67
- package/src/router/metrics.ts +0 -34
- package/src/router/middleware-types.ts +0 -116
- package/src/router/middleware.ts +231 -120
- package/src/router/navigation-snapshot.ts +7 -56
- package/src/router/params-util.ts +23 -0
- package/src/router/parse-pattern.ts +115 -0
- package/src/router/pattern-matching.ts +99 -152
- package/src/router/prefetch-cache-ttl.ts +51 -0
- package/src/router/prefetch-limits.ts +37 -0
- package/src/router/prerender-match.ts +111 -66
- package/src/router/preview-match.ts +3 -1
- package/src/router/request-classification.ts +47 -42
- package/src/router/revalidation.ts +75 -81
- package/src/router/route-snapshot.ts +14 -3
- package/src/router/router-context.ts +6 -29
- package/src/router/router-interfaces.ts +70 -8
- package/src/router/router-options.ts +126 -4
- package/src/router/segment-resolution/fresh.ts +104 -80
- package/src/router/segment-resolution/helpers.ts +86 -6
- package/src/router/segment-resolution/loader-cache.ts +155 -39
- package/src/router/segment-resolution/loader-mask.ts +60 -0
- package/src/router/segment-resolution/loader-snapshot.ts +259 -0
- package/src/router/segment-resolution/mask-nested.ts +83 -0
- package/src/router/segment-resolution/revalidation.ts +215 -304
- package/src/router/segment-resolution/static-store.ts +19 -5
- package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
- package/src/router/segment-resolution/view-transition-default.ts +35 -15
- package/src/router/segment-resolution.ts +5 -1
- package/src/router/segment-wrappers.ts +6 -5
- package/src/router/state-cookie-name.ts +33 -0
- package/src/router/substitute-pattern-params.ts +54 -35
- package/src/router/telemetry-otel.ts +160 -200
- package/src/router/telemetry.ts +9 -23
- package/src/router/timeout.ts +0 -20
- package/src/router/tracing.ts +215 -0
- package/src/router/trie-matching.ts +171 -64
- package/src/router/types.ts +1 -63
- package/src/router/url-params.ts +13 -5
- package/src/router.ts +119 -48
- package/src/rsc/full-payload.ts +70 -0
- package/src/rsc/handler-context.ts +1 -0
- package/src/rsc/handler.ts +267 -152
- package/src/rsc/helpers.ts +78 -4
- package/src/rsc/index.ts +1 -4
- package/src/rsc/json-route-result.ts +38 -0
- package/src/rsc/loader-fetch.ts +114 -38
- package/src/rsc/manifest-init.ts +29 -42
- package/src/rsc/nonce.ts +10 -1
- package/src/rsc/origin-guard.ts +11 -15
- package/src/rsc/progressive-enhancement.ts +120 -13
- package/src/rsc/redirect-guard.ts +100 -0
- package/src/rsc/response-cache-serve.ts +238 -0
- package/src/rsc/response-error.ts +79 -12
- package/src/rsc/response-route-handler.ts +58 -141
- package/src/rsc/rsc-rendering.ts +492 -49
- package/src/rsc/runtime-warnings.ts +14 -0
- package/src/rsc/server-action.ts +268 -82
- package/src/rsc/shell-capture.ts +1190 -0
- package/src/rsc/shell-serve.ts +181 -0
- package/src/rsc/transition-gate.ts +89 -0
- package/src/rsc/types.ts +45 -3
- package/src/runtime-env.ts +18 -0
- package/src/search-params.ts +31 -26
- package/src/segment-loader-promise.ts +49 -4
- package/src/segment-system.tsx +260 -95
- package/src/server/context.ts +99 -9
- package/src/server/cookie-parse.ts +32 -0
- package/src/server/cookie-store.ts +125 -2
- package/src/server/handle-store.ts +21 -38
- package/src/server/loader-registry.ts +33 -42
- package/src/server/request-context.ts +379 -138
- package/src/ssr/index.tsx +491 -182
- package/src/ssr/inject-rsc-eager.ts +167 -0
- package/src/ssr/ssr-root.tsx +228 -0
- package/src/static-handler.ts +10 -13
- package/src/testing/cache-status.ts +44 -48
- package/src/testing/collect-handle.ts +14 -31
- package/src/testing/dispatch.ts +533 -160
- package/src/testing/e2e/fixture.ts +45 -11
- package/src/testing/e2e/index.ts +1 -22
- package/src/testing/e2e/matchers.ts +0 -16
- package/src/testing/e2e/parity.ts +85 -4
- package/src/testing/e2e/server.ts +12 -0
- package/src/testing/flight-matchers.ts +7 -14
- package/src/testing/flight-normalize.ts +11 -0
- package/src/testing/flight-runtime.d.ts +36 -0
- package/src/testing/flight-tree.ts +682 -0
- package/src/testing/flight.entry.ts +30 -0
- package/src/testing/flight.ts +145 -70
- package/src/testing/generated-routes.ts +26 -50
- package/src/testing/index.ts +18 -19
- package/src/testing/internal/context.ts +184 -68
- package/src/testing/internal/flight-client-globals.ts +30 -0
- package/src/testing/internal/seed-vars.ts +54 -0
- package/src/testing/render-handler.ts +357 -0
- package/src/testing/render-route.tsx +134 -115
- package/src/testing/run-loader.ts +140 -51
- package/src/testing/run-middleware.ts +59 -33
- package/src/testing/run-transition-when.ts +164 -0
- package/src/testing/vitest-stubs/cloudflare-email.ts +1 -1
- package/src/testing/vitest-stubs/cloudflare-workers.ts +1 -1
- package/src/testing/vitest.ts +138 -16
- package/src/theme/ThemeProvider.tsx +56 -84
- package/src/theme/ThemeScript.tsx +7 -9
- package/src/theme/constants.ts +52 -13
- package/src/theme/index.ts +0 -7
- package/src/theme/theme-context.ts +1 -5
- package/src/theme/theme-script.ts +22 -21
- package/src/theme/use-theme.ts +0 -3
- package/src/types/boundaries.ts +0 -35
- package/src/types/cache-types.ts +13 -4
- package/src/types/error-types.ts +30 -90
- package/src/types/global-namespace.ts +15 -15
- package/src/types/handler-context.ts +45 -15
- package/src/types/index.ts +2 -10
- package/src/types/loader-types.ts +6 -3
- package/src/types/request-scope.ts +8 -22
- package/src/types/route-config.ts +20 -52
- package/src/types/route-entry.ts +0 -6
- package/src/types/segments.ts +100 -13
- package/src/urls/include-helper.ts +10 -12
- package/src/urls/include-provider.ts +71 -0
- package/src/urls/index.ts +2 -8
- package/src/urls/path-helper-types.ts +52 -14
- package/src/urls/path-helper.ts +5 -54
- package/src/urls/pattern-types.ts +36 -0
- package/src/urls/type-extraction.ts +76 -42
- package/src/urls/urls-function.ts +0 -14
- package/src/use-loader.tsx +0 -186
- package/src/vercel/index.ts +11 -0
- package/src/vercel/tracing.ts +88 -0
- package/src/vite/discovery/bundle-postprocess.ts +2 -1
- package/src/vite/discovery/dev-prerender-cache.ts +117 -0
- package/src/vite/discovery/discover-routers.ts +34 -43
- package/src/vite/discovery/discovery-errors.ts +61 -0
- package/src/vite/discovery/prerender-collection.ts +33 -46
- package/src/vite/discovery/state.ts +12 -1
- package/src/vite/discovery/virtual-module-codegen.ts +1 -11
- package/src/vite/index.ts +9 -0
- package/src/vite/inject-client-debug.ts +88 -0
- package/src/vite/plugin-types.ts +143 -10
- package/src/vite/plugins/cjs-to-esm.ts +8 -12
- package/src/vite/plugins/client-ref-dedup.ts +0 -11
- package/src/vite/plugins/client-ref-hashing.ts +0 -10
- package/src/vite/plugins/cloudflare-protocol-stub.ts +0 -20
- package/src/vite/plugins/expose-action-id.ts +2 -73
- package/src/vite/plugins/expose-id-utils.ts +85 -56
- package/src/vite/plugins/expose-ids/export-analysis.ts +30 -43
- package/src/vite/plugins/expose-ids/handler-transform.ts +5 -31
- package/src/vite/plugins/expose-ids/loader-transform.ts +12 -20
- package/src/vite/plugins/expose-ids/router-transform.ts +98 -26
- package/src/vite/plugins/expose-internal-ids.ts +10 -1
- package/src/vite/plugins/performance-tracks.ts +0 -3
- package/src/vite/plugins/refresh-cmd.ts +1 -1
- package/src/vite/plugins/use-cache-transform.ts +21 -46
- package/src/vite/plugins/vercel-output.ts +384 -0
- package/src/vite/plugins/version-injector.ts +22 -27
- package/src/vite/plugins/version-plugin.ts +6 -66
- package/src/vite/plugins/virtual-entries.ts +137 -26
- package/src/vite/rango.ts +146 -135
- package/src/vite/router-discovery.ts +189 -48
- package/src/vite/utils/ast-handler-extract.ts +11 -20
- package/src/vite/utils/bundle-analysis.ts +6 -13
- package/src/vite/utils/client-chunks.ts +0 -6
- package/src/vite/utils/directive-prologue.ts +40 -0
- package/src/vite/utils/forward-user-plugins.ts +0 -22
- package/src/vite/utils/manifest-utils.ts +4 -75
- package/src/vite/utils/package-resolution.ts +1 -73
- package/src/vite/utils/prerender-utils.ts +71 -44
- package/src/vite/utils/shared-utils.ts +55 -37
- package/src/browser/react/use-client-cache.ts +0 -58
- package/src/browser/shallow.ts +0 -40
- package/src/handles/index.ts +0 -7
- package/src/network-error-thrower.tsx +0 -23
- 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
|
-
|
|
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}:
|
|
30
|
+
return ` ${key}: ${JSON.stringify(pattern)},`;
|
|
26
31
|
}
|
|
27
|
-
const searchBody = Object.entries(search).map(([k, v]) => `${k}:
|
|
28
|
-
return ` ${key}: { path:
|
|
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,
|
|
@@ -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
198
|
namespace Rango {
|
|
190
|
-
interface GeneratedRouteMap extends
|
|
199
|
+
interface GeneratedRouteMap extends NamedRoutesShape {}
|
|
191
200
|
}
|
|
192
201
|
}
|
|
193
202
|
`;
|
|
@@ -238,6 +247,33 @@ var init_scan_filter = __esm({
|
|
|
238
247
|
import { readFileSync, existsSync } from "node:fs";
|
|
239
248
|
import { dirname, resolve } from "node:path";
|
|
240
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
|
+
}
|
|
241
277
|
function extractNamePrefixFromInclude(node) {
|
|
242
278
|
if (node.arguments.length >= 3) {
|
|
243
279
|
const thirdArg = node.arguments[2];
|
|
@@ -253,8 +289,98 @@ function extractNamePrefixFromInclude(node) {
|
|
|
253
289
|
}
|
|
254
290
|
return null;
|
|
255
291
|
}
|
|
256
|
-
function
|
|
257
|
-
const
|
|
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(
|
|
258
384
|
"input.tsx",
|
|
259
385
|
code,
|
|
260
386
|
ts3.ScriptTarget.Latest,
|
|
@@ -278,12 +404,19 @@ function extractIncludesWithDiagnostics(code) {
|
|
|
278
404
|
}
|
|
279
405
|
const secondArg = node.arguments[1];
|
|
280
406
|
const namePrefix = extractNamePrefixFromInclude(node);
|
|
407
|
+
const dynamicImportSpec = extractDynamicImportSpecifier(secondArg);
|
|
281
408
|
if (ts3.isIdentifier(secondArg)) {
|
|
282
409
|
resolved.push({
|
|
283
410
|
pathPrefix,
|
|
284
411
|
variableName: secondArg.text,
|
|
285
412
|
namePrefix
|
|
286
413
|
});
|
|
414
|
+
} else if (dynamicImportSpec !== null) {
|
|
415
|
+
resolved.push({
|
|
416
|
+
pathPrefix,
|
|
417
|
+
moduleSpecifier: dynamicImportSpec,
|
|
418
|
+
namePrefix
|
|
419
|
+
});
|
|
287
420
|
} else if (ts3.isCallExpression(secondArg)) {
|
|
288
421
|
const callText = secondArg.expression.getText(sourceFile);
|
|
289
422
|
unresolvable.push({
|
|
@@ -308,7 +441,7 @@ function extractIncludesWithDiagnostics(code) {
|
|
|
308
441
|
return { resolved, unresolvable };
|
|
309
442
|
}
|
|
310
443
|
function resolveImportedVariable(code, localName) {
|
|
311
|
-
const importRegex = /import\s
|
|
444
|
+
const importRegex = /import\s*(?:[\w$]+\s*,\s*)?\{([^}]+)\}\s*from\s*["']([^"']+)["']/g;
|
|
312
445
|
let match;
|
|
313
446
|
while ((match = importRegex.exec(code)) !== null) {
|
|
314
447
|
const imports = match[1];
|
|
@@ -345,8 +478,8 @@ function resolveImportPath(importSpec, fromFile) {
|
|
|
345
478
|
}
|
|
346
479
|
return null;
|
|
347
480
|
}
|
|
348
|
-
function extractUrlsBlockForVariable(code, varName) {
|
|
349
|
-
const sourceFile = ts3.createSourceFile(
|
|
481
|
+
function extractUrlsBlockForVariable(code, varName, sourceFileArg) {
|
|
482
|
+
const sourceFile = sourceFileArg ?? ts3.createSourceFile(
|
|
350
483
|
"input.tsx",
|
|
351
484
|
code,
|
|
352
485
|
ts3.ScriptTarget.Latest,
|
|
@@ -368,67 +501,113 @@ function extractUrlsBlockForVariable(code, varName) {
|
|
|
368
501
|
visit(sourceFile);
|
|
369
502
|
return result;
|
|
370
503
|
}
|
|
371
|
-
function buildRouteMapFromBlock(block, fullSource, filePath, visited, searchSchemasOut, diagnosticsOut) {
|
|
504
|
+
function buildRouteMapFromBlock(block, fullSource, filePath, visited, searchSchemasOut, diagnosticsOut, memo) {
|
|
372
505
|
const routeMap = {};
|
|
373
|
-
const
|
|
506
|
+
const blockSourceFile = parseBlock(memo, block);
|
|
507
|
+
const localRoutes = extractRoutesFromSource(block, blockSourceFile);
|
|
374
508
|
for (const { name, pattern, search } of localRoutes) {
|
|
375
509
|
routeMap[name] = pattern;
|
|
376
510
|
if (search && searchSchemasOut) {
|
|
377
511
|
searchSchemasOut[name] = search;
|
|
378
512
|
}
|
|
379
513
|
}
|
|
380
|
-
const { resolved: includes, unresolvable } = extractIncludesWithDiagnostics(
|
|
514
|
+
const { resolved: includes, unresolvable } = extractIncludesWithDiagnostics(
|
|
515
|
+
block,
|
|
516
|
+
blockSourceFile
|
|
517
|
+
);
|
|
381
518
|
if (diagnosticsOut) {
|
|
382
519
|
for (const entry of unresolvable) {
|
|
383
520
|
diagnosticsOut.push({ ...entry, sourceFile: filePath });
|
|
384
521
|
}
|
|
385
522
|
}
|
|
386
|
-
for (const
|
|
523
|
+
for (const inc of includes) {
|
|
524
|
+
const { pathPrefix, namePrefix } = inc;
|
|
387
525
|
let childResult;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const targetFile = resolveImportPath(imported.specifier, filePath);
|
|
526
|
+
if (inc.moduleSpecifier) {
|
|
527
|
+
const targetFile = resolveImportPath(inc.moduleSpecifier, filePath);
|
|
391
528
|
if (!targetFile) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
});
|
|
400
|
-
}
|
|
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
|
+
});
|
|
401
536
|
continue;
|
|
402
537
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
diagnosticsOut
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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)
|
|
413
554
|
);
|
|
414
|
-
if (!
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
});
|
|
423
|
-
}
|
|
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
|
+
});
|
|
424
563
|
continue;
|
|
425
564
|
}
|
|
426
|
-
|
|
427
|
-
|
|
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({
|
|
428
595
|
variableName,
|
|
596
|
+
resolutionFile: filePath,
|
|
597
|
+
resolutionSource: fullSource,
|
|
598
|
+
reportFile: filePath,
|
|
599
|
+
memo,
|
|
429
600
|
visited,
|
|
430
|
-
diagnosticsOut
|
|
431
|
-
|
|
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;
|
|
432
611
|
}
|
|
433
612
|
if (namePrefix === null) {
|
|
434
613
|
continue;
|
|
@@ -451,8 +630,67 @@ function buildRouteMapFromBlock(block, fullSource, filePath, visited, searchSche
|
|
|
451
630
|
}
|
|
452
631
|
return routeMap;
|
|
453
632
|
}
|
|
454
|
-
function
|
|
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) {
|
|
455
692
|
visited = visited ?? /* @__PURE__ */ new Set();
|
|
693
|
+
memo = memo ?? createScanMemo();
|
|
456
694
|
const realPath = resolve(filePath);
|
|
457
695
|
const key = variableName ? `${realPath}:${variableName}` : realPath;
|
|
458
696
|
if (visited.has(key)) {
|
|
@@ -462,7 +700,7 @@ function buildCombinedRouteMapWithSearch(filePath, variableName, visited, diagno
|
|
|
462
700
|
visited.add(key);
|
|
463
701
|
let source;
|
|
464
702
|
try {
|
|
465
|
-
source =
|
|
703
|
+
source = readSourceMemoized(memo, realPath);
|
|
466
704
|
} catch {
|
|
467
705
|
return { routes: {}, searchSchemas: {} };
|
|
468
706
|
}
|
|
@@ -470,7 +708,11 @@ function buildCombinedRouteMapWithSearch(filePath, variableName, visited, diagno
|
|
|
470
708
|
if (inlineBlock) {
|
|
471
709
|
block = inlineBlock;
|
|
472
710
|
} else if (variableName) {
|
|
473
|
-
const extracted = extractUrlsBlockForVariable(
|
|
711
|
+
const extracted = extractUrlsBlockForVariable(
|
|
712
|
+
source,
|
|
713
|
+
variableName,
|
|
714
|
+
parseBlock(memo, source)
|
|
715
|
+
);
|
|
474
716
|
if (!extracted) return { routes: {}, searchSchemas: {} };
|
|
475
717
|
block = extracted;
|
|
476
718
|
} else {
|
|
@@ -483,7 +725,8 @@ function buildCombinedRouteMapWithSearch(filePath, variableName, visited, diagno
|
|
|
483
725
|
realPath,
|
|
484
726
|
visited,
|
|
485
727
|
searchSchemas,
|
|
486
|
-
diagnosticsOut
|
|
728
|
+
diagnosticsOut,
|
|
729
|
+
memo
|
|
487
730
|
);
|
|
488
731
|
visited.delete(key);
|
|
489
732
|
return { routes, searchSchemas };
|
|
@@ -528,8 +771,16 @@ function writePerModuleRouteTypesForFile(filePath) {
|
|
|
528
771
|
let routes;
|
|
529
772
|
if (varNames.length > 0) {
|
|
530
773
|
routes = [];
|
|
774
|
+
const memo = createScanMemo();
|
|
531
775
|
for (const varName of varNames) {
|
|
532
|
-
const { routes: routeMap, searchSchemas } = buildCombinedRouteMapWithSearch(
|
|
776
|
+
const { routes: routeMap, searchSchemas } = buildCombinedRouteMapWithSearch(
|
|
777
|
+
filePath,
|
|
778
|
+
varName,
|
|
779
|
+
void 0,
|
|
780
|
+
void 0,
|
|
781
|
+
void 0,
|
|
782
|
+
memo
|
|
783
|
+
);
|
|
533
784
|
for (const [name, pattern] of Object.entries(routeMap)) {
|
|
534
785
|
const params = extractParamsFromPattern(pattern);
|
|
535
786
|
routes.push({
|
|
@@ -581,25 +832,39 @@ function isLineTerminator(ch) {
|
|
|
581
832
|
const c = ch.charCodeAt(0);
|
|
582
833
|
return c === 10 || c === 13 || c === 8232 || c === 8233;
|
|
583
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
|
+
}
|
|
584
845
|
function makeCodeClassifier(code) {
|
|
585
846
|
const n = code.length;
|
|
586
847
|
let i = 0;
|
|
587
848
|
let skipStart = -1;
|
|
588
849
|
let skipEnd = -1;
|
|
850
|
+
let lastSig;
|
|
589
851
|
return (q) => {
|
|
590
852
|
if (q >= skipStart && q < skipEnd) return false;
|
|
591
853
|
while (i < n && i <= q) {
|
|
592
854
|
const c = code[i];
|
|
593
855
|
const d = i + 1 < n ? code[i + 1] : "";
|
|
594
856
|
let end = -1;
|
|
857
|
+
let transparent = false;
|
|
595
858
|
if (c === "/" && d === "/") {
|
|
596
859
|
let j = i + 2;
|
|
597
860
|
while (j < n && !isLineTerminator(code[j])) j++;
|
|
598
861
|
end = j;
|
|
862
|
+
transparent = true;
|
|
599
863
|
} else if (c === "/" && d === "*") {
|
|
600
864
|
let j = i + 2;
|
|
601
865
|
while (j < n && !(code[j] === "*" && code[j + 1] === "/")) j++;
|
|
602
866
|
end = Math.min(n, j + 2);
|
|
867
|
+
transparent = true;
|
|
603
868
|
} else if (c === '"' || c === "'" || c === "`") {
|
|
604
869
|
let j = i + 1;
|
|
605
870
|
while (j < n) {
|
|
@@ -614,6 +879,29 @@ function makeCodeClassifier(code) {
|
|
|
614
879
|
j++;
|
|
615
880
|
}
|
|
616
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
|
+
}
|
|
617
905
|
}
|
|
618
906
|
if (end >= 0) {
|
|
619
907
|
if (q < end) {
|
|
@@ -622,7 +910,9 @@ function makeCodeClassifier(code) {
|
|
|
622
910
|
return false;
|
|
623
911
|
}
|
|
624
912
|
i = end;
|
|
913
|
+
if (!transparent) lastSig = "x";
|
|
625
914
|
} else {
|
|
915
|
+
if (!/\s/.test(c)) lastSig = c;
|
|
626
916
|
i++;
|
|
627
917
|
}
|
|
628
918
|
}
|
|
@@ -639,9 +929,26 @@ function firstCodeMatchIndex(code, pattern) {
|
|
|
639
929
|
}
|
|
640
930
|
return -1;
|
|
641
931
|
}
|
|
932
|
+
var REGEX_PRECEDING_KEYWORDS;
|
|
642
933
|
var init_source_scan = __esm({
|
|
643
934
|
"src/build/route-types/source-scan.ts"() {
|
|
644
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
|
+
]);
|
|
645
952
|
}
|
|
646
953
|
});
|
|
647
954
|
|
|
@@ -675,7 +982,10 @@ function countPublicRouteEntries(source) {
|
|
|
675
982
|
function isRoutableSourceFile(name) {
|
|
676
983
|
return (name.endsWith(".ts") || name.endsWith(".tsx") || name.endsWith(".js") || name.endsWith(".jsx")) && !name.includes(".gen.") && !name.includes(".test.") && !name.includes(".spec.");
|
|
677
984
|
}
|
|
678
|
-
function
|
|
985
|
+
function isExcludedScanDir(name) {
|
|
986
|
+
return name === "node_modules" || name === "dist" || name === "coverage" || name === "__tests__" || name === "__mocks__" || name.startsWith(".");
|
|
987
|
+
}
|
|
988
|
+
function findCallSiteFilesRecursive(dir, pattern, patternG, stopAtMatchDir, filter, results) {
|
|
679
989
|
let entries;
|
|
680
990
|
try {
|
|
681
991
|
entries = readdirSync2(dir, { withFileTypes: true });
|
|
@@ -686,32 +996,36 @@ function findRouterFilesRecursive(dir, filter, results) {
|
|
|
686
996
|
return;
|
|
687
997
|
}
|
|
688
998
|
const childDirs = [];
|
|
689
|
-
const
|
|
999
|
+
const matchesInDir = [];
|
|
690
1000
|
for (const entry of entries) {
|
|
691
1001
|
const fullPath = join2(dir, entry.name);
|
|
692
1002
|
if (entry.isDirectory()) {
|
|
693
|
-
if (entry.name
|
|
694
|
-
continue;
|
|
695
|
-
childDirs.push(fullPath);
|
|
1003
|
+
if (!isExcludedScanDir(entry.name)) childDirs.push(fullPath);
|
|
696
1004
|
continue;
|
|
697
1005
|
}
|
|
698
1006
|
if (!isRoutableSourceFile(entry.name)) continue;
|
|
699
1007
|
if (filter && !filter(fullPath)) continue;
|
|
700
1008
|
try {
|
|
701
1009
|
const source = readFileSync3(fullPath, "utf-8");
|
|
702
|
-
if (
|
|
703
|
-
|
|
1010
|
+
if (pattern.test(source) && firstCodeMatchIndex(source, patternG) >= 0) {
|
|
1011
|
+
matchesInDir.push(fullPath);
|
|
704
1012
|
}
|
|
705
1013
|
} catch {
|
|
706
1014
|
continue;
|
|
707
1015
|
}
|
|
708
1016
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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
|
+
}
|
|
715
1029
|
}
|
|
716
1030
|
}
|
|
717
1031
|
function findNestedRouterConflict(routerFiles) {
|
|
@@ -976,7 +1290,14 @@ function detectUnresolvableIncludesForUrlsFile(filePath) {
|
|
|
976
1290
|
}
|
|
977
1291
|
function findRouterFiles(root, filter) {
|
|
978
1292
|
const result = [];
|
|
979
|
-
|
|
1293
|
+
findCallSiteFilesRecursive(
|
|
1294
|
+
root,
|
|
1295
|
+
ROUTER_CALL_PATTERN,
|
|
1296
|
+
ROUTER_CALL_PATTERN_G,
|
|
1297
|
+
true,
|
|
1298
|
+
filter,
|
|
1299
|
+
result
|
|
1300
|
+
);
|
|
980
1301
|
return result;
|
|
981
1302
|
}
|
|
982
1303
|
function writeCombinedRouteTypes(root, knownRouterFiles, opts) {
|
|
@@ -1099,11 +1420,16 @@ async function initializeApp() {
|
|
|
1099
1420
|
createTemporaryReferenceSet,
|
|
1100
1421
|
};
|
|
1101
1422
|
|
|
1102
|
-
|
|
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 });
|
|
1103
1428
|
|
|
1429
|
+
const app = createElement(Rango);
|
|
1104
1430
|
hydrateRoot(
|
|
1105
1431
|
document,
|
|
1106
|
-
createElement(StrictMode, null,
|
|
1432
|
+
strictMode === false ? app : createElement(StrictMode, null, app)
|
|
1107
1433
|
);
|
|
1108
1434
|
}
|
|
1109
1435
|
|
|
@@ -1111,9 +1437,14 @@ initializeApp().catch(console.error);
|
|
|
1111
1437
|
`.trim();
|
|
1112
1438
|
VIRTUAL_ENTRY_SSR = `
|
|
1113
1439
|
import { createFromReadableStream } from "@rangojs/router/internal/deps/ssr";
|
|
1114
|
-
import { renderToReadableStream } from "react-dom/server.edge";
|
|
1440
|
+
import { renderToReadableStream, resume } from "react-dom/server.edge";
|
|
1441
|
+
import { prerender } from "react-dom/static.edge";
|
|
1115
1442
|
import { injectRSCPayload } from "@rangojs/router/internal/deps/html-stream-server";
|
|
1116
|
-
import {
|
|
1443
|
+
import {
|
|
1444
|
+
createSSRHandler,
|
|
1445
|
+
createShellCaptureHandler,
|
|
1446
|
+
createShellResumeHandler,
|
|
1447
|
+
} from "@rangojs/router/ssr";
|
|
1117
1448
|
|
|
1118
1449
|
export const renderHTML = createSSRHandler({
|
|
1119
1450
|
createFromReadableStream,
|
|
@@ -1122,6 +1453,26 @@ export const renderHTML = createSSRHandler({
|
|
|
1122
1453
|
loadBootstrapScriptContent: () =>
|
|
1123
1454
|
import.meta.viteRsc.loadBootstrapScriptContent("index"),
|
|
1124
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
|
+
});
|
|
1125
1476
|
`.trim();
|
|
1126
1477
|
VIRTUAL_IDS = {
|
|
1127
1478
|
browser: "virtual:rsc-router/entry.browser.js",
|
|
@@ -1132,13 +1483,37 @@ export const renderHTML = createSSRHandler({
|
|
|
1132
1483
|
}
|
|
1133
1484
|
});
|
|
1134
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
|
+
|
|
1135
1510
|
// src/vite/plugins/version-plugin.ts
|
|
1136
1511
|
var version_plugin_exports = {};
|
|
1137
1512
|
__export(version_plugin_exports, {
|
|
1138
1513
|
createVersionPlugin: () => createVersionPlugin,
|
|
1139
1514
|
isViteDepCachePath: () => isViteDepCachePath
|
|
1140
1515
|
});
|
|
1141
|
-
import { parseAst } from "vite";
|
|
1516
|
+
import { parseAst as parseAst2 } from "vite";
|
|
1142
1517
|
function isCodeModule(id) {
|
|
1143
1518
|
return /\.(tsx?|jsx?)($|\?)/.test(id);
|
|
1144
1519
|
}
|
|
@@ -1146,23 +1521,13 @@ function normalizeModuleId(id) {
|
|
|
1146
1521
|
return id.split("?", 1)[0];
|
|
1147
1522
|
}
|
|
1148
1523
|
function getClientModuleSignature(source) {
|
|
1524
|
+
if (!hasUseClientDirective(source)) return void 0;
|
|
1149
1525
|
let program;
|
|
1150
1526
|
try {
|
|
1151
|
-
program =
|
|
1527
|
+
program = parseAst2(source, { lang: "tsx" });
|
|
1152
1528
|
} catch {
|
|
1153
1529
|
return void 0;
|
|
1154
1530
|
}
|
|
1155
|
-
let isUseClient = false;
|
|
1156
|
-
for (const node of program.body ?? []) {
|
|
1157
|
-
if (node?.type === "ExpressionStatement" && node.expression?.type === "Literal" && typeof node.expression.value === "string") {
|
|
1158
|
-
if (node.expression.value === "use client") {
|
|
1159
|
-
isUseClient = true;
|
|
1160
|
-
}
|
|
1161
|
-
continue;
|
|
1162
|
-
}
|
|
1163
|
-
break;
|
|
1164
|
-
}
|
|
1165
|
-
if (!isUseClient) return void 0;
|
|
1166
1531
|
const exports = /* @__PURE__ */ new Set();
|
|
1167
1532
|
let hasDefault = false;
|
|
1168
1533
|
let hasExportAll = false;
|
|
@@ -1287,7 +1652,6 @@ function createVersionPlugin() {
|
|
|
1287
1652
|
}
|
|
1288
1653
|
return null;
|
|
1289
1654
|
},
|
|
1290
|
-
// Track RSC module changes and update version
|
|
1291
1655
|
async hotUpdate(ctx) {
|
|
1292
1656
|
if (!isDev) return;
|
|
1293
1657
|
const isRscModule = this.environment?.name === "rsc";
|
|
@@ -1337,6 +1701,7 @@ var init_version_plugin = __esm({
|
|
|
1337
1701
|
"src/vite/plugins/version-plugin.ts"() {
|
|
1338
1702
|
"use strict";
|
|
1339
1703
|
init_virtual_entries();
|
|
1704
|
+
init_directive_prologue();
|
|
1340
1705
|
}
|
|
1341
1706
|
});
|
|
1342
1707
|
|
|
@@ -1464,7 +1829,10 @@ async function discoverAndWriteRouteTypes(opts) {
|
|
|
1464
1829
|
let routerMountIndex = 0;
|
|
1465
1830
|
for (const [id, router] of registry) {
|
|
1466
1831
|
if (!router.urlpatterns) continue;
|
|
1467
|
-
const manifest = generateManifest(
|
|
1832
|
+
const manifest = await generateManifest(
|
|
1833
|
+
router.urlpatterns,
|
|
1834
|
+
routerMountIndex
|
|
1835
|
+
);
|
|
1468
1836
|
routerMountIndex++;
|
|
1469
1837
|
const rawManifest = manifest.routeManifest;
|
|
1470
1838
|
const routeManifest = {};
|