astro 5.16.5 → 6.0.0-alpha.1
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/{astro.js → bin/astro.mjs} +7 -8
- package/client.d.ts +19 -45
- package/components/ClientRouter.astro +0 -5
- package/components/Code.astro +2 -2
- package/components/Image.astro +2 -2
- package/components/Picture.astro +1 -1
- package/dist/actions/consts.d.ts +2 -5
- package/dist/actions/consts.js +4 -8
- package/dist/actions/integration.js +2 -4
- package/dist/actions/runtime/client.d.ts +84 -3
- package/dist/actions/runtime/client.js +238 -7
- package/dist/actions/runtime/entrypoints/client.d.ts +7 -0
- package/dist/actions/runtime/entrypoints/client.js +91 -0
- package/dist/actions/runtime/entrypoints/route.d.ts +2 -0
- package/dist/actions/runtime/{route.js → entrypoints/route.js} +1 -1
- package/dist/actions/runtime/entrypoints/server.d.ts +6 -0
- package/dist/actions/runtime/entrypoints/server.js +33 -0
- package/dist/actions/runtime/server.d.ts +11 -29
- package/dist/actions/runtime/server.js +162 -82
- package/dist/actions/runtime/types.d.ts +64 -0
- package/dist/actions/runtime/types.js +0 -0
- package/dist/actions/utils.d.ts +2 -2
- package/dist/actions/utils.js +2 -2
- package/dist/actions/vite-plugin-actions.js +18 -21
- package/dist/assets/build/generate.d.ts +2 -2
- package/dist/assets/build/generate.js +11 -9
- package/dist/assets/build/remote.js +4 -14
- package/dist/assets/endpoint/config.js +2 -2
- package/dist/assets/endpoint/dev.js +7 -6
- package/dist/assets/fonts/config.d.ts +86 -174
- package/dist/assets/fonts/config.js +15 -17
- package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.d.ts +3 -3
- package/dist/assets/fonts/infra/dev-remote-font-provider-mod-resolver.js +4 -4
- package/dist/assets/fonts/types.d.ts +1 -1
- package/dist/assets/fonts/vite-plugin-fonts.js +6 -3
- package/dist/assets/services/sharp.js +5 -6
- package/dist/assets/utils/index.d.ts +0 -6
- package/dist/assets/utils/index.js +0 -9
- package/dist/assets/utils/{transformToPath.d.ts → node.d.ts} +15 -1
- package/dist/assets/utils/{node/emitAsset.js → node.js} +34 -56
- package/dist/assets/vite-plugin-assets.js +9 -14
- package/dist/cli/index.js +0 -2
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/cli/preferences/index.js +5 -1
- package/dist/config/index.js +11 -16
- package/dist/container/index.d.ts +0 -1
- package/dist/container/index.js +19 -14
- package/dist/container/pipeline.d.ts +2 -1
- package/dist/container/pipeline.js +4 -11
- package/dist/content/config.d.ts +34 -40
- package/dist/content/config.js +17 -13
- package/dist/content/content-layer.js +14 -21
- package/dist/content/data-store.d.ts +0 -2
- package/dist/content/loaders/errors.d.ts +3 -3
- package/dist/content/loaders/errors.js +5 -2
- package/dist/content/loaders/glob.d.ts +0 -5
- package/dist/content/loaders/glob.js +3 -30
- package/dist/content/loaders/types.d.ts +11 -4
- package/dist/content/mutable-data-store.js +1 -14
- package/dist/content/runtime-assets.d.ts +4 -4
- package/dist/content/runtime-assets.js +4 -7
- package/dist/content/runtime.d.ts +35 -73
- package/dist/content/runtime.js +63 -231
- package/dist/content/server-listeners.js +25 -88
- package/dist/content/types-generator.d.ts +1 -6
- package/dist/content/types-generator.js +87 -156
- package/dist/content/utils.d.ts +47 -412
- package/dist/content/utils.js +88 -203
- package/dist/content/vite-plugin-content-assets.d.ts +12 -4
- package/dist/content/vite-plugin-content-assets.js +100 -56
- package/dist/content/vite-plugin-content-imports.js +10 -8
- package/dist/content/vite-plugin-content-virtual-mod.js +13 -131
- package/dist/core/app/app.d.ts +5 -0
- package/dist/core/app/app.js +13 -0
- package/dist/core/app/base.d.ts +132 -0
- package/dist/core/app/base.js +448 -0
- package/dist/core/app/common.d.ts +6 -2
- package/dist/core/app/common.js +60 -33
- package/dist/core/app/dev/app.d.ts +15 -0
- package/dist/core/app/dev/app.js +86 -0
- package/dist/core/app/dev/pipeline.d.ts +13 -0
- package/dist/core/app/dev/pipeline.js +123 -0
- package/dist/core/app/entrypoint.d.ts +2 -0
- package/dist/core/app/entrypoint.js +15 -0
- package/dist/core/app/index.d.ts +7 -114
- package/dist/core/app/index.js +20 -557
- package/dist/core/app/logging.d.ts +3 -0
- package/dist/core/app/logging.js +11 -0
- package/dist/core/app/manifest.d.ts +9 -0
- package/dist/core/app/manifest.js +107 -0
- package/dist/core/app/middlewares.js +1 -1
- package/dist/core/app/node.d.ts +2 -8
- package/dist/core/app/node.js +8 -9
- package/dist/core/app/pipeline.d.ts +6 -5
- package/dist/core/app/pipeline.js +65 -49
- package/dist/core/app/types.d.ts +58 -22
- package/dist/core/app/validate-forwarded-headers.d.ts +16 -0
- package/dist/core/app/validate-forwarded-headers.js +60 -0
- package/dist/core/base-pipeline.d.ts +22 -14
- package/dist/core/base-pipeline.js +54 -6
- package/dist/core/build/app.d.ts +13 -0
- package/dist/core/build/app.js +38 -0
- package/dist/core/build/common.d.ts +1 -1
- package/dist/core/build/common.js +2 -2
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +95 -204
- package/dist/core/build/graph.js +2 -2
- package/dist/core/build/index.js +11 -19
- package/dist/core/build/internal.d.ts +3 -29
- package/dist/core/build/internal.js +1 -45
- package/dist/core/build/pipeline.d.ts +15 -26
- package/dist/core/build/pipeline.js +106 -170
- package/dist/core/build/plugins/index.d.ts +4 -2
- package/dist/core/build/plugins/index.js +17 -23
- package/dist/core/build/plugins/plugin-analyzer.d.ts +2 -2
- package/dist/core/build/plugins/plugin-analyzer.js +5 -13
- package/dist/core/build/plugins/plugin-component-entry.d.ts +7 -2
- package/dist/core/build/plugins/plugin-component-entry.js +5 -13
- package/dist/core/build/plugins/plugin-css.d.ts +2 -2
- package/dist/core/build/plugins/plugin-css.js +86 -41
- package/dist/core/build/plugins/plugin-internals.d.ts +2 -2
- package/dist/core/build/plugins/plugin-internals.js +24 -18
- package/dist/core/build/plugins/plugin-manifest.d.ts +33 -5
- package/dist/core/build/plugins/plugin-manifest.js +89 -131
- package/dist/core/build/plugins/plugin-middleware.d.ts +2 -2
- package/dist/core/build/plugins/plugin-middleware.js +5 -7
- package/dist/core/build/plugins/plugin-noop.d.ts +3 -0
- package/dist/core/build/plugins/plugin-noop.js +29 -0
- package/dist/core/build/plugins/plugin-prerender.d.ts +2 -2
- package/dist/core/build/plugins/plugin-prerender.js +7 -64
- package/dist/core/build/plugins/plugin-scripts.d.ts +5 -2
- package/dist/core/build/plugins/plugin-scripts.js +5 -13
- package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
- package/dist/core/build/plugins/plugin-ssr.js +60 -132
- package/dist/core/build/plugins/util.d.ts +1 -25
- package/dist/core/build/plugins/util.js +0 -47
- package/dist/core/build/runtime.d.ts +26 -0
- package/dist/core/build/runtime.js +45 -0
- package/dist/core/build/static-build.d.ts +2 -2
- package/dist/core/build/static-build.js +180 -154
- package/dist/core/build/types.d.ts +1 -2
- package/dist/core/build/util.d.ts +0 -1
- package/dist/core/build/util.js +0 -7
- package/dist/core/compile/compile.d.ts +2 -3
- package/dist/core/compile/compile.js +2 -4
- package/dist/core/config/config.js +2 -2
- package/dist/core/config/index.d.ts +0 -1
- package/dist/core/config/index.js +0 -2
- package/dist/core/config/schemas/base.d.ts +330 -1463
- package/dist/core/config/schemas/base.js +40 -56
- package/dist/core/config/schemas/refined.d.ts +2 -2
- package/dist/core/config/schemas/refined.js +8 -1
- package/dist/core/config/schemas/relative.d.ts +607 -1737
- package/dist/core/config/schemas/relative.js +4 -4
- package/dist/core/config/settings.d.ts +3 -3
- package/dist/core/config/settings.js +5 -6
- package/dist/core/config/validate.js +13 -2
- package/dist/core/config/vite-load.js +12 -3
- package/dist/core/constants.d.ts +12 -0
- package/dist/core/constants.js +22 -1
- package/dist/core/create-vite.d.ts +2 -6
- package/dist/core/create-vite.js +36 -47
- package/dist/core/csp/common.d.ts +1 -1
- package/dist/core/csp/common.js +1 -1
- package/dist/core/csp/config.d.ts +8 -4
- package/dist/core/csp/config.js +1 -1
- package/dist/core/dev/container.js +13 -9
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +15 -6
- package/dist/core/errors/dev/runtime.d.ts +6 -0
- package/dist/core/errors/dev/runtime.js +27 -0
- package/dist/core/errors/dev/vite.js +2 -19
- package/dist/core/errors/errors-data.d.ts +85 -57
- package/dist/core/errors/errors-data.js +40 -28
- package/dist/core/errors/errors.d.ts +3 -3
- package/dist/core/errors/errors.js +1 -1
- package/dist/core/errors/overlay.js +1 -1
- package/dist/core/errors/zod-error-map.d.ts +2 -2
- package/dist/core/errors/zod-error-map.js +26 -24
- package/dist/core/messages.d.ts +2 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.js +1 -1
- package/dist/core/middleware/defineMiddleware.d.ts +2 -0
- package/dist/core/middleware/defineMiddleware.js +6 -0
- package/dist/core/middleware/index.d.ts +4 -4
- package/dist/core/middleware/index.js +6 -12
- package/dist/core/middleware/sequence.js +4 -4
- package/dist/core/middleware/vite-plugin.d.ts +1 -1
- package/dist/core/middleware/vite-plugin.js +18 -7
- package/dist/core/module-loader/index.d.ts +2 -2
- package/dist/core/module-loader/index.js +1 -1
- package/dist/core/module-loader/{loader.d.ts → runner.d.ts} +6 -17
- package/dist/core/module-loader/{loader.js → runner.js} +3 -0
- package/dist/core/module-loader/vite.d.ts +3 -2
- package/dist/core/module-loader/vite.js +17 -13
- package/dist/core/preview/index.js +20 -5
- package/dist/core/preview/static-preview-server.js +1 -0
- package/dist/core/redirects/component.js +1 -2
- package/dist/core/redirects/index.d.ts +0 -1
- package/dist/core/redirects/index.js +1 -3
- package/dist/core/redirects/render.js +5 -2
- package/dist/core/render/paginate.d.ts +1 -1
- package/dist/core/render/paginate.js +8 -6
- package/dist/core/render/params-and-props.d.ts +2 -0
- package/dist/core/render/params-and-props.js +19 -7
- package/dist/core/render/route-cache.d.ts +3 -3
- package/dist/core/render/route-cache.js +7 -7
- package/dist/core/render-context.d.ts +9 -7
- package/dist/core/render-context.js +46 -47
- package/dist/core/routing/astro-designed-error-pages.js +2 -2
- package/dist/core/routing/default.js +1 -1
- package/dist/core/routing/helpers.d.ts +22 -0
- package/dist/core/routing/helpers.js +25 -0
- package/dist/core/routing/index.d.ts +1 -1
- package/dist/core/routing/index.js +2 -2
- package/dist/core/routing/manifest/create.d.ts +6 -1
- package/dist/core/routing/manifest/create.js +9 -13
- package/dist/core/routing/manifest/generator.d.ts +3 -1
- package/dist/core/routing/params.d.ts +2 -1
- package/dist/core/routing/params.js +8 -8
- package/dist/core/routing/validation.d.ts +1 -2
- package/dist/core/routing/validation.js +2 -18
- package/dist/core/server-islands/endpoint.d.ts +1 -2
- package/dist/core/server-islands/endpoint.js +5 -4
- package/dist/core/server-islands/vite-plugin-server-islands.d.ts +1 -1
- package/dist/core/server-islands/vite-plugin-server-islands.js +89 -44
- package/dist/core/session/vite-plugin.d.ts +6 -0
- package/dist/core/session/vite-plugin.js +53 -0
- package/dist/core/session.d.ts +4 -2
- package/dist/core/session.js +8 -48
- package/dist/core/sync/index.d.ts +2 -5
- package/dist/core/sync/index.js +19 -34
- package/dist/core/util.d.ts +2 -2
- package/dist/core/util.js +3 -3
- package/dist/entrypoints/legacy.d.ts +2 -0
- package/dist/entrypoints/legacy.js +12 -0
- package/dist/entrypoints/prerender.d.ts +4 -0
- package/dist/entrypoints/prerender.js +7 -0
- package/dist/env/env-loader.d.ts +0 -1
- package/dist/env/env-loader.js +4 -17
- package/dist/env/schema.d.ts +21 -251
- package/dist/env/schema.js +6 -3
- package/dist/env/vite-plugin-env.js +3 -2
- package/dist/env/vite-plugin-import-meta-env.js +3 -2
- package/dist/environments.d.ts +3 -0
- package/dist/environments.js +11 -0
- package/dist/events/error.d.ts +2 -2
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.js +0 -3
- package/dist/i18n/utils.d.ts +1 -6
- package/dist/i18n/utils.js +1 -63
- package/dist/i18n/vite-plugin-i18n.d.ts +0 -5
- package/dist/i18n/vite-plugin-i18n.js +1 -22
- package/dist/integrations/hooks.d.ts +2 -3
- package/dist/integrations/hooks.js +9 -33
- package/dist/manifest/serialized.d.ts +9 -0
- package/dist/manifest/serialized.js +144 -0
- package/dist/manifest/virtual-module.d.ts +1 -4
- package/dist/manifest/virtual-module.js +77 -80
- package/dist/preferences/index.d.ts +1 -2
- package/dist/prefetch/index.d.ts +0 -10
- package/dist/prefetch/index.js +1 -1
- package/dist/prerender/routing.d.ts +5 -7
- package/dist/prerender/routing.js +6 -17
- package/dist/runtime/server/astro-global.d.ts +2 -2
- package/dist/runtime/server/astro-global.js +86 -24
- package/dist/runtime/server/render/server-islands.js +2 -2
- package/dist/runtime/server/transition.d.ts +1 -0
- package/dist/transitions/events.d.ts +7 -0
- package/dist/transitions/router.js +7 -3
- package/dist/transitions/vite-plugin-transitions.js +1 -4
- package/dist/types/astro.d.ts +10 -8
- package/dist/types/public/common.d.ts +1 -3
- package/dist/types/public/config.d.ts +364 -415
- package/dist/types/public/context.d.ts +21 -52
- package/dist/types/public/index.d.ts +2 -1
- package/dist/types/public/integrations.d.ts +23 -18
- package/dist/types/public/internal.d.ts +3 -18
- package/dist/types/public/preview.d.ts +6 -0
- package/dist/virtual-modules/i18n.d.ts +10 -2
- package/dist/virtual-modules/i18n.js +16 -7
- package/dist/virtual-modules/live-config.d.ts +1 -3
- package/dist/virtual-modules/live-config.js +1 -5
- package/dist/virtual-modules/middleware.d.ts +2 -1
- package/dist/virtual-modules/middleware.js +2 -1
- package/dist/vite-plugin-adapter-config/index.js +3 -2
- package/dist/vite-plugin-app/app.d.ts +47 -0
- package/dist/vite-plugin-app/app.js +410 -0
- package/dist/vite-plugin-app/createAstroServerApp.d.ts +8 -0
- package/dist/vite-plugin-app/createAstroServerApp.js +56 -0
- package/dist/vite-plugin-app/index.d.ts +3 -0
- package/dist/vite-plugin-app/index.js +16 -0
- package/dist/{vite-plugin-astro-server → vite-plugin-app}/pipeline.d.ts +5 -7
- package/dist/vite-plugin-app/pipeline.js +166 -0
- package/dist/vite-plugin-astro/index.js +11 -13
- package/dist/vite-plugin-astro-server/controller.d.ts +1 -1
- package/dist/vite-plugin-astro-server/error.d.ts +3 -4
- package/dist/vite-plugin-astro-server/error.js +2 -5
- package/dist/vite-plugin-astro-server/index.d.ts +1 -2
- package/dist/vite-plugin-astro-server/index.js +6 -4
- package/dist/vite-plugin-astro-server/metadata.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.d.ts +4 -7
- package/dist/vite-plugin-astro-server/plugin.js +53 -96
- package/dist/vite-plugin-astro-server/server-state.d.ts +1 -1
- package/dist/vite-plugin-astro-server/util.d.ts +0 -2
- package/dist/vite-plugin-astro-server/util.js +1 -2
- package/dist/vite-plugin-astro-server/vite.d.ts +2 -2
- package/dist/vite-plugin-astro-server/vite.js +7 -7
- package/dist/vite-plugin-config-alias/index.js +40 -32
- package/dist/vite-plugin-css/index.d.ts +18 -0
- package/dist/vite-plugin-css/index.js +134 -0
- package/dist/vite-plugin-css/util.d.ts +5 -0
- package/dist/vite-plugin-css/util.js +8 -0
- package/dist/vite-plugin-environment/index.d.ts +15 -0
- package/dist/vite-plugin-environment/index.js +77 -0
- package/dist/vite-plugin-head/index.d.ts +1 -2
- package/dist/vite-plugin-head/index.js +42 -58
- package/dist/vite-plugin-hmr-reload/index.js +2 -1
- package/dist/vite-plugin-markdown/index.js +0 -1
- package/dist/vite-plugin-pages/const.d.ts +2 -0
- package/dist/vite-plugin-pages/const.js +6 -0
- package/dist/vite-plugin-pages/index.d.ts +2 -0
- package/dist/vite-plugin-pages/index.js +7 -0
- package/dist/vite-plugin-pages/page.d.ts +7 -0
- package/dist/vite-plugin-pages/page.js +48 -0
- package/dist/vite-plugin-pages/pages.d.ts +8 -0
- package/dist/vite-plugin-pages/pages.js +57 -0
- package/dist/vite-plugin-pages/util.d.ts +8 -0
- package/dist/vite-plugin-pages/util.js +15 -0
- package/dist/vite-plugin-renderers/index.d.ts +9 -0
- package/dist/vite-plugin-renderers/index.js +40 -0
- package/dist/vite-plugin-routes/index.d.ts +14 -0
- package/dist/vite-plugin-routes/index.js +177 -0
- package/dist/vite-plugin-scripts/index.js +2 -6
- package/dist/vite-plugin-scripts/page-ssr.js +3 -2
- package/dist/zod.d.ts +2 -2
- package/dist/zod.js +2 -2
- package/package.json +14 -15
- package/templates/content/module.mjs +9 -63
- package/templates/content/types.d.ts +32 -78
- package/types/actions.d.ts +1 -5
- package/types/content.d.ts +9 -11
- package/types/transitions.d.ts +25 -0
- package/dist/actions/loadActions.d.ts +0 -8
- package/dist/actions/loadActions.js +0 -13
- package/dist/actions/runtime/route.d.ts +0 -2
- package/dist/actions/runtime/shared.d.ts +0 -60
- package/dist/actions/runtime/shared.js +0 -296
- package/dist/actions/runtime/utils.d.ts +0 -31
- package/dist/actions/runtime/utils.js +0 -16
- package/dist/actions/runtime/virtual.d.ts +0 -4
- package/dist/actions/runtime/virtual.js +0 -127
- package/dist/assets/utils/node/emitAsset.d.ts +0 -29
- package/dist/assets/utils/transformToPath.js +0 -32
- package/dist/config/vite-plugin-content-listen.d.ts +0 -17
- package/dist/config/vite-plugin-content-listen.js +0 -26
- package/dist/container/polyfill.d.ts +0 -1
- package/dist/container/polyfill.js +0 -2
- package/dist/core/build/css-asset-name.d.ts +0 -9
- package/dist/core/build/css-asset-name.js +0 -89
- package/dist/core/build/plugin.d.ts +0 -43
- package/dist/core/build/plugin.js +0 -61
- package/dist/core/build/plugins/plugin-actions.d.ts +0 -4
- package/dist/core/build/plugins/plugin-actions.js +0 -16
- package/dist/core/build/plugins/plugin-chunks.d.ts +0 -2
- package/dist/core/build/plugins/plugin-chunks.js +0 -33
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -6
- package/dist/core/build/plugins/plugin-pages.js +0 -66
- package/dist/core/build/plugins/plugin-renderers.d.ts +0 -5
- package/dist/core/build/plugins/plugin-renderers.js +0 -54
- package/dist/core/middleware/loadMiddleware.d.ts +0 -7
- package/dist/core/middleware/loadMiddleware.js +0 -14
- package/dist/core/polyfill.d.ts +0 -5
- package/dist/core/polyfill.js +0 -17
- package/dist/core/redirects/helpers.d.ts +0 -7
- package/dist/core/redirects/helpers.js +0 -10
- package/dist/core/routing/manifest/serialization.d.ts +0 -5
- package/dist/core/routing/manifest/serialization.js +0 -37
- package/dist/prerender/metadata.d.ts +0 -8
- package/dist/prerender/metadata.js +0 -18
- package/dist/vite-plugin-astro-postprocess/index.d.ts +0 -2
- package/dist/vite-plugin-astro-postprocess/index.js +0 -48
- package/dist/vite-plugin-astro-server/css.d.ts +0 -13
- package/dist/vite-plugin-astro-server/css.js +0 -48
- package/dist/vite-plugin-astro-server/pipeline.js +0 -166
- package/dist/vite-plugin-astro-server/request.d.ts +0 -14
- package/dist/vite-plugin-astro-server/request.js +0 -73
- package/dist/vite-plugin-astro-server/route.d.ts +0 -25
- package/dist/vite-plugin-astro-server/route.js +0 -283
- package/dist/vite-plugin-scanner/index.d.ts +0 -10
- package/dist/vite-plugin-scanner/index.js +0 -87
- package/dist/vite-plugin-ssr-manifest/index.d.ts +0 -2
- package/dist/vite-plugin-ssr-manifest/index.js +0 -26
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import type { ActionAPIContext } from '../actions/runtime/
|
|
1
|
+
import type { ActionAPIContext } from '../actions/runtime/types.js';
|
|
2
2
|
import type { ComponentInstance } from '../types/astro.js';
|
|
3
3
|
import type { MiddlewareHandler, Props } from '../types/public/common.js';
|
|
4
|
-
import type { APIContext, AstroGlobal
|
|
4
|
+
import type { APIContext, AstroGlobal } from '../types/public/context.js';
|
|
5
5
|
import type { RouteData, SSRResult } from '../types/public/internal.js';
|
|
6
|
-
import type { SSRActions } from './app/types.js';
|
|
6
|
+
import type { ServerIslandMappings, SSRActions } from './app/types.js';
|
|
7
7
|
import { AstroCookies } from './cookies/index.js';
|
|
8
8
|
import { type Pipeline } from './render/index.js';
|
|
9
9
|
import { AstroSession } from './session.js';
|
|
10
|
-
export declare const apiContextRoutesSymbol: unique symbol;
|
|
11
10
|
/**
|
|
12
11
|
* Each request is rendered using a `RenderContext`.
|
|
13
12
|
* It contains data unique to each request. It is responsible for executing middleware, calling endpoints, and rendering the page by gathering necessary data from a `Pipeline`.
|
|
14
13
|
*/
|
|
14
|
+
export type CreateRenderContext = Pick<RenderContext, 'pathname' | 'pipeline' | 'request' | 'routeData' | 'clientAddress'> & Partial<Pick<RenderContext, 'locals' | 'status' | 'props' | 'partial' | 'actions' | 'shouldInjectCspMetaTags' | 'skipMiddleware'>>;
|
|
15
15
|
export declare class RenderContext {
|
|
16
16
|
#private;
|
|
17
17
|
readonly pipeline: Pipeline;
|
|
18
18
|
locals: App.Locals;
|
|
19
19
|
readonly middleware: MiddlewareHandler;
|
|
20
20
|
readonly actions: SSRActions;
|
|
21
|
+
readonly serverIslands: ServerIslandMappings;
|
|
21
22
|
pathname: string;
|
|
22
23
|
request: Request;
|
|
23
24
|
routeData: RouteData;
|
|
@@ -30,6 +31,7 @@ export declare class RenderContext {
|
|
|
30
31
|
partial: undefined | boolean;
|
|
31
32
|
shouldInjectCspMetaTags: boolean;
|
|
32
33
|
session: AstroSession | undefined;
|
|
34
|
+
skipMiddleware: boolean;
|
|
33
35
|
private constructor();
|
|
34
36
|
/**
|
|
35
37
|
* A flag that tells the render content if the rewriting was triggered
|
|
@@ -40,7 +42,7 @@ export declare class RenderContext {
|
|
|
40
42
|
*/
|
|
41
43
|
counter: number;
|
|
42
44
|
result: SSRResult | undefined;
|
|
43
|
-
static create({ locals,
|
|
45
|
+
static create({ locals, pathname, pipeline, request, routeData, clientAddress, status, props, partial, shouldInjectCspMetaTags, skipMiddleware, }: CreateRenderContext): Promise<RenderContext>;
|
|
44
46
|
/**
|
|
45
47
|
* The main function of the RenderContext.
|
|
46
48
|
*
|
|
@@ -64,8 +66,8 @@ export declare class RenderContext {
|
|
|
64
66
|
*
|
|
65
67
|
* The page level partial is used as the prototype of the user-visible `Astro` global object, which is instantiated once per use of a component.
|
|
66
68
|
*/
|
|
67
|
-
createAstro(result: SSRResult,
|
|
68
|
-
createAstroPagePartial(result: SSRResult,
|
|
69
|
+
createAstro(result: SSRResult, props: Record<string, any>, slotValues: Record<string, any> | null, apiContext: ActionAPIContext): AstroGlobal;
|
|
70
|
+
createAstroPagePartial(result: SSRResult, apiContext: ActionAPIContext): Omit<AstroGlobal, 'props' | 'self' | 'slots'>;
|
|
69
71
|
getClientAddress(): string;
|
|
70
72
|
computeCurrentLocale(): string | undefined;
|
|
71
73
|
computePreferredLocale(): string | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import colors from "piccolore";
|
|
2
|
+
import { deserializeActionResult } from "../actions/runtime/client.js";
|
|
2
3
|
import { getActionContext } from "../actions/runtime/server.js";
|
|
3
|
-
import { deserializeActionResult } from "../actions/runtime/shared.js";
|
|
4
4
|
import { createCallAction, createGetActionResult, hasActionPayload } from "../actions/utils.js";
|
|
5
5
|
import {
|
|
6
6
|
computeCurrentLocale,
|
|
@@ -10,12 +10,12 @@ import {
|
|
|
10
10
|
import { renderEndpoint } from "../runtime/server/endpoint.js";
|
|
11
11
|
import { renderPage } from "../runtime/server/index.js";
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
clientAddressSymbol,
|
|
13
|
+
ASTRO_GENERATOR,
|
|
15
14
|
REROUTE_DIRECTIVE_HEADER,
|
|
16
15
|
REWRITE_DIRECTIVE_HEADER_KEY,
|
|
17
16
|
REWRITE_DIRECTIVE_HEADER_VALUE,
|
|
18
17
|
ROUTE_TYPE_HEADER,
|
|
18
|
+
pipelineSymbol,
|
|
19
19
|
responseSentSymbol
|
|
20
20
|
} from "./constants.js";
|
|
21
21
|
import { AstroCookies, attachCookiesToResponse } from "./cookies/index.js";
|
|
@@ -32,13 +32,13 @@ import { isRoute404or500, isRouteExternalRedirect, isRouteServerIsland } from ".
|
|
|
32
32
|
import { copyRequest, getOriginPathname, setOriginPathname } from "./routing/rewrite.js";
|
|
33
33
|
import { AstroSession } from "./session.js";
|
|
34
34
|
import { validateAndDecodePathname } from "./util/pathname.js";
|
|
35
|
-
const apiContextRoutesSymbol = Symbol.for("context.routes");
|
|
36
35
|
class RenderContext {
|
|
37
|
-
constructor(pipeline, locals, middleware, actions, pathname, request, routeData, status, clientAddress, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = RenderContext.#createNormalizedUrl(request.url), props = {}, partial = void 0, shouldInjectCspMetaTags = !!pipeline.manifest.csp, session =
|
|
36
|
+
constructor(pipeline, locals, middleware, actions, serverIslands, pathname, request, routeData, status, clientAddress, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = RenderContext.#createNormalizedUrl(request.url), props = {}, partial = void 0, shouldInjectCspMetaTags = !!pipeline.manifest.csp, session = void 0, skipMiddleware = false) {
|
|
38
37
|
this.pipeline = pipeline;
|
|
39
38
|
this.locals = locals;
|
|
40
39
|
this.middleware = middleware;
|
|
41
40
|
this.actions = actions;
|
|
41
|
+
this.serverIslands = serverIslands;
|
|
42
42
|
this.pathname = pathname;
|
|
43
43
|
this.request = request;
|
|
44
44
|
this.routeData = routeData;
|
|
@@ -51,6 +51,7 @@ class RenderContext {
|
|
|
51
51
|
this.partial = partial;
|
|
52
52
|
this.shouldInjectCspMetaTags = shouldInjectCspMetaTags;
|
|
53
53
|
this.session = session;
|
|
54
|
+
this.skipMiddleware = skipMiddleware;
|
|
54
55
|
}
|
|
55
56
|
static #createNormalizedUrl(requestUrl) {
|
|
56
57
|
const url = new URL(requestUrl);
|
|
@@ -75,7 +76,6 @@ class RenderContext {
|
|
|
75
76
|
result = void 0;
|
|
76
77
|
static async create({
|
|
77
78
|
locals = {},
|
|
78
|
-
middleware,
|
|
79
79
|
pathname,
|
|
80
80
|
pipeline,
|
|
81
81
|
request,
|
|
@@ -84,33 +84,45 @@ class RenderContext {
|
|
|
84
84
|
status = 200,
|
|
85
85
|
props,
|
|
86
86
|
partial = void 0,
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
shouldInjectCspMetaTags,
|
|
88
|
+
skipMiddleware = false
|
|
89
89
|
}) {
|
|
90
90
|
const pipelineMiddleware = await pipeline.getMiddleware();
|
|
91
|
-
const pipelineActions =
|
|
91
|
+
const pipelineActions = await pipeline.getActions();
|
|
92
|
+
const pipelineSessionDriver = await pipeline.getSessionDriver();
|
|
93
|
+
const serverIslands = await pipeline.getServerIslands();
|
|
92
94
|
setOriginPathname(
|
|
93
95
|
request,
|
|
94
96
|
pathname,
|
|
95
97
|
pipeline.manifest.trailingSlash,
|
|
96
98
|
pipeline.manifest.buildFormat
|
|
97
99
|
);
|
|
100
|
+
const cookies = new AstroCookies(request);
|
|
101
|
+
const session = pipeline.manifest.sessionConfig && pipelineSessionDriver ? new AstroSession(
|
|
102
|
+
cookies,
|
|
103
|
+
pipeline.manifest.sessionConfig,
|
|
104
|
+
pipeline.runtimeMode,
|
|
105
|
+
pipelineSessionDriver
|
|
106
|
+
) : void 0;
|
|
98
107
|
return new RenderContext(
|
|
99
108
|
pipeline,
|
|
100
109
|
locals,
|
|
101
|
-
sequence(...pipeline.internalMiddleware,
|
|
110
|
+
sequence(...pipeline.internalMiddleware, pipelineMiddleware),
|
|
102
111
|
pipelineActions,
|
|
112
|
+
serverIslands,
|
|
103
113
|
pathname,
|
|
104
114
|
request,
|
|
105
115
|
routeData,
|
|
106
116
|
status,
|
|
107
117
|
clientAddress,
|
|
108
|
-
|
|
118
|
+
cookies,
|
|
109
119
|
void 0,
|
|
110
120
|
void 0,
|
|
111
121
|
props,
|
|
112
122
|
partial,
|
|
113
|
-
shouldInjectCspMetaTags ?? !!pipeline.manifest.csp
|
|
123
|
+
shouldInjectCspMetaTags ?? !!pipeline.manifest.csp,
|
|
124
|
+
session,
|
|
125
|
+
skipMiddleware
|
|
114
126
|
);
|
|
115
127
|
}
|
|
116
128
|
/**
|
|
@@ -126,15 +138,16 @@ class RenderContext {
|
|
|
126
138
|
*/
|
|
127
139
|
async render(componentInstance, slots = {}) {
|
|
128
140
|
const { middleware, pipeline } = this;
|
|
129
|
-
const { logger,
|
|
141
|
+
const { logger, streaming, manifest } = pipeline;
|
|
130
142
|
const props = Object.keys(this.props).length > 0 ? this.props : await getProps({
|
|
131
143
|
mod: componentInstance,
|
|
132
144
|
routeData: this.routeData,
|
|
133
145
|
routeCache: this.pipeline.routeCache,
|
|
134
146
|
pathname: this.pathname,
|
|
135
147
|
logger,
|
|
136
|
-
serverLike,
|
|
137
|
-
base: manifest.base
|
|
148
|
+
serverLike: manifest.serverLike,
|
|
149
|
+
base: manifest.base,
|
|
150
|
+
trailingSlash: manifest.trailingSlash
|
|
138
151
|
});
|
|
139
152
|
const actionApiContext = this.createActionAPIContext();
|
|
140
153
|
const apiContext = this.createAPIContext(props, actionApiContext);
|
|
@@ -156,7 +169,7 @@ class RenderContext {
|
|
|
156
169
|
pathname,
|
|
157
170
|
newUrl
|
|
158
171
|
} = await pipeline.tryRewrite(payload, this.request);
|
|
159
|
-
if (this.pipeline.serverLike === true && this.routeData.prerender === false && routeData.prerender === true) {
|
|
172
|
+
if (this.pipeline.manifest.serverLike === true && this.routeData.prerender === false && routeData.prerender === true) {
|
|
160
173
|
throw new AstroError({
|
|
161
174
|
...ForbiddenRewrite,
|
|
162
175
|
message: ForbiddenRewrite.message(this.pathname, pathname, routeData.component),
|
|
@@ -246,7 +259,7 @@ class RenderContext {
|
|
|
246
259
|
if (isRouteExternalRedirect(this.routeData)) {
|
|
247
260
|
return renderRedirect(this);
|
|
248
261
|
}
|
|
249
|
-
const response = await callMiddleware(middleware, apiContext, lastNext);
|
|
262
|
+
const response = this.skipMiddleware ? await lastNext(apiContext) : await callMiddleware(middleware, apiContext, lastNext);
|
|
250
263
|
if (response.headers.get(ROUTE_TYPE_HEADER)) {
|
|
251
264
|
response.headers.delete(ROUTE_TYPE_HEADER);
|
|
252
265
|
}
|
|
@@ -255,10 +268,14 @@ class RenderContext {
|
|
|
255
268
|
}
|
|
256
269
|
createAPIContext(props, context) {
|
|
257
270
|
const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
|
|
258
|
-
|
|
271
|
+
const rewrite = async (reroutePayload) => {
|
|
272
|
+
return await this.#executeRewrite(reroutePayload);
|
|
273
|
+
};
|
|
274
|
+
Reflect.set(context, pipelineSymbol, this.pipeline);
|
|
259
275
|
return Object.assign(context, {
|
|
260
276
|
props,
|
|
261
277
|
redirect,
|
|
278
|
+
rewrite,
|
|
262
279
|
getActionResult: createGetActionResult(context.locals),
|
|
263
280
|
callAction: createCallAction(context)
|
|
264
281
|
});
|
|
@@ -271,7 +288,7 @@ class RenderContext {
|
|
|
271
288
|
this.request
|
|
272
289
|
);
|
|
273
290
|
const isI18nFallback = routeData.fallbackRoutes && routeData.fallbackRoutes.length > 0;
|
|
274
|
-
if (this.pipeline.serverLike && !this.routeData.prerender && routeData.prerender && !isI18nFallback) {
|
|
291
|
+
if (this.pipeline.manifest.serverLike && !this.routeData.prerender && routeData.prerender && !isI18nFallback) {
|
|
275
292
|
throw new AstroError({
|
|
276
293
|
...ForbiddenRewrite,
|
|
277
294
|
message: ForbiddenRewrite.message(this.pathname, pathname, routeData.component),
|
|
@@ -312,10 +329,6 @@ class RenderContext {
|
|
|
312
329
|
createActionAPIContext() {
|
|
313
330
|
const renderContext = this;
|
|
314
331
|
const { params, pipeline, url } = this;
|
|
315
|
-
const generator = `Astro v${ASTRO_VERSION}`;
|
|
316
|
-
const rewrite = async (reroutePayload) => {
|
|
317
|
-
return await this.#executeRewrite(reroutePayload);
|
|
318
|
-
};
|
|
319
332
|
return {
|
|
320
333
|
// Don't allow reassignment of cookies because it doesn't work
|
|
321
334
|
get cookies() {
|
|
@@ -329,7 +342,7 @@ class RenderContext {
|
|
|
329
342
|
get currentLocale() {
|
|
330
343
|
return renderContext.computeCurrentLocale();
|
|
331
344
|
},
|
|
332
|
-
generator,
|
|
345
|
+
generator: ASTRO_GENERATOR,
|
|
333
346
|
get locals() {
|
|
334
347
|
return renderContext.locals;
|
|
335
348
|
},
|
|
@@ -343,7 +356,6 @@ class RenderContext {
|
|
|
343
356
|
get preferredLocaleList() {
|
|
344
357
|
return renderContext.computePreferredLocaleList();
|
|
345
358
|
},
|
|
346
|
-
rewrite,
|
|
347
359
|
request: this.request,
|
|
348
360
|
site: pipeline.site,
|
|
349
361
|
url,
|
|
@@ -451,7 +463,7 @@ class RenderContext {
|
|
|
451
463
|
compressHTML,
|
|
452
464
|
cookies,
|
|
453
465
|
/** This function returns the `Astro` faux-global */
|
|
454
|
-
createAstro: (
|
|
466
|
+
createAstro: (props, slots) => this.createAstro(result, props, slots, ctx),
|
|
455
467
|
links,
|
|
456
468
|
params: this.params,
|
|
457
469
|
partial,
|
|
@@ -463,7 +475,7 @@ class RenderContext {
|
|
|
463
475
|
scripts,
|
|
464
476
|
styles,
|
|
465
477
|
actionResult,
|
|
466
|
-
serverIslandNameMap:
|
|
478
|
+
serverIslandNameMap: this.serverIslands.serverIslandNameMap ?? /* @__PURE__ */ new Map(),
|
|
467
479
|
key: manifest.key,
|
|
468
480
|
trailingSlash: manifest.trailingSlash,
|
|
469
481
|
_metadata: {
|
|
@@ -502,20 +514,12 @@ class RenderContext {
|
|
|
502
514
|
*
|
|
503
515
|
* The page level partial is used as the prototype of the user-visible `Astro` global object, which is instantiated once per use of a component.
|
|
504
516
|
*/
|
|
505
|
-
createAstro(result,
|
|
517
|
+
createAstro(result, props, slotValues, apiContext) {
|
|
506
518
|
let astroPagePartial;
|
|
507
519
|
if (this.isRewriting) {
|
|
508
|
-
astroPagePartial = this.#astroPagePartial = this.createAstroPagePartial(
|
|
509
|
-
result,
|
|
510
|
-
astroStaticPartial,
|
|
511
|
-
apiContext
|
|
512
|
-
);
|
|
520
|
+
astroPagePartial = this.#astroPagePartial = this.createAstroPagePartial(result, apiContext);
|
|
513
521
|
} else {
|
|
514
|
-
astroPagePartial = this.#astroPagePartial ??= this.createAstroPagePartial(
|
|
515
|
-
result,
|
|
516
|
-
astroStaticPartial,
|
|
517
|
-
apiContext
|
|
518
|
-
);
|
|
522
|
+
astroPagePartial = this.#astroPagePartial ??= this.createAstroPagePartial(result, apiContext);
|
|
519
523
|
}
|
|
520
524
|
const astroComponentPartial = { props, self: null };
|
|
521
525
|
const Astro = Object.assign(
|
|
@@ -537,7 +541,7 @@ class RenderContext {
|
|
|
537
541
|
});
|
|
538
542
|
return Astro;
|
|
539
543
|
}
|
|
540
|
-
createAstroPagePartial(result,
|
|
544
|
+
createAstroPagePartial(result, apiContext) {
|
|
541
545
|
const renderContext = this;
|
|
542
546
|
const { cookies, locals, params, pipeline, url } = this;
|
|
543
547
|
const { response } = result;
|
|
@@ -554,8 +558,7 @@ class RenderContext {
|
|
|
554
558
|
};
|
|
555
559
|
const callAction = createCallAction(apiContext);
|
|
556
560
|
return {
|
|
557
|
-
generator:
|
|
558
|
-
glob: astroStaticPartial.glob,
|
|
561
|
+
generator: ASTRO_GENERATOR,
|
|
559
562
|
routePattern: this.routeData.route,
|
|
560
563
|
isPrerendered: this.routeData.prerender,
|
|
561
564
|
cookies,
|
|
@@ -647,7 +650,7 @@ class RenderContext {
|
|
|
647
650
|
};
|
|
648
651
|
}
|
|
649
652
|
getClientAddress() {
|
|
650
|
-
const { pipeline,
|
|
653
|
+
const { pipeline, routeData, clientAddress } = this;
|
|
651
654
|
if (routeData.prerender) {
|
|
652
655
|
throw new AstroError({
|
|
653
656
|
...AstroErrorData.PrerenderClientAddressNotAvailable,
|
|
@@ -657,9 +660,6 @@ class RenderContext {
|
|
|
657
660
|
if (clientAddress) {
|
|
658
661
|
return clientAddress;
|
|
659
662
|
}
|
|
660
|
-
if (clientAddressSymbol in request) {
|
|
661
|
-
return Reflect.get(request, clientAddressSymbol);
|
|
662
|
-
}
|
|
663
663
|
if (pipeline.adapterName) {
|
|
664
664
|
throw new AstroError({
|
|
665
665
|
...AstroErrorData.ClientAddressNotAvailable,
|
|
@@ -730,6 +730,5 @@ class RenderContext {
|
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
732
|
export {
|
|
733
|
-
RenderContext
|
|
734
|
-
apiContextRoutesSymbol
|
|
733
|
+
RenderContext
|
|
735
734
|
};
|
|
@@ -2,7 +2,6 @@ import notFoundTemplate from "../../template/4xx.js";
|
|
|
2
2
|
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
|
3
3
|
const DEFAULT_404_ROUTE = {
|
|
4
4
|
component: DEFAULT_404_COMPONENT,
|
|
5
|
-
generate: () => "",
|
|
6
5
|
params: [],
|
|
7
6
|
pattern: /^\/404\/?$/,
|
|
8
7
|
prerender: false,
|
|
@@ -12,7 +11,8 @@ const DEFAULT_404_ROUTE = {
|
|
|
12
11
|
route: "/404",
|
|
13
12
|
fallbackRoutes: [],
|
|
14
13
|
isIndex: false,
|
|
15
|
-
origin: "internal"
|
|
14
|
+
origin: "internal",
|
|
15
|
+
distURL: []
|
|
16
16
|
};
|
|
17
17
|
function ensure404Route(manifest) {
|
|
18
18
|
if (!manifest.routes.some((route) => route.route === "/404")) {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { DEFAULT_404_ROUTE, default404Instance } from "./astro-designed-error-pages.js";
|
|
8
8
|
const DEFAULT_COMPONENTS = [DEFAULT_404_COMPONENT, SERVER_ISLAND_COMPONENT];
|
|
9
9
|
function createDefaultRoutes(manifest) {
|
|
10
|
-
const root = new URL(manifest.
|
|
10
|
+
const root = new URL(manifest.rootDir);
|
|
11
11
|
return [
|
|
12
12
|
{
|
|
13
13
|
instance: default404Instance,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RouteData } from '../../types/public/internal.js';
|
|
2
|
+
import type { RouteInfo } from '../app/types.js';
|
|
3
|
+
type RedirectRouteData = RouteData & {
|
|
4
|
+
redirect: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Function guard that checks if a route is redirect. If so, `RouteData.redirectRoute` and
|
|
8
|
+
* `RouteData.redirect` aren't `undefined` anymore
|
|
9
|
+
* @param route
|
|
10
|
+
*/
|
|
11
|
+
export declare function routeIsRedirect(route: RouteData | undefined): route is RedirectRouteData;
|
|
12
|
+
export declare function routeIsFallback(route: RouteData | undefined): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Give a route, it returns its fallback routes from a `list` of `RouteInfo[]`.
|
|
15
|
+
*
|
|
16
|
+
* It throws an error if no fallback routes were found. This means there's an error
|
|
17
|
+
* when we construct the list of routes
|
|
18
|
+
* @param route
|
|
19
|
+
* @param routeList
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFallbackRoute(route: RouteData, routeList: RouteInfo[]): RouteData;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function routeIsRedirect(route) {
|
|
2
|
+
return route?.type === "redirect";
|
|
3
|
+
}
|
|
4
|
+
function routeIsFallback(route) {
|
|
5
|
+
return route?.type === "fallback";
|
|
6
|
+
}
|
|
7
|
+
function getFallbackRoute(route, routeList) {
|
|
8
|
+
const fallbackRoute = routeList.find((r) => {
|
|
9
|
+
if (route.route === "/" && r.routeData.route === "/") {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return r.routeData.fallbackRoutes.find((f) => {
|
|
13
|
+
return f.route === route.route;
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
if (!fallbackRoute) {
|
|
17
|
+
throw new Error(`No fallback route found for route ${route.route}`);
|
|
18
|
+
}
|
|
19
|
+
return fallbackRoute.routeData;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
getFallbackRoute,
|
|
23
|
+
routeIsFallback,
|
|
24
|
+
routeIsRedirect
|
|
25
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { routeIsRedirect } from "./helpers.js";
|
|
1
2
|
import { createRoutesList } from "./manifest/create.js";
|
|
2
|
-
import { serializeRouteData } from "./manifest/serialization.js";
|
|
3
3
|
import { matchAllRoutes } from "./match.js";
|
|
4
4
|
export {
|
|
5
5
|
createRoutesList,
|
|
6
6
|
matchAllRoutes,
|
|
7
|
-
|
|
7
|
+
routeIsRedirect
|
|
8
8
|
};
|
|
@@ -10,8 +10,13 @@ interface CreateRouteManifestParams {
|
|
|
10
10
|
fsMod?: typeof nodeFs;
|
|
11
11
|
}
|
|
12
12
|
/** Create manifest of all static routes */
|
|
13
|
-
export declare function createRoutesList(params: CreateRouteManifestParams, logger: Logger, { dev }?: {
|
|
13
|
+
export declare function createRoutesList(params: CreateRouteManifestParams, logger: Logger, { dev, skipBuildOutputAssignment, }?: {
|
|
14
14
|
dev?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, the assignment of `settings.buildOutput` is skipped.
|
|
17
|
+
* Usually, that's needed when this function has already been called.
|
|
18
|
+
*/
|
|
19
|
+
skipBuildOutputAssignment?: boolean;
|
|
15
20
|
}): Promise<RoutesList>;
|
|
16
21
|
export declare function resolveInjectedRoute(entrypoint: string, root: URL, cwd?: string): {
|
|
17
22
|
resolved: string;
|
|
@@ -5,9 +5,9 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import pLimit from "p-limit";
|
|
6
6
|
import colors from "piccolore";
|
|
7
7
|
import { injectImageEndpoint } from "../../../assets/endpoint/config.js";
|
|
8
|
-
import { toRoutingStrategy } from "../../../i18n/utils.js";
|
|
9
8
|
import { runHookRoutesResolved } from "../../../integrations/hooks.js";
|
|
10
9
|
import { getPrerenderDefault } from "../../../prerender/utils.js";
|
|
10
|
+
import { toRoutingStrategy } from "../../app/index.js";
|
|
11
11
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
|
12
12
|
import {
|
|
13
13
|
MissingIndexForInternationalization,
|
|
@@ -19,7 +19,6 @@ import { injectServerIslandRoute } from "../../server-islands/endpoint.js";
|
|
|
19
19
|
import { resolvePages } from "../../util.js";
|
|
20
20
|
import { ensure404Route } from "../astro-designed-error-pages.js";
|
|
21
21
|
import { routeComparator } from "../priority.js";
|
|
22
|
-
import { getRouteGenerator } from "./generator.js";
|
|
23
22
|
import { getPattern } from "./pattern.js";
|
|
24
23
|
import { getRoutePrerenderOption } from "./prerender.js";
|
|
25
24
|
import { validateSegment } from "./segment.js";
|
|
@@ -148,7 +147,6 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
|
|
148
147
|
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
|
149
148
|
const trailingSlash = trailingSlashForPath(pathname, settings.config);
|
|
150
149
|
const pattern = getPattern(segments, settings.config.base, trailingSlash);
|
|
151
|
-
const generate = getRouteGenerator(segments, trailingSlash);
|
|
152
150
|
const route = joinSegments(segments);
|
|
153
151
|
routes.push({
|
|
154
152
|
route,
|
|
@@ -158,7 +156,6 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
|
|
158
156
|
segments,
|
|
159
157
|
params,
|
|
160
158
|
component,
|
|
161
|
-
generate,
|
|
162
159
|
pathname: pathname || void 0,
|
|
163
160
|
prerender,
|
|
164
161
|
fallbackRoutes: [],
|
|
@@ -178,7 +175,7 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
|
|
|
178
175
|
}
|
|
179
176
|
return routes;
|
|
180
177
|
}
|
|
181
|
-
const trailingSlashForPath = (pathname, config) => pathname && hasFileExtension(pathname) ? "
|
|
178
|
+
const trailingSlashForPath = (pathname, config) => pathname && hasFileExtension(pathname) ? "never" : config.trailingSlash;
|
|
182
179
|
function createInjectedRoutes({ settings, cwd }) {
|
|
183
180
|
const { config } = settings;
|
|
184
181
|
const prerender = getPrerenderDefault(config);
|
|
@@ -194,7 +191,6 @@ function createInjectedRoutes({ settings, cwd }) {
|
|
|
194
191
|
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
|
195
192
|
const trailingSlash = trailingSlashForPath(pathname, config);
|
|
196
193
|
const pattern = getPattern(segments, settings.config.base, trailingSlash);
|
|
197
|
-
const generate = getRouteGenerator(segments, trailingSlash);
|
|
198
194
|
const params = segments.flat().filter((p) => p.dynamic).map((p) => p.content);
|
|
199
195
|
const route = joinSegments(segments);
|
|
200
196
|
routes.push({
|
|
@@ -206,7 +202,6 @@ function createInjectedRoutes({ settings, cwd }) {
|
|
|
206
202
|
segments,
|
|
207
203
|
params,
|
|
208
204
|
component,
|
|
209
|
-
generate,
|
|
210
205
|
pathname: pathname || void 0,
|
|
211
206
|
prerender: prerenderInjected ?? prerender,
|
|
212
207
|
fallbackRoutes: [],
|
|
@@ -226,7 +221,6 @@ function createRedirectRoutes({ settings }, routeMap) {
|
|
|
226
221
|
return getParts(s, from);
|
|
227
222
|
});
|
|
228
223
|
const pattern = getPattern(segments, settings.config.base, trailingSlash);
|
|
229
|
-
const generate = getRouteGenerator(segments, trailingSlash);
|
|
230
224
|
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
|
231
225
|
const params = segments.flat().filter((p) => p.dynamic).map((p) => p.content);
|
|
232
226
|
const route = joinSegments(segments);
|
|
@@ -251,7 +245,6 @@ function createRedirectRoutes({ settings }, routeMap) {
|
|
|
251
245
|
segments,
|
|
252
246
|
params,
|
|
253
247
|
component: from,
|
|
254
|
-
generate,
|
|
255
248
|
pathname: pathname || void 0,
|
|
256
249
|
prerender: getPrerenderDefault(config),
|
|
257
250
|
redirect: to,
|
|
@@ -301,7 +294,10 @@ function detectRouteCollision(a, b, _config, logger) {
|
|
|
301
294
|
);
|
|
302
295
|
logger.warn("router", "A collision will result in an hard error in following versions of Astro.");
|
|
303
296
|
}
|
|
304
|
-
async function createRoutesList(params, logger, {
|
|
297
|
+
async function createRoutesList(params, logger, {
|
|
298
|
+
dev = false,
|
|
299
|
+
skipBuildOutputAssignment = false
|
|
300
|
+
} = {}) {
|
|
305
301
|
const { settings } = params;
|
|
306
302
|
const { config } = settings;
|
|
307
303
|
const routeMap = /* @__PURE__ */ new Map();
|
|
@@ -321,7 +317,9 @@ async function createRoutesList(params, logger, { dev = false } = {}) {
|
|
|
321
317
|
const routes = [
|
|
322
318
|
...[...filteredFiledBasedRoutes, ...injectedRoutes, ...redirectRoutes].sort(routeComparator)
|
|
323
319
|
];
|
|
324
|
-
|
|
320
|
+
if (skipBuildOutputAssignment !== true) {
|
|
321
|
+
settings.buildOutput = getPrerenderDefault(config) ? "static" : "server";
|
|
322
|
+
}
|
|
325
323
|
const limit = pLimit(10);
|
|
326
324
|
let promises = [];
|
|
327
325
|
for (const route of routes) {
|
|
@@ -472,7 +470,6 @@ async function createRoutesList(params, logger, { dev = false } = {}) {
|
|
|
472
470
|
validateSegment(s);
|
|
473
471
|
return getParts(s, route);
|
|
474
472
|
});
|
|
475
|
-
const generate = getRouteGenerator(segments, config.trailingSlash);
|
|
476
473
|
const index = routes.findIndex((r) => r === fallbackToRoute);
|
|
477
474
|
if (index >= 0) {
|
|
478
475
|
const fallbackRoute = {
|
|
@@ -480,7 +477,6 @@ async function createRoutesList(params, logger, { dev = false } = {}) {
|
|
|
480
477
|
pathname,
|
|
481
478
|
route,
|
|
482
479
|
segments,
|
|
483
|
-
generate,
|
|
484
480
|
pattern: getPattern(segments, config.base, config.trailingSlash),
|
|
485
481
|
type: "fallback",
|
|
486
482
|
fallbackRoutes: []
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { AstroConfig } from '../../../types/public/config.js';
|
|
2
2
|
import type { RoutePart } from '../../../types/public/internal.js';
|
|
3
|
-
|
|
3
|
+
type RouteGenerator = (data?: any) => string;
|
|
4
|
+
export declare function getRouteGenerator(segments: RoutePart[][], addTrailingSlash: AstroConfig['trailingSlash']): RouteGenerator;
|
|
5
|
+
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { GetStaticPathsItem } from '../../types/public/common.js';
|
|
2
|
+
import type { AstroConfig } from '../../types/public/index.js';
|
|
2
3
|
import type { RouteData } from '../../types/public/internal.js';
|
|
3
4
|
/**
|
|
4
5
|
* given a route's Params object, validate parameter
|
|
5
6
|
* values and create a stringified key for the route
|
|
6
7
|
* that can be used to match request routes
|
|
7
8
|
*/
|
|
8
|
-
export declare function stringifyParams(params: GetStaticPathsItem['params'], route: RouteData): string;
|
|
9
|
+
export declare function stringifyParams(params: GetStaticPathsItem['params'], route: RouteData, trailingSlash: AstroConfig['trailingSlash']): string;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { trimSlashes } from "../path.js";
|
|
2
|
+
import { getRouteGenerator } from "./manifest/generator.js";
|
|
2
3
|
import { validateGetStaticPathsParameter } from "./validation.js";
|
|
3
|
-
function stringifyParams(params, route) {
|
|
4
|
-
const validatedParams =
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
function stringifyParams(params, route, trailingSlash) {
|
|
5
|
+
const validatedParams = {};
|
|
6
|
+
for (const [key, value] of Object.entries(params)) {
|
|
7
|
+
validateGetStaticPathsParameter([key, value], route.component);
|
|
7
8
|
if (value !== void 0) {
|
|
8
|
-
|
|
9
|
+
validatedParams[key] = trimSlashes(value);
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return route.generate(validatedParams);
|
|
11
|
+
}
|
|
12
|
+
return getRouteGenerator(route.segments, trailingSlash)(validatedParams);
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
15
15
|
stringifyParams
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ComponentInstance } from '../../types/astro.js';
|
|
2
2
|
import type { GetStaticPathsResult } from '../../types/public/common.js';
|
|
3
3
|
import type { RouteData } from '../../types/public/internal.js';
|
|
4
|
-
import type { Logger } from '../logger/core.js';
|
|
5
4
|
/** Throws error for invalid parameter in getStaticPaths() response */
|
|
6
5
|
export declare function validateGetStaticPathsParameter([key, value]: [string, any], route: string): void;
|
|
7
6
|
/** Error for deprecated or malformed route components */
|
|
@@ -10,4 +9,4 @@ export declare function validateDynamicRouteModule(mod: ComponentInstance, { ssr
|
|
|
10
9
|
route: RouteData;
|
|
11
10
|
}): void;
|
|
12
11
|
/** Throw error and log warnings for malformed getStaticPaths() response */
|
|
13
|
-
export declare function validateGetStaticPathsResult(result: GetStaticPathsResult,
|
|
12
|
+
export declare function validateGetStaticPathsResult(result: GetStaticPathsResult, route: RouteData): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
2
|
-
const VALID_PARAM_TYPES = ["string", "
|
|
2
|
+
const VALID_PARAM_TYPES = ["string", "undefined"];
|
|
3
3
|
function validateGetStaticPathsParameter([key, value], route) {
|
|
4
4
|
if (!VALID_PARAM_TYPES.includes(typeof value)) {
|
|
5
5
|
throw new AstroError({
|
|
@@ -22,7 +22,7 @@ function validateDynamicRouteModule(mod, {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
function validateGetStaticPathsResult(result,
|
|
25
|
+
function validateGetStaticPathsResult(result, route) {
|
|
26
26
|
if (!Array.isArray(result)) {
|
|
27
27
|
throw new AstroError({
|
|
28
28
|
...AstroErrorData.InvalidGetStaticPathsReturn,
|
|
@@ -49,22 +49,6 @@ function validateGetStaticPathsResult(result, logger, route) {
|
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
for (const [key, val] of Object.entries(pathObject.params)) {
|
|
53
|
-
if (!(typeof val === "undefined" || typeof val === "string" || typeof val === "number")) {
|
|
54
|
-
logger.warn(
|
|
55
|
-
"router",
|
|
56
|
-
`getStaticPaths() returned an invalid path param: "${key}". A string, number or undefined value was expected, but got \`${JSON.stringify(
|
|
57
|
-
val
|
|
58
|
-
)}\`.`
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
if (typeof val === "string" && val === "") {
|
|
62
|
-
logger.warn(
|
|
63
|
-
"router",
|
|
64
|
-
`getStaticPaths() returned an invalid path param: "${key}". \`undefined\` expected for an optional param, but got empty string.`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
52
|
});
|
|
69
53
|
}
|
|
70
54
|
export {
|