vinext 0.0.51 → 0.0.53
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/README.md +1 -1
- package/dist/build/clean-output.d.ts +14 -0
- package/dist/build/clean-output.js +36 -0
- package/dist/build/clean-output.js.map +1 -0
- package/dist/build/precompress.d.ts +7 -7
- package/dist/build/precompress.js +18 -17
- package/dist/build/precompress.js.map +1 -1
- package/dist/build/prerender.d.ts +9 -16
- package/dist/build/prerender.js +88 -50
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/run-prerender.js +10 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/static-export.d.ts +5 -0
- package/dist/build/static-export.js +8 -3
- package/dist/build/static-export.js.map +1 -1
- package/dist/check.js +4 -0
- package/dist/check.js.map +1 -1
- package/dist/cli-args.d.ts +1 -0
- package/dist/cli-args.js +5 -0
- package/dist/cli-args.js.map +1 -1
- package/dist/cli.js +58 -4
- package/dist/cli.js.map +1 -1
- package/dist/client/instrumentation-client-inject.d.ts +34 -0
- package/dist/client/instrumentation-client-inject.js +57 -0
- package/dist/client/instrumentation-client-inject.js.map +1 -0
- package/dist/client/navigation-runtime.d.ts +60 -0
- package/dist/client/navigation-runtime.js +171 -0
- package/dist/client/navigation-runtime.js.map +1 -0
- package/dist/client/pages-router-link-navigation.d.ts +26 -0
- package/dist/client/pages-router-link-navigation.js +14 -0
- package/dist/client/pages-router-link-navigation.js.map +1 -0
- package/dist/client/vinext-next-data.d.ts +14 -3
- package/dist/client/vinext-next-data.js +50 -1
- package/dist/client/vinext-next-data.js.map +1 -0
- package/dist/client/window-next.d.ts +10 -2
- package/dist/client/window-next.js.map +1 -1
- package/dist/cloudflare/kv-cache-handler.js +2 -1
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.d.ts +63 -16
- package/dist/config/config-matchers.js +145 -9
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +32 -5
- package/dist/config/next-config.js +55 -15
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +130 -46
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.js +9 -3
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +4 -2
- package/dist/entries/app-rsc-entry.js +76 -16
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +1 -0
- package/dist/entries/app-rsc-manifest.js +53 -6
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +3 -3
- package/dist/entries/app-ssr-entry.js +4 -4
- package/dist/entries/app-ssr-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.js +40 -3
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +261 -31
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +2 -1
- package/dist/entries/runtime-entry-module.js +9 -3
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +161 -46
- package/dist/index.js.map +1 -1
- package/dist/plugins/css-data-url.d.ts +7 -0
- package/dist/plugins/css-data-url.js +81 -0
- package/dist/plugins/css-data-url.js.map +1 -0
- package/dist/plugins/fonts.js +30 -5
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/middleware-server-only.d.ts +54 -0
- package/dist/plugins/middleware-server-only.js +91 -0
- package/dist/plugins/middleware-server-only.js.map +1 -0
- package/dist/plugins/optimize-imports.js +4 -4
- package/dist/plugins/optimize-imports.js.map +1 -1
- package/dist/plugins/strip-server-exports.js +5 -8
- package/dist/plugins/strip-server-exports.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +20 -1
- package/dist/routing/app-route-graph.js +58 -6
- package/dist/routing/app-route-graph.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -2
- package/dist/routing/app-router.js +2 -2
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/route-trie.js +13 -18
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/utils.d.ts +12 -1
- package/dist/routing/utils.js +18 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.js +153 -42
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-browser-action-result.d.ts +16 -1
- package/dist/server/app-browser-action-result.js +15 -1
- package/dist/server/app-browser-action-result.js.map +1 -1
- package/dist/server/app-browser-entry.js +309 -155
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-interception-context.d.ts +24 -0
- package/dist/server/app-browser-interception-context.js +32 -0
- package/dist/server/app-browser-interception-context.js.map +1 -0
- package/dist/server/app-browser-navigation-controller.d.ts +3 -1
- package/dist/server/app-browser-navigation-controller.js +5 -1
- package/dist/server/app-browser-navigation-controller.js.map +1 -1
- package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
- package/dist/server/app-browser-rsc-redirect.js +2 -2
- package/dist/server/app-browser-rsc-redirect.js.map +1 -1
- package/dist/server/app-browser-state.d.ts +18 -1
- package/dist/server/app-browser-state.js +19 -1
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-stream.d.ts +5 -14
- package/dist/server/app-browser-stream.js +13 -7
- package/dist/server/app-browser-stream.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +2 -1
- package/dist/server/app-browser-visible-commit.js +1 -0
- package/dist/server/app-browser-visible-commit.js.map +1 -1
- package/dist/server/app-elements-wire.d.ts +10 -5
- package/dist/server/app-elements-wire.js +84 -2
- package/dist/server/app-elements-wire.js.map +1 -1
- package/dist/server/app-elements.d.ts +3 -2
- package/dist/server/app-elements.js +3 -2
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.d.ts +12 -3
- package/dist/server/app-fallback-renderer.js +15 -8
- package/dist/server/app-fallback-renderer.js.map +1 -1
- package/dist/server/app-history-state.js +6 -2
- package/dist/server/app-history-state.js.map +1 -1
- package/dist/server/app-interception-context-header.d.ts +33 -0
- package/dist/server/app-interception-context-header.js +44 -0
- package/dist/server/app-interception-context-header.js.map +1 -0
- package/dist/server/app-middleware.d.ts +13 -0
- package/dist/server/app-middleware.js +3 -1
- package/dist/server/app-middleware.js.map +1 -1
- package/dist/server/app-mounted-slots-header.d.ts +19 -0
- package/dist/server/app-mounted-slots-header.js +40 -1
- package/dist/server/app-mounted-slots-header.js.map +1 -1
- package/dist/server/app-optimistic-routing.d.ts +54 -0
- package/dist/server/app-optimistic-routing.js +208 -0
- package/dist/server/app-optimistic-routing.js.map +1 -0
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +2 -0
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.d.ts +1 -0
- package/dist/server/app-page-boundary.js +2 -0
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +15 -1
- package/dist/server/app-page-cache.js +68 -7
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +5 -0
- package/dist/server/app-page-dispatch.js +39 -5
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +7 -3
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +29 -1
- package/dist/server/app-page-execution.js +91 -4
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.d.ts +1 -0
- package/dist/server/app-page-head.js +29 -2
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-probe.js +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.d.ts +3 -0
- package/dist/server/app-page-render.js +7 -3
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-response.d.ts +11 -1
- package/dist/server/app-page-response.js +18 -5
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +1 -0
- package/dist/server/app-page-route-wiring.js +35 -15
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +4 -0
- package/dist/server/app-page-stream.js +3 -0
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-prerender-static-params.d.ts +2 -1
- package/dist/server/app-prerender-static-params.js +44 -8
- package/dist/server/app-prerender-static-params.js.map +1 -1
- package/dist/server/app-route-handler-cache.d.ts +2 -2
- package/dist/server/app-route-handler-cache.js +3 -2
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +7 -1
- package/dist/server/app-route-handler-dispatch.js +4 -1
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +18 -2
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-response.js +6 -5
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-router-entry.js +6 -2
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-handler.d.ts +11 -1
- package/dist/server/app-rsc-handler.js +48 -21
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-render-mode.d.ts +4 -3
- package/dist/server/app-rsc-render-mode.js +7 -1
- package/dist/server/app-rsc-render-mode.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.d.ts +4 -1
- package/dist/server/app-rsc-request-normalization.js +6 -2
- package/dist/server/app-rsc-request-normalization.js.map +1 -1
- package/dist/server/app-rsc-response-finalizer.d.ts +8 -1
- package/dist/server/app-rsc-response-finalizer.js +10 -3
- package/dist/server/app-rsc-response-finalizer.js.map +1 -1
- package/dist/server/app-rsc-route-matching.js +2 -2
- package/dist/server/app-rsc-route-matching.js.map +1 -1
- package/dist/server/app-segment-config.d.ts +4 -1
- package/dist/server/app-segment-config.js +6 -1
- package/dist/server/app-segment-config.js.map +1 -1
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +5 -1
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.d.ts +2 -0
- package/dist/server/app-ssr-entry.js +92 -55
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +30 -2
- package/dist/server/app-ssr-stream.js +95 -8
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +2 -1
- package/dist/server/app-static-generation.js.map +1 -1
- package/dist/server/artifact-compatibility.d.ts +1 -1
- package/dist/server/artifact-compatibility.js.map +1 -1
- package/dist/server/cache-headers.d.ts +7 -0
- package/dist/server/cache-headers.js +19 -0
- package/dist/server/cache-headers.js.map +1 -0
- package/dist/server/cache-proof.d.ts +49 -3
- package/dist/server/cache-proof.js +78 -22
- package/dist/server/cache-proof.js.map +1 -1
- package/dist/server/client-reuse-manifest.d.ts +99 -0
- package/dist/server/client-reuse-manifest.js +212 -0
- package/dist/server/client-reuse-manifest.js.map +1 -0
- package/dist/server/default-global-error-module.d.ts +20 -0
- package/dist/server/default-global-error-module.js +20 -0
- package/dist/server/default-global-error-module.js.map +1 -0
- package/dist/server/default-not-found-module.d.ts +20 -0
- package/dist/server/default-not-found-module.js +20 -0
- package/dist/server/default-not-found-module.js.map +1 -0
- package/dist/server/dev-server.d.ts +10 -2
- package/dist/server/dev-server.js +99 -36
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/edge-api-runtime.d.ts +5 -0
- package/dist/server/edge-api-runtime.js +8 -0
- package/dist/server/edge-api-runtime.js.map +1 -0
- package/dist/server/headers.d.ts +22 -1
- package/dist/server/headers.js +22 -1
- package/dist/server/headers.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +16 -1
- package/dist/server/http-error-responses.js +21 -1
- package/dist/server/http-error-responses.js.map +1 -1
- package/dist/server/image-optimization.d.ts +13 -4
- package/dist/server/image-optimization.js +15 -4
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/isr-cache.d.ts +6 -2
- package/dist/server/isr-cache.js +20 -4
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/middleware-runtime.d.ts +15 -0
- package/dist/server/middleware-runtime.js +59 -7
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +5 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/navigation-planner.d.ts +9 -3
- package/dist/server/navigation-planner.js +98 -25
- package/dist/server/navigation-planner.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +2 -1
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/navigation-trace.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +45 -1
- package/dist/server/pages-api-route.js +27 -4
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-body-parser-config.d.ts +60 -0
- package/dist/server/pages-body-parser-config.js +79 -0
- package/dist/server/pages-body-parser-config.js.map +1 -0
- package/dist/server/pages-data-route.d.ts +77 -0
- package/dist/server/pages-data-route.js +98 -0
- package/dist/server/pages-data-route.js.map +1 -0
- package/dist/server/pages-default-404.d.ts +31 -0
- package/dist/server/pages-default-404.js +40 -0
- package/dist/server/pages-default-404.js.map +1 -0
- package/dist/server/pages-i18n.d.ts +51 -1
- package/dist/server/pages-i18n.js +61 -1
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/pages-node-compat.d.ts +10 -0
- package/dist/server/pages-node-compat.js +12 -1
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +69 -2
- package/dist/server/pages-page-data.js +47 -31
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +13 -1
- package/dist/server/pages-page-response.js +16 -11
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prerender-route-params.d.ts +14 -0
- package/dist/server/prerender-route-params.js +94 -0
- package/dist/server/prerender-route-params.js.map +1 -0
- package/dist/server/prod-server.d.ts +15 -37
- package/dist/server/prod-server.js +143 -107
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/proxy-trust.d.ts +41 -0
- package/dist/server/proxy-trust.js +70 -0
- package/dist/server/proxy-trust.js.map +1 -0
- package/dist/server/request-pipeline.d.ts +13 -4
- package/dist/server/request-pipeline.js +32 -14
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/seed-cache.d.ts +12 -31
- package/dist/server/seed-cache.js +30 -37
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/server/server-action-not-found.js +8 -3
- package/dist/server/server-action-not-found.js.map +1 -1
- package/dist/server/skip-cache-proof.d.ts +41 -0
- package/dist/server/skip-cache-proof.js +101 -0
- package/dist/server/skip-cache-proof.js.map +1 -0
- package/dist/server/static-file-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js +8 -7
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/server/streaming-metadata.d.ts +5 -0
- package/dist/server/streaming-metadata.js +10 -0
- package/dist/server/streaming-metadata.js.map +1 -0
- package/dist/shims/app-router-scroll-state.d.ts +12 -0
- package/dist/shims/app-router-scroll-state.js +38 -0
- package/dist/shims/app-router-scroll-state.js.map +1 -0
- package/dist/shims/app-router-scroll.d.ts +14 -0
- package/dist/shims/app-router-scroll.js +100 -0
- package/dist/shims/app-router-scroll.js.map +1 -0
- package/dist/shims/before-interactive-context.d.ts +30 -0
- package/dist/shims/before-interactive-context.js +10 -0
- package/dist/shims/before-interactive-context.js.map +1 -0
- package/dist/shims/cache-runtime.d.ts +1 -1
- package/dist/shims/cache-runtime.js +14 -1
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/client-locale.d.ts +15 -0
- package/dist/shims/client-locale.js +13 -0
- package/dist/shims/client-locale.js.map +1 -0
- package/dist/shims/default-global-error.d.ts +32 -0
- package/dist/shims/default-global-error.js +181 -0
- package/dist/shims/default-global-error.js.map +1 -0
- package/dist/shims/default-not-found.d.ts +12 -0
- package/dist/shims/default-not-found.js +61 -0
- package/dist/shims/default-not-found.js.map +1 -0
- package/dist/shims/document.d.ts +59 -3
- package/dist/shims/document.js +36 -5
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +2 -2
- package/dist/shims/font-local.d.ts +5 -0
- package/dist/shims/font-local.js +6 -2
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/form.js +13 -6
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/head.js +4 -4
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +6 -2
- package/dist/shims/headers.js +64 -21
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/image.d.ts +1 -1
- package/dist/shims/image.js +4 -4
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/pages-data-target.d.ts +58 -0
- package/dist/shims/internal/pages-data-target.js +91 -0
- package/dist/shims/internal/pages-data-target.js.map +1 -0
- package/dist/shims/internal/pages-data-url.d.ts +42 -0
- package/dist/shims/internal/pages-data-url.js +73 -0
- package/dist/shims/internal/pages-data-url.js.map +1 -0
- package/dist/shims/link.d.ts +21 -3
- package/dist/shims/link.js +189 -30
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +2 -1
- package/dist/shims/metadata.js +65 -6
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +8 -2
- package/dist/shims/navigation.js +67 -23
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +18 -2
- package/dist/shims/og.js +49 -1
- package/dist/shims/og.js.map +1 -0
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/root-params.d.ts +3 -1
- package/dist/shims/root-params.js +11 -3
- package/dist/shims/root-params.js.map +1 -1
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +12 -5
- package/dist/shims/router.js +535 -86
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.js +86 -12
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server.d.ts +21 -4
- package/dist/shims/server.js +30 -9
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.js +5 -1
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-safety.d.ts +23 -1
- package/dist/shims/url-safety.js +29 -2
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/shims/url-utils.d.ts +2 -1
- package/dist/shims/url-utils.js +15 -4
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/typegen.d.ts +10 -0
- package/dist/typegen.js +242 -0
- package/dist/typegen.js.map +1 -0
- package/dist/utils/asset-prefix.d.ts +33 -5
- package/dist/utils/asset-prefix.js +39 -6
- package/dist/utils/asset-prefix.js.map +1 -1
- package/dist/utils/cache-control-metadata.d.ts +2 -1
- package/dist/utils/cache-control-metadata.js +1 -3
- package/dist/utils/cache-control-metadata.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +2 -1
- package/dist/utils/domain-locale.js +9 -1
- package/dist/utils/domain-locale.js.map +1 -1
- package/dist/utils/html-limited-bots.d.ts +5 -0
- package/dist/utils/html-limited-bots.js +15 -0
- package/dist/utils/html-limited-bots.js.map +1 -0
- package/dist/utils/lazy-chunks.d.ts +1 -1
- package/dist/utils/lazy-chunks.js +1 -1
- package/dist/utils/lazy-chunks.js.map +1 -1
- package/dist/utils/prerender-output-paths.d.ts +15 -0
- package/dist/utils/prerender-output-paths.js +24 -0
- package/dist/utils/prerender-output-paths.js.map +1 -0
- package/dist/utils/query.d.ts +23 -1
- package/dist/utils/query.js +46 -2
- package/dist/utils/query.js.map +1 -1
- package/dist/utils/record.d.ts +5 -0
- package/dist/utils/record.js +8 -0
- package/dist/utils/record.js.map +1 -0
- package/package.json +11 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HasCondition, NextHeader, NextRedirect, NextRewrite } from "./next-config.js";
|
|
1
|
+
import { HasCondition, NextHeader, NextI18nConfig, NextRedirect, NextRewrite } from "./next-config.js";
|
|
2
2
|
|
|
3
3
|
//#region src/config/config-matchers.d.ts
|
|
4
4
|
/**
|
|
@@ -37,6 +37,28 @@ type RequestContext = {
|
|
|
37
37
|
query: URLSearchParams;
|
|
38
38
|
host: string;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* basePath gating state passed alongside the pathname to every matcher.
|
|
42
|
+
*
|
|
43
|
+
* Rewrites/redirects/headers run with default `basePath: true` semantics in
|
|
44
|
+
* Next.js: the rule only matches when the inbound request was under the
|
|
45
|
+
* configured `basePath`. Rules with `basePath: false` opt out and match
|
|
46
|
+
* the original (un-stripped) pathname regardless of prefix.
|
|
47
|
+
*
|
|
48
|
+
* When `basePath` is empty (not configured) every rule is treated as
|
|
49
|
+
* basePath-defaulted: every request matches.
|
|
50
|
+
*
|
|
51
|
+
* @see .nextjs-ref/packages/next/src/lib/load-custom-routes.ts:198-220
|
|
52
|
+
*/
|
|
53
|
+
type BasePathMatchState = {
|
|
54
|
+
/** Configured `basePath` (without trailing slash) or "" when unset. */basePath: string;
|
|
55
|
+
/**
|
|
56
|
+
* True when the inbound request was originally under `basePath` (i.e.
|
|
57
|
+
* the prod-server/handler stripped the prefix before the matcher runs).
|
|
58
|
+
* Ignored when `basePath` is empty.
|
|
59
|
+
*/
|
|
60
|
+
hadBasePath: boolean;
|
|
61
|
+
};
|
|
40
62
|
/**
|
|
41
63
|
* Parse a Cookie header string into a key-value record.
|
|
42
64
|
*/
|
|
@@ -70,17 +92,6 @@ declare function applyMiddlewareRequestHeaders(middlewareHeaders: Record<string,
|
|
|
70
92
|
postMwReqCtx: RequestContext;
|
|
71
93
|
};
|
|
72
94
|
declare function checkHasConditions(has: HasCondition[] | undefined, missing: HasCondition[] | undefined, ctx: RequestContext): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Match a Next.js config pattern (from redirects/rewrites sources) against a pathname.
|
|
75
|
-
* Returns matched params or null.
|
|
76
|
-
*
|
|
77
|
-
* Supports:
|
|
78
|
-
* :param - matches a single path segment
|
|
79
|
-
* :param* - matches zero or more segments (catch-all)
|
|
80
|
-
* :param+ - matches one or more segments
|
|
81
|
-
* (regex) - inline regex patterns in the source
|
|
82
|
-
* :param(constraint) - named param with inline regex constraint
|
|
83
|
-
*/
|
|
84
95
|
declare function matchConfigPattern(pathname: string, pattern: string): Record<string, string> | null;
|
|
85
96
|
/**
|
|
86
97
|
* Apply redirect rules from next.config.js.
|
|
@@ -117,7 +128,7 @@ declare function matchConfigPattern(pathname: string, pattern: string): Record<s
|
|
|
117
128
|
* an original index < N are checked via matchConfigPattern first — they are
|
|
118
129
|
* few in practice (typically zero) so this is not a hot-path concern.
|
|
119
130
|
*/
|
|
120
|
-
declare function matchRedirect(pathname: string, redirects: NextRedirect[], ctx: RequestContext): {
|
|
131
|
+
declare function matchRedirect(pathname: string, redirects: NextRedirect[], ctx: RequestContext, basePathState?: BasePathMatchState): {
|
|
121
132
|
destination: string;
|
|
122
133
|
permanent: boolean;
|
|
123
134
|
} | null;
|
|
@@ -129,7 +140,7 @@ declare function matchRedirect(pathname: string, redirects: NextRedirect[], ctx:
|
|
|
129
140
|
* to evaluate has/missing conditions. Next.js always has request context
|
|
130
141
|
* when evaluating rewrites, so this parameter is required.
|
|
131
142
|
*/
|
|
132
|
-
declare function matchRewrite(pathname: string, rewrites: NextRewrite[], ctx: RequestContext): string | null;
|
|
143
|
+
declare function matchRewrite(pathname: string, rewrites: NextRewrite[], ctx: RequestContext, basePathState?: BasePathMatchState): string | null;
|
|
133
144
|
/**
|
|
134
145
|
* Sanitize a redirect/rewrite destination to collapse protocol-relative URLs.
|
|
135
146
|
*
|
|
@@ -166,10 +177,46 @@ declare function proxyExternalRequest(request: Request, externalUrl: string): Pr
|
|
|
166
177
|
* to evaluate has/missing conditions. Next.js always has request context
|
|
167
178
|
* when evaluating headers, so this parameter is required.
|
|
168
179
|
*/
|
|
169
|
-
declare function matchHeaders(pathname: string, headers: NextHeader[], ctx: RequestContext): Array<{
|
|
180
|
+
declare function matchHeaders(pathname: string, headers: NextHeader[], ctx: RequestContext, basePathState?: BasePathMatchState): Array<{
|
|
170
181
|
key: string;
|
|
171
182
|
value: string;
|
|
172
183
|
}>;
|
|
184
|
+
/**
|
|
185
|
+
* Apply Next.js i18n locale-prefix transformation to a set of redirect or
|
|
186
|
+
* rewrite rules. Mirrors the relevant slice of Next.js's `processRoutes`
|
|
187
|
+
* (load-custom-routes.ts) with one deliberate divergence noted below.
|
|
188
|
+
*
|
|
189
|
+
* For each rule:
|
|
190
|
+
* - If `locale === false` or no i18n is configured, the rule is emitted
|
|
191
|
+
* untouched. This is the core of issue #1336 item 1: with `locale: false`
|
|
192
|
+
* the user-supplied source is matched against the raw locale-prefixed
|
|
193
|
+
* URL so a `:locale` segment in the source captures the prefix itself.
|
|
194
|
+
* - Otherwise an internal locale-capture variant is produced whose source
|
|
195
|
+
* starts with `/:nextInternalLocale(en|sv|nl)` so that locale-prefixed
|
|
196
|
+
* URLs match. For redirects only, a second variant prefixed with
|
|
197
|
+
* `/${defaultLocale}` is also emitted, matching Next.js exactly.
|
|
198
|
+
* - **Vinext divergence**: we ALSO retain the original (unprefixed) source
|
|
199
|
+
* so that requests for the default locale that arrive without a prefix
|
|
200
|
+
* still match. Next.js solves this upstream by path-normalising every
|
|
201
|
+
* incoming default-locale request to include the prefix
|
|
202
|
+
* (`resolve-routes.ts` lines ~251-263); vinext currently does that
|
|
203
|
+
* normalisation only inside the pages-server-entry route matcher, so
|
|
204
|
+
* the rewrite/redirect matcher would otherwise miss unprefixed paths.
|
|
205
|
+
* Keeping the unprefixed variant gives functionally identical behaviour
|
|
206
|
+
* without requiring a server-wide path normalisation pass. The original
|
|
207
|
+
* source is appended LAST so the locale-aware variants win when both
|
|
208
|
+
* forms could match.
|
|
209
|
+
*
|
|
210
|
+
* Destinations that are local (start with `/`) are similarly rewritten with
|
|
211
|
+
* `/:nextInternalLocale` for the locale-capture variant so the locale
|
|
212
|
+
* survives the rewrite/redirect target.
|
|
213
|
+
*
|
|
214
|
+
* Mirrors the Next.js reference in
|
|
215
|
+
* packages/next/src/lib/load-custom-routes.ts — see `processRoutes`.
|
|
216
|
+
*/
|
|
217
|
+
declare function applyLocaleToRoutes<T extends NextRedirect | NextRewrite>(routes: T[], i18n: NextI18nConfig | null | undefined, type: "redirect" | "rewrite", options?: {
|
|
218
|
+
trailingSlash?: boolean;
|
|
219
|
+
}): T[];
|
|
173
220
|
//#endregion
|
|
174
|
-
export { RequestContext, applyMiddlewareRequestHeaders, checkHasConditions, escapeHeaderSource, isExternalUrl, isSafeRegex, matchConfigPattern, matchHeaders, matchRedirect, matchRewrite, normalizeHost, parseCookies, proxyExternalRequest, requestContextFromRequest, safeRegExp, sanitizeDestination };
|
|
221
|
+
export { BasePathMatchState, RequestContext, applyLocaleToRoutes, applyMiddlewareRequestHeaders, checkHasConditions, escapeHeaderSource, isExternalUrl, isSafeRegex, matchConfigPattern, matchHeaders, matchRedirect, matchRewrite, normalizeHost, parseCookies, proxyExternalRequest, requestContextFromRequest, safeRegExp, sanitizeDestination };
|
|
175
222
|
//# sourceMappingURL=config-matchers.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_SECRET_HEADER } from "../server/headers.js";
|
|
1
|
+
import { VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER } from "../server/headers.js";
|
|
2
2
|
import { buildRequestHeadersFromMiddlewareResponse } from "../server/middleware-request-headers.js";
|
|
3
3
|
//#region src/config/config-matchers.ts
|
|
4
4
|
/**
|
|
@@ -99,8 +99,18 @@ function getCachedRegex(cache, key, compile) {
|
|
|
99
99
|
* locale-static fast-path match is found, any linear rules that appear earlier
|
|
100
100
|
* in the array are still checked first.
|
|
101
101
|
*/
|
|
102
|
-
/**
|
|
103
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Matches `/:param(alternation)?/static/suffix` — the locale-static pattern.
|
|
104
|
+
*
|
|
105
|
+
* The `?` after the capture group is itself optional so that both forms are
|
|
106
|
+
* detected:
|
|
107
|
+
* - `/:locale(en|fr)?/foo` (locale segment optional — user-written rules)
|
|
108
|
+
* - `/:nextInternalLocale(en|fr)/foo` (locale segment mandatory — emitted
|
|
109
|
+
* by `applyLocaleToRoutes` for the locale-capture variant)
|
|
110
|
+
* Both forms benefit from O(1) suffix lookup; the optionality is recorded
|
|
111
|
+
* on the entry so we know whether to try the no-locale-prefix bucket.
|
|
112
|
+
*/
|
|
113
|
+
const _LOCALE_STATIC_RE = /^\/:[\w-]+\(([^)]+)\)(\??)\/([a-zA-Z0-9_~.%@!$&'*+,;=:/-]+)$/;
|
|
104
114
|
const _redirectIndexCache = /* @__PURE__ */ new WeakMap();
|
|
105
115
|
/**
|
|
106
116
|
* Build (or retrieve from cache) the redirect index for a given redirects array.
|
|
@@ -120,7 +130,8 @@ function _getRedirectIndex(redirects) {
|
|
|
120
130
|
if (m) {
|
|
121
131
|
const paramName = redirect.source.slice(2, redirect.source.indexOf("("));
|
|
122
132
|
const alternation = m[1];
|
|
123
|
-
const
|
|
133
|
+
const optional = m[2] === "?";
|
|
134
|
+
const suffix = "/" + m[3];
|
|
124
135
|
const altRe = safeRegExp("^(?:" + alternation + ")$");
|
|
125
136
|
if (!altRe) {
|
|
126
137
|
linear.push([i, redirect]);
|
|
@@ -129,6 +140,7 @@ function _getRedirectIndex(redirects) {
|
|
|
129
140
|
const entry = {
|
|
130
141
|
paramName,
|
|
131
142
|
altRe,
|
|
143
|
+
optional,
|
|
132
144
|
redirect,
|
|
133
145
|
originalIndex: i
|
|
134
146
|
};
|
|
@@ -307,6 +319,26 @@ function escapeHeaderSource(source) {
|
|
|
307
319
|
}
|
|
308
320
|
return result;
|
|
309
321
|
}
|
|
322
|
+
const _BASEPATH_DEFAULT = {
|
|
323
|
+
basePath: "",
|
|
324
|
+
hadBasePath: true
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Decide whether a rule should be evaluated at all given the current
|
|
328
|
+
* basePath-gating state.
|
|
329
|
+
*
|
|
330
|
+
* Encodes the Next.js rules:
|
|
331
|
+
* - basePath: false rule → only when the request was NOT under basePath
|
|
332
|
+
* (i.e. it's the explicit opt-out path). When `basePath` itself is
|
|
333
|
+
* empty, basePath: false rules are still allowed to match — there's
|
|
334
|
+
* just no basePath to gate them.
|
|
335
|
+
* - default rule (basePath !== false) → only when the request WAS under
|
|
336
|
+
* basePath (or no basePath is configured).
|
|
337
|
+
*/
|
|
338
|
+
function shouldEvaluateRule(ruleBasePath, state) {
|
|
339
|
+
if (!state.basePath) return true;
|
|
340
|
+
return ruleBasePath === false ? !state.hadBasePath : state.hadBasePath;
|
|
341
|
+
}
|
|
310
342
|
/**
|
|
311
343
|
* Parse a Cookie header string into a key-value record.
|
|
312
344
|
*/
|
|
@@ -472,8 +504,31 @@ function extractConstraint(str, re) {
|
|
|
472
504
|
* (regex) - inline regex patterns in the source
|
|
473
505
|
* :param(constraint) - named param with inline regex constraint
|
|
474
506
|
*/
|
|
507
|
+
/**
|
|
508
|
+
* Strip a single trailing slash from a pathname for config-source matching.
|
|
509
|
+
*
|
|
510
|
+
* Next.js conditionally appends `(/)?` to rewrite/redirect/header source
|
|
511
|
+
* regexes when `trailingSlash: true` (see Next.js
|
|
512
|
+
* `resolve-rewrites.ts` and `server-utils.ts:checkRewrite`). Rather than
|
|
513
|
+
* threading the trailingSlash flag through every matcher, we unconditionally
|
|
514
|
+
* strip a trailing slash from the incoming pathname. When `trailingSlash: false`
|
|
515
|
+
* the request pipeline emits a normalizing redirect (step 3) before config
|
|
516
|
+
* rewrites/redirects (step 6) ever run, so the pathname is already slash-free;
|
|
517
|
+
* the unconditional strip is defense-in-depth for that ordering. When
|
|
518
|
+
* `trailingSlash: true` it bridges the gap between the canonicalized request
|
|
519
|
+
* path (`/rewrite-1/`) and source patterns written without a trailing slash
|
|
520
|
+
* (`/rewrite-1`).
|
|
521
|
+
*
|
|
522
|
+
* The root path `"/"` is preserved as-is.
|
|
523
|
+
*/
|
|
524
|
+
function stripTrailingSlashForConfigMatch(pathname) {
|
|
525
|
+
return pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
|
|
526
|
+
}
|
|
475
527
|
function matchConfigPattern(pathname, pattern) {
|
|
476
|
-
|
|
528
|
+
pathname = stripTrailingSlashForConfigMatch(pathname);
|
|
529
|
+
const catchAllAnchor = /:[\w-]+[*+]/.test(pattern);
|
|
530
|
+
const namedParamCount = (pattern.match(/:[\w-]+/g) || []).length;
|
|
531
|
+
if (pattern.includes("(") || pattern.includes("\\") || /:[\w-]+[*+][^/]/.test(pattern) || /:[\w-]+\./.test(pattern) || catchAllAnchor && namedParamCount > 1) try {
|
|
477
532
|
const compiled = getCachedRegex(_compiledPatternCache, pattern, () => {
|
|
478
533
|
const paramNames = [];
|
|
479
534
|
let regexStr = "";
|
|
@@ -566,16 +621,19 @@ function matchConfigPattern(pathname, pattern) {
|
|
|
566
621
|
* an original index < N are checked via matchConfigPattern first — they are
|
|
567
622
|
* few in practice (typically zero) so this is not a hot-path concern.
|
|
568
623
|
*/
|
|
569
|
-
function matchRedirect(pathname, redirects, ctx) {
|
|
624
|
+
function matchRedirect(pathname, redirects, ctx, basePathState = _BASEPATH_DEFAULT) {
|
|
570
625
|
if (redirects.length === 0) return null;
|
|
626
|
+
pathname = stripTrailingSlashForConfigMatch(pathname);
|
|
571
627
|
const index = _getRedirectIndex(redirects);
|
|
572
628
|
let localeMatch = null;
|
|
573
629
|
let localeMatchIndex = Infinity;
|
|
574
630
|
if (index.localeStatic.size > 0) {
|
|
575
631
|
const noLocaleBucket = index.localeStatic.get(pathname);
|
|
576
632
|
if (noLocaleBucket) for (const entry of noLocaleBucket) {
|
|
633
|
+
if (!entry.optional) continue;
|
|
577
634
|
if (entry.originalIndex >= localeMatchIndex) continue;
|
|
578
635
|
const redirect = entry.redirect;
|
|
636
|
+
if (!shouldEvaluateRule(redirect.basePath, basePathState)) continue;
|
|
579
637
|
const conditionParams = redirect.has || redirect.missing ? collectConditionParams(redirect.has, redirect.missing, ctx) : _emptyParams();
|
|
580
638
|
if (!conditionParams) continue;
|
|
581
639
|
localeMatch = {
|
|
@@ -597,6 +655,7 @@ function matchRedirect(pathname, redirects, ctx) {
|
|
|
597
655
|
if (entry.originalIndex >= localeMatchIndex) continue;
|
|
598
656
|
if (!entry.altRe.test(localePart)) continue;
|
|
599
657
|
const redirect = entry.redirect;
|
|
658
|
+
if (!shouldEvaluateRule(redirect.basePath, basePathState)) continue;
|
|
600
659
|
const conditionParams = redirect.has || redirect.missing ? collectConditionParams(redirect.has, redirect.missing, ctx) : _emptyParams();
|
|
601
660
|
if (!conditionParams) continue;
|
|
602
661
|
localeMatch = {
|
|
@@ -613,6 +672,7 @@ function matchRedirect(pathname, redirects, ctx) {
|
|
|
613
672
|
}
|
|
614
673
|
for (const [origIdx, redirect] of index.linear) {
|
|
615
674
|
if (origIdx >= localeMatchIndex) break;
|
|
675
|
+
if (!shouldEvaluateRule(redirect.basePath, basePathState)) continue;
|
|
616
676
|
const params = matchConfigPattern(pathname, redirect.source);
|
|
617
677
|
if (params) {
|
|
618
678
|
const conditionParams = redirect.has || redirect.missing ? collectConditionParams(redirect.has, redirect.missing, ctx) : _emptyParams();
|
|
@@ -636,8 +696,9 @@ function matchRedirect(pathname, redirects, ctx) {
|
|
|
636
696
|
* to evaluate has/missing conditions. Next.js always has request context
|
|
637
697
|
* when evaluating rewrites, so this parameter is required.
|
|
638
698
|
*/
|
|
639
|
-
function matchRewrite(pathname, rewrites, ctx) {
|
|
699
|
+
function matchRewrite(pathname, rewrites, ctx, basePathState = _BASEPATH_DEFAULT) {
|
|
640
700
|
for (const rewrite of rewrites) {
|
|
701
|
+
if (!shouldEvaluateRule(rewrite.basePath, basePathState)) continue;
|
|
641
702
|
const params = matchConfigPattern(pathname, rewrite.source);
|
|
642
703
|
if (params) {
|
|
643
704
|
const conditionParams = rewrite.has || rewrite.missing ? collectConditionParams(rewrite.has, rewrite.missing, ctx) : _emptyParams();
|
|
@@ -723,6 +784,7 @@ async function proxyExternalRequest(request, externalUrl) {
|
|
|
723
784
|
for (const key of headers.keys()) if (key.startsWith("x-middleware-")) keysToDelete.push(key);
|
|
724
785
|
for (const key of keysToDelete) headers.delete(key);
|
|
725
786
|
headers.delete(VINEXT_PRERENDER_SECRET_HEADER);
|
|
787
|
+
headers.delete(VINEXT_PRERENDER_ROUTE_PARAMS_HEADER);
|
|
726
788
|
headers.delete(VINEXT_MW_CTX_HEADER);
|
|
727
789
|
const method = request.method;
|
|
728
790
|
const hasBody = method !== "GET" && method !== "HEAD";
|
|
@@ -775,9 +837,11 @@ async function proxyExternalRequest(request, externalUrl) {
|
|
|
775
837
|
* to evaluate has/missing conditions. Next.js always has request context
|
|
776
838
|
* when evaluating headers, so this parameter is required.
|
|
777
839
|
*/
|
|
778
|
-
function matchHeaders(pathname, headers, ctx) {
|
|
840
|
+
function matchHeaders(pathname, headers, ctx, basePathState = _BASEPATH_DEFAULT) {
|
|
841
|
+
pathname = stripTrailingSlashForConfigMatch(pathname);
|
|
779
842
|
const result = [];
|
|
780
843
|
for (const rule of headers) {
|
|
844
|
+
if (!shouldEvaluateRule(rule.basePath, basePathState)) continue;
|
|
781
845
|
const sourceRegex = getCachedRegex(_compiledHeaderSourceCache, rule.source, () => safeRegExp("^" + escapeHeaderSource(rule.source) + "$"));
|
|
782
846
|
if (sourceRegex && sourceRegex.test(pathname)) {
|
|
783
847
|
if (rule.has || rule.missing) {
|
|
@@ -788,7 +852,79 @@ function matchHeaders(pathname, headers, ctx) {
|
|
|
788
852
|
}
|
|
789
853
|
return result;
|
|
790
854
|
}
|
|
855
|
+
/**
|
|
856
|
+
* Escape a string for inclusion in a regex character class / alternation.
|
|
857
|
+
* Mirrors `escape-string-regexp` semantics used by Next.js's processRoutes.
|
|
858
|
+
*/
|
|
859
|
+
function _escapeRegexString(value) {
|
|
860
|
+
return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Apply Next.js i18n locale-prefix transformation to a set of redirect or
|
|
864
|
+
* rewrite rules. Mirrors the relevant slice of Next.js's `processRoutes`
|
|
865
|
+
* (load-custom-routes.ts) with one deliberate divergence noted below.
|
|
866
|
+
*
|
|
867
|
+
* For each rule:
|
|
868
|
+
* - If `locale === false` or no i18n is configured, the rule is emitted
|
|
869
|
+
* untouched. This is the core of issue #1336 item 1: with `locale: false`
|
|
870
|
+
* the user-supplied source is matched against the raw locale-prefixed
|
|
871
|
+
* URL so a `:locale` segment in the source captures the prefix itself.
|
|
872
|
+
* - Otherwise an internal locale-capture variant is produced whose source
|
|
873
|
+
* starts with `/:nextInternalLocale(en|sv|nl)` so that locale-prefixed
|
|
874
|
+
* URLs match. For redirects only, a second variant prefixed with
|
|
875
|
+
* `/${defaultLocale}` is also emitted, matching Next.js exactly.
|
|
876
|
+
* - **Vinext divergence**: we ALSO retain the original (unprefixed) source
|
|
877
|
+
* so that requests for the default locale that arrive without a prefix
|
|
878
|
+
* still match. Next.js solves this upstream by path-normalising every
|
|
879
|
+
* incoming default-locale request to include the prefix
|
|
880
|
+
* (`resolve-routes.ts` lines ~251-263); vinext currently does that
|
|
881
|
+
* normalisation only inside the pages-server-entry route matcher, so
|
|
882
|
+
* the rewrite/redirect matcher would otherwise miss unprefixed paths.
|
|
883
|
+
* Keeping the unprefixed variant gives functionally identical behaviour
|
|
884
|
+
* without requiring a server-wide path normalisation pass. The original
|
|
885
|
+
* source is appended LAST so the locale-aware variants win when both
|
|
886
|
+
* forms could match.
|
|
887
|
+
*
|
|
888
|
+
* Destinations that are local (start with `/`) are similarly rewritten with
|
|
889
|
+
* `/:nextInternalLocale` for the locale-capture variant so the locale
|
|
890
|
+
* survives the rewrite/redirect target.
|
|
891
|
+
*
|
|
892
|
+
* Mirrors the Next.js reference in
|
|
893
|
+
* packages/next/src/lib/load-custom-routes.ts — see `processRoutes`.
|
|
894
|
+
*/
|
|
895
|
+
function applyLocaleToRoutes(routes, i18n, type, options = {}) {
|
|
896
|
+
if (!i18n || routes.length === 0) return routes;
|
|
897
|
+
const trailingSlash = options.trailingSlash ?? false;
|
|
898
|
+
const internalLocale = `/:nextInternalLocale(${i18n.locales.map(_escapeRegexString).join("|")})`;
|
|
899
|
+
const suffixFor = (source) => source === "/" && !trailingSlash ? "" : source;
|
|
900
|
+
const defaultLocales = type === "redirect" ? [i18n.defaultLocale] : [];
|
|
901
|
+
const out = [];
|
|
902
|
+
for (const r of routes) {
|
|
903
|
+
if (r.locale === false) {
|
|
904
|
+
out.push(r);
|
|
905
|
+
continue;
|
|
906
|
+
}
|
|
907
|
+
const isExternal = !!r.destination && !r.destination.startsWith("/");
|
|
908
|
+
if (!isExternal) for (const locale of defaultLocales) {
|
|
909
|
+
const localizedSource = `/${locale}${suffixFor(r.source)}`;
|
|
910
|
+
out.push({
|
|
911
|
+
...r,
|
|
912
|
+
source: localizedSource
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
const internalSource = `${internalLocale}${suffixFor(r.source)}`;
|
|
916
|
+
let internalDestination = r.destination;
|
|
917
|
+
if (internalDestination && internalDestination.startsWith("/") && !isExternal) internalDestination = `/:nextInternalLocale${internalDestination === "/" && !trailingSlash ? "" : internalDestination}`;
|
|
918
|
+
out.push({
|
|
919
|
+
...r,
|
|
920
|
+
source: internalSource,
|
|
921
|
+
destination: internalDestination
|
|
922
|
+
});
|
|
923
|
+
out.push(r);
|
|
924
|
+
}
|
|
925
|
+
return out;
|
|
926
|
+
}
|
|
791
927
|
//#endregion
|
|
792
|
-
export { applyMiddlewareRequestHeaders, checkHasConditions, escapeHeaderSource, isExternalUrl, isSafeRegex, matchConfigPattern, matchHeaders, matchRedirect, matchRewrite, normalizeHost, parseCookies, proxyExternalRequest, requestContextFromRequest, safeRegExp, sanitizeDestination };
|
|
928
|
+
export { applyLocaleToRoutes, applyMiddlewareRequestHeaders, checkHasConditions, escapeHeaderSource, isExternalUrl, isSafeRegex, matchConfigPattern, matchHeaders, matchRedirect, matchRewrite, normalizeHost, parseCookies, proxyExternalRequest, requestContextFromRequest, safeRegExp, sanitizeDestination };
|
|
793
929
|
|
|
794
930
|
//# sourceMappingURL=config-matchers.js.map
|