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,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Params } from '../../types/public/common.js';
|
|
2
2
|
import type { APIContext } from '../../types/public/context.js';
|
|
3
3
|
import { sequence } from './sequence.js';
|
|
4
|
-
declare function defineMiddleware(fn: MiddlewareHandler): MiddlewareHandler;
|
|
5
4
|
/**
|
|
6
5
|
* Payload for creating a context to be passed to Astro middleware
|
|
7
6
|
*/
|
|
@@ -25,7 +24,7 @@ export type CreateContext = {
|
|
|
25
24
|
/**
|
|
26
25
|
* Initial value of the locals
|
|
27
26
|
*/
|
|
28
|
-
locals
|
|
27
|
+
locals?: App.Locals;
|
|
29
28
|
};
|
|
30
29
|
/**
|
|
31
30
|
* Creates a context to be passed to Astro middleware `onRequest` function.
|
|
@@ -43,4 +42,5 @@ declare function createContext({ request, params, userDefinedLocales, defaultLoc
|
|
|
43
42
|
* @param value
|
|
44
43
|
*/
|
|
45
44
|
declare function trySerializeLocals(value: unknown): string;
|
|
46
|
-
export { createContext,
|
|
45
|
+
export { createContext, sequence, trySerializeLocals };
|
|
46
|
+
export { defineMiddleware } from './defineMiddleware.js';
|
|
@@ -4,21 +4,18 @@ import {
|
|
|
4
4
|
computePreferredLocale,
|
|
5
5
|
computePreferredLocaleList
|
|
6
6
|
} from "../../i18n/utils.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ASTRO_GENERATOR } from "../constants.js";
|
|
8
8
|
import { AstroCookies } from "../cookies/index.js";
|
|
9
9
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
10
10
|
import { getClientIpAddress } from "../routing/request.js";
|
|
11
11
|
import { getOriginPathname } from "../routing/rewrite.js";
|
|
12
12
|
import { sequence } from "./sequence.js";
|
|
13
|
-
function defineMiddleware(fn) {
|
|
14
|
-
return fn;
|
|
15
|
-
}
|
|
16
13
|
function createContext({
|
|
17
14
|
request,
|
|
18
15
|
params = {},
|
|
19
16
|
userDefinedLocales = [],
|
|
20
17
|
defaultLocale = "",
|
|
21
|
-
locals
|
|
18
|
+
locals = {}
|
|
22
19
|
}) {
|
|
23
20
|
let preferredLocale = void 0;
|
|
24
21
|
let preferredLocaleList = void 0;
|
|
@@ -34,7 +31,7 @@ function createContext({
|
|
|
34
31
|
request,
|
|
35
32
|
params,
|
|
36
33
|
site: void 0,
|
|
37
|
-
generator:
|
|
34
|
+
generator: ASTRO_GENERATOR,
|
|
38
35
|
props: {},
|
|
39
36
|
rewrite,
|
|
40
37
|
routePattern: "",
|
|
@@ -71,14 +68,10 @@ function createContext({
|
|
|
71
68
|
return clientIpAddress;
|
|
72
69
|
},
|
|
73
70
|
get locals() {
|
|
74
|
-
|
|
75
|
-
if (locals === void 0) {
|
|
76
|
-
_locals = {};
|
|
77
|
-
}
|
|
78
|
-
if (typeof _locals !== "object") {
|
|
71
|
+
if (typeof locals !== "object") {
|
|
79
72
|
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
|
80
73
|
}
|
|
81
|
-
return
|
|
74
|
+
return locals;
|
|
82
75
|
},
|
|
83
76
|
set locals(_) {
|
|
84
77
|
throw new AstroError(AstroErrorData.LocalsReassigned);
|
|
@@ -136,6 +129,7 @@ function trySerializeLocals(value) {
|
|
|
136
129
|
throw new Error("The passed value can't be serialized.");
|
|
137
130
|
}
|
|
138
131
|
}
|
|
132
|
+
import { defineMiddleware } from "./defineMiddleware.js";
|
|
139
133
|
export {
|
|
140
134
|
createContext,
|
|
141
135
|
defineMiddleware,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { pipelineSymbol } from "../constants.js";
|
|
1
2
|
import { ForbiddenRewrite } from "../errors/errors-data.js";
|
|
2
3
|
import { AstroError } from "../errors/index.js";
|
|
3
4
|
import { getParams } from "../render/index.js";
|
|
4
|
-
import { apiContextRoutesSymbol } from "../render-context.js";
|
|
5
5
|
import { setOriginPathname } from "../routing/rewrite.js";
|
|
6
|
-
import { defineMiddleware } from "./
|
|
6
|
+
import { defineMiddleware } from "./defineMiddleware.js";
|
|
7
7
|
function sequence(...handlers) {
|
|
8
8
|
const filtered = handlers.filter((h) => !!h);
|
|
9
9
|
const length = filtered.length;
|
|
@@ -32,12 +32,12 @@ function sequence(...handlers) {
|
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
const oldPathname = handleContext.url.pathname;
|
|
35
|
-
const pipeline = Reflect.get(handleContext,
|
|
35
|
+
const pipeline = Reflect.get(handleContext, pipelineSymbol);
|
|
36
36
|
const { routeData, pathname } = await pipeline.tryRewrite(
|
|
37
37
|
payload,
|
|
38
38
|
handleContext.request
|
|
39
39
|
);
|
|
40
|
-
if (pipeline.serverLike === true && handleContext.isPrerendered === false && routeData.prerender === true) {
|
|
40
|
+
if (pipeline.manifest.serverLike === true && handleContext.isPrerendered === false && routeData.prerender === true) {
|
|
41
41
|
throw new AstroError({
|
|
42
42
|
...ForbiddenRewrite,
|
|
43
43
|
message: ForbiddenRewrite.message(
|
|
@@ -2,7 +2,7 @@ import type { Plugin as VitePlugin } from 'vite';
|
|
|
2
2
|
import type { AstroSettings } from '../../types/astro.js';
|
|
3
3
|
import type { BuildInternals } from '../build/internal.js';
|
|
4
4
|
import type { StaticBuildOptions } from '../build/types.js';
|
|
5
|
-
export declare const MIDDLEWARE_MODULE_ID = "
|
|
5
|
+
export declare const MIDDLEWARE_MODULE_ID = "virtual:astro:middleware";
|
|
6
6
|
export declare function vitePluginMiddleware({ settings }: {
|
|
7
7
|
settings: AstroSettings;
|
|
8
8
|
}): VitePlugin;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getServerOutputDirectory } from "../../prerender/utils.js";
|
|
2
2
|
import { addRollupInput } from "../build/add-rollup-input.js";
|
|
3
|
-
import { MIDDLEWARE_PATH_SEGMENT_NAME } from "../constants.js";
|
|
3
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES, MIDDLEWARE_PATH_SEGMENT_NAME } from "../constants.js";
|
|
4
4
|
import { MissingMiddlewareForInternationalization } from "../errors/errors-data.js";
|
|
5
5
|
import { AstroError } from "../errors/index.js";
|
|
6
6
|
import { normalizePath } from "../viteUtils.js";
|
|
7
|
-
const MIDDLEWARE_MODULE_ID = "
|
|
7
|
+
const MIDDLEWARE_MODULE_ID = "virtual:astro:middleware";
|
|
8
|
+
const MIDDLEWARE_RESOLVED_MODULE_ID = "\0" + MIDDLEWARE_MODULE_ID;
|
|
8
9
|
const NOOP_MIDDLEWARE = "\0noop-middleware";
|
|
9
10
|
function vitePluginMiddleware({ settings }) {
|
|
10
11
|
let resolvedMiddlewareId = void 0;
|
|
@@ -12,6 +13,9 @@ function vitePluginMiddleware({ settings }) {
|
|
|
12
13
|
let userMiddlewareIsPresent = false;
|
|
13
14
|
return {
|
|
14
15
|
name: "@astro/plugin-middleware",
|
|
16
|
+
applyToEnvironment(environment) {
|
|
17
|
+
return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr || environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.astro || environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender;
|
|
18
|
+
},
|
|
15
19
|
async resolveId(id) {
|
|
16
20
|
if (id === MIDDLEWARE_MODULE_ID) {
|
|
17
21
|
const middlewareId = await this.resolve(
|
|
@@ -20,9 +24,9 @@ function vitePluginMiddleware({ settings }) {
|
|
|
20
24
|
userMiddlewareIsPresent = !!middlewareId;
|
|
21
25
|
if (middlewareId) {
|
|
22
26
|
resolvedMiddlewareId = middlewareId.id;
|
|
23
|
-
return
|
|
27
|
+
return MIDDLEWARE_RESOLVED_MODULE_ID;
|
|
24
28
|
} else if (hasIntegrationMiddleware) {
|
|
25
|
-
return
|
|
29
|
+
return MIDDLEWARE_RESOLVED_MODULE_ID;
|
|
26
30
|
} else {
|
|
27
31
|
return NOOP_MIDDLEWARE;
|
|
28
32
|
}
|
|
@@ -37,7 +41,7 @@ function vitePluginMiddleware({ settings }) {
|
|
|
37
41
|
throw new AstroError(MissingMiddlewareForInternationalization);
|
|
38
42
|
}
|
|
39
43
|
return { code: "export const onRequest = (_, next) => next()" };
|
|
40
|
-
} else if (id ===
|
|
44
|
+
} else if (id === MIDDLEWARE_RESOLVED_MODULE_ID) {
|
|
41
45
|
if (!userMiddlewareIsPresent && settings.config.i18n?.routing === "manual") {
|
|
42
46
|
throw new AstroError(MissingMiddlewareForInternationalization);
|
|
43
47
|
}
|
|
@@ -76,14 +80,21 @@ function createMiddlewareImports(entrypoints, prefix) {
|
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
function vitePluginMiddlewareBuild(opts, internals) {
|
|
83
|
+
let canSplitMiddleware = true;
|
|
79
84
|
return {
|
|
80
85
|
name: "@astro/plugin-middleware-build",
|
|
86
|
+
configResolved(config) {
|
|
87
|
+
canSplitMiddleware = config.ssr.target !== "webworker";
|
|
88
|
+
},
|
|
81
89
|
options(options) {
|
|
82
|
-
|
|
90
|
+
if (canSplitMiddleware) {
|
|
91
|
+
return addRollupInput(options, [MIDDLEWARE_MODULE_ID]);
|
|
92
|
+
} else {
|
|
93
|
+
}
|
|
83
94
|
},
|
|
84
95
|
writeBundle(_, bundle) {
|
|
85
96
|
for (const [chunkName, chunk] of Object.entries(bundle)) {
|
|
86
|
-
if (chunk.type !== "asset" && chunk.facadeModuleId ===
|
|
97
|
+
if (chunk.type !== "asset" && chunk.facadeModuleId === MIDDLEWARE_RESOLVED_MODULE_ID) {
|
|
87
98
|
const outputDirectory = getServerOutputDirectory(opts.settings);
|
|
88
99
|
internals.middlewareEntryPoint = new URL(chunkName, outputDirectory);
|
|
89
100
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { LoaderEvents, ModuleInfo, ModuleLoader
|
|
2
|
-
export { createLoader } from './
|
|
1
|
+
export type { LoaderEvents, ModuleInfo, ModuleLoader } from './runner.js';
|
|
2
|
+
export { createLoader } from './runner.js';
|
|
3
3
|
export { createViteLoader } from './vite.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as fs from 'node:fs';
|
|
2
|
+
import type { EnvironmentModuleNode, RunnableDevEnvironment } from 'vite';
|
|
2
3
|
import type { TypedEventEmitter } from '../../types/typed-emitter.js';
|
|
3
4
|
export type LoaderEvents = {
|
|
4
5
|
'file-add': (msg: [path: string, stats?: fs.Stats | undefined]) => void;
|
|
@@ -16,29 +17,17 @@ export type ModuleLoaderEventEmitter = TypedEventEmitter<LoaderEvents>;
|
|
|
16
17
|
export interface ModuleLoader {
|
|
17
18
|
import: (src: string) => Promise<Record<string, any>>;
|
|
18
19
|
resolveId: (specifier: string, parentId: string | undefined) => Promise<string | undefined>;
|
|
19
|
-
getModuleById: (id: string) =>
|
|
20
|
-
getModulesByFile: (file: string) => Set<
|
|
20
|
+
getModuleById: (id: string) => EnvironmentModuleNode | undefined;
|
|
21
|
+
getModulesByFile: (file: string) => Set<EnvironmentModuleNode> | undefined;
|
|
21
22
|
getModuleInfo: (id: string) => ModuleInfo | null;
|
|
22
|
-
eachModule(callbackfn: (value:
|
|
23
|
-
invalidateModule(mod:
|
|
23
|
+
eachModule(callbackfn: (value: EnvironmentModuleNode, key: string, map: Map<string, EnvironmentModuleNode>) => void): void;
|
|
24
|
+
invalidateModule(mod: EnvironmentModuleNode): void;
|
|
24
25
|
fixStacktrace: (error: Error) => void;
|
|
25
26
|
clientReload: () => void;
|
|
26
27
|
webSocketSend: (msg: any) => void;
|
|
27
28
|
isHttps: () => boolean;
|
|
28
29
|
events: TypedEventEmitter<LoaderEvents>;
|
|
29
|
-
|
|
30
|
-
export interface ModuleNode {
|
|
31
|
-
id: string | null;
|
|
32
|
-
url: string;
|
|
33
|
-
file: string | null;
|
|
34
|
-
ssrModule: Record<string, any> | null;
|
|
35
|
-
ssrTransformResult: {
|
|
36
|
-
deps?: string[];
|
|
37
|
-
dynamicDeps?: string[];
|
|
38
|
-
} | null;
|
|
39
|
-
ssrError: Error | null;
|
|
40
|
-
importedModules: Set<ModuleNode>;
|
|
41
|
-
importers: Set<ModuleNode>;
|
|
30
|
+
getSSREnvironment: () => RunnableDevEnvironment;
|
|
42
31
|
}
|
|
43
32
|
export interface ModuleInfo {
|
|
44
33
|
id: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { RunnableDevEnvironment } from 'vite';
|
|
3
|
+
import type { ModuleLoader } from './runner.js';
|
|
4
|
+
export declare function createViteLoader(viteServer: vite.ViteDevServer, ssrEnvironment: RunnableDevEnvironment): ModuleLoader;
|
|
@@ -3,7 +3,8 @@ import path from "node:path";
|
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { collectErrorMetadata } from "../errors/dev/utils.js";
|
|
5
5
|
import { getViteErrorPayload } from "../errors/dev/vite.js";
|
|
6
|
-
|
|
6
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
7
|
+
function createViteLoader(viteServer, ssrEnvironment) {
|
|
7
8
|
const events = new EventEmitter();
|
|
8
9
|
let isTsconfigUpdated = false;
|
|
9
10
|
function isTsconfigUpdate(filePath) {
|
|
@@ -26,8 +27,8 @@ function createViteLoader(viteServer) {
|
|
|
26
27
|
events.emit("file-change", args);
|
|
27
28
|
}
|
|
28
29
|
});
|
|
29
|
-
const _wsSend = viteServer.hot.send;
|
|
30
|
-
viteServer.hot.send = function(...args) {
|
|
30
|
+
const _wsSend = viteServer.environments.client.hot.send;
|
|
31
|
+
viteServer.environments.client.hot.send = function(...args) {
|
|
31
32
|
if (isTsconfigUpdated) {
|
|
32
33
|
isTsconfigUpdated = false;
|
|
33
34
|
return;
|
|
@@ -55,41 +56,44 @@ function createViteLoader(viteServer) {
|
|
|
55
56
|
};
|
|
56
57
|
return {
|
|
57
58
|
import(src) {
|
|
58
|
-
return
|
|
59
|
+
return ssrEnvironment.runner.import(src);
|
|
59
60
|
},
|
|
60
61
|
async resolveId(spec, parent) {
|
|
61
|
-
const ret = await
|
|
62
|
+
const ret = await ssrEnvironment.pluginContainer.resolveId(spec, parent);
|
|
62
63
|
return ret?.id;
|
|
63
64
|
},
|
|
64
65
|
getModuleById(id) {
|
|
65
|
-
return
|
|
66
|
+
return ssrEnvironment.moduleGraph.getModuleById(id);
|
|
66
67
|
},
|
|
67
68
|
getModulesByFile(file) {
|
|
68
|
-
return
|
|
69
|
+
return ssrEnvironment.moduleGraph.getModulesByFile(file);
|
|
69
70
|
},
|
|
70
71
|
getModuleInfo(id) {
|
|
71
|
-
return
|
|
72
|
+
return ssrEnvironment.pluginContainer.getModuleInfo(id);
|
|
72
73
|
},
|
|
73
74
|
eachModule(cb) {
|
|
74
|
-
return
|
|
75
|
+
return ssrEnvironment.moduleGraph.idToModuleMap.forEach(cb);
|
|
75
76
|
},
|
|
76
77
|
invalidateModule(mod) {
|
|
77
|
-
|
|
78
|
+
ssrEnvironment.moduleGraph.invalidateModule(mod);
|
|
78
79
|
},
|
|
79
80
|
fixStacktrace(err) {
|
|
80
81
|
return viteServer.ssrFixStacktrace(err);
|
|
81
82
|
},
|
|
82
83
|
clientReload() {
|
|
83
|
-
viteServer.hot.send({
|
|
84
|
+
viteServer.environments.client.hot.send({
|
|
84
85
|
type: "full-reload",
|
|
85
86
|
path: "*"
|
|
86
87
|
});
|
|
87
88
|
},
|
|
88
89
|
webSocketSend(msg) {
|
|
89
|
-
return viteServer.hot.send(msg);
|
|
90
|
+
return viteServer.environments.client.hot.send(msg);
|
|
91
|
+
},
|
|
92
|
+
getSSREnvironment() {
|
|
93
|
+
return viteServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
|
|
90
94
|
},
|
|
91
95
|
isHttps() {
|
|
92
|
-
return !!
|
|
96
|
+
return !!ssrEnvironment.config.server.https;
|
|
93
97
|
},
|
|
94
98
|
events
|
|
95
99
|
};
|
|
@@ -4,22 +4,28 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
4
4
|
import { AstroIntegrationLogger } from "../../core/logger/core.js";
|
|
5
5
|
import { telemetry } from "../../events/index.js";
|
|
6
6
|
import { eventCliSession } from "../../events/session.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
normalizeCodegenDir,
|
|
9
|
+
runHookConfigDone,
|
|
10
|
+
runHookConfigSetup
|
|
11
|
+
} from "../../integrations/hooks.js";
|
|
8
12
|
import { resolveConfig } from "../config/config.js";
|
|
9
13
|
import { createNodeLogger } from "../config/logging.js";
|
|
10
14
|
import { createSettings } from "../config/settings.js";
|
|
11
|
-
import { apply as applyPolyfills } from "../polyfill.js";
|
|
12
15
|
import { createRoutesList } from "../routing/index.js";
|
|
13
16
|
import { ensureProcessNodeEnv } from "../util.js";
|
|
14
17
|
import createStaticPreviewServer from "./static-preview-server.js";
|
|
15
18
|
import { getResolvedHostForHttpServer } from "./util.js";
|
|
16
19
|
async function preview(inlineConfig) {
|
|
17
|
-
applyPolyfills();
|
|
18
20
|
ensureProcessNodeEnv("production");
|
|
19
21
|
const logger = createNodeLogger(inlineConfig);
|
|
20
22
|
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "preview");
|
|
21
23
|
telemetry.record(eventCliSession("preview", userConfig));
|
|
22
|
-
const _settings = await createSettings(
|
|
24
|
+
const _settings = await createSettings(
|
|
25
|
+
astroConfig,
|
|
26
|
+
inlineConfig.logLevel,
|
|
27
|
+
fileURLToPath(astroConfig.root)
|
|
28
|
+
);
|
|
23
29
|
const settings = await runHookConfigSetup({
|
|
24
30
|
settings: _settings,
|
|
25
31
|
command: "preview",
|
|
@@ -61,7 +67,16 @@ async function preview(inlineConfig) {
|
|
|
61
67
|
port: settings.config.server.port,
|
|
62
68
|
base: settings.config.base,
|
|
63
69
|
logger: new AstroIntegrationLogger(logger.options, settings.adapter.name),
|
|
64
|
-
headers: settings.config.server.headers
|
|
70
|
+
headers: settings.config.server.headers,
|
|
71
|
+
createCodegenDir: () => {
|
|
72
|
+
const codegenDir = new URL(
|
|
73
|
+
normalizeCodegenDir(settings.adapter ? settings.adapter.name : "_temp"),
|
|
74
|
+
settings.dotAstroDir
|
|
75
|
+
);
|
|
76
|
+
fs.mkdirSync(codegenDir, { recursive: true });
|
|
77
|
+
return codegenDir;
|
|
78
|
+
},
|
|
79
|
+
root: settings.config.root
|
|
65
80
|
});
|
|
66
81
|
return server;
|
|
67
82
|
}
|
|
@@ -15,6 +15,7 @@ async function createStaticPreviewServer(settings, logger) {
|
|
|
15
15
|
build: {
|
|
16
16
|
outDir: fileURLToPath(settings.config.outDir)
|
|
17
17
|
},
|
|
18
|
+
root: fileURLToPath(settings.config.root),
|
|
18
19
|
preview: {
|
|
19
20
|
host: settings.config.server.host,
|
|
20
21
|
port: settings.config.server.port,
|
|
@@ -7,8 +7,7 @@ const RedirectComponentInstance = {
|
|
|
7
7
|
};
|
|
8
8
|
const RedirectSinglePageBuiltModule = {
|
|
9
9
|
page: () => Promise.resolve(RedirectComponentInstance),
|
|
10
|
-
onRequest: (_, next) => next()
|
|
11
|
-
renderers: []
|
|
10
|
+
onRequest: (_, next) => next()
|
|
12
11
|
};
|
|
13
12
|
export {
|
|
14
13
|
RedirectComponentInstance,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { RedirectComponentInstance, RedirectSinglePageBuiltModule } from "./component.js";
|
|
2
|
-
import { routeIsRedirect } from "./helpers.js";
|
|
3
2
|
import { getRedirectLocationOrThrow } from "./validate.js";
|
|
4
3
|
export {
|
|
5
4
|
RedirectComponentInstance,
|
|
6
5
|
RedirectSinglePageBuiltModule,
|
|
7
|
-
getRedirectLocationOrThrow
|
|
8
|
-
routeIsRedirect
|
|
6
|
+
getRedirectLocationOrThrow
|
|
9
7
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getRouteGenerator } from "../routing/manifest/generator.js";
|
|
1
2
|
function redirectIsExternal(redirect) {
|
|
2
3
|
if (typeof redirect === "string") {
|
|
3
4
|
return redirect.startsWith("http://") || redirect.startsWith("https://");
|
|
@@ -25,10 +26,12 @@ async function renderRedirect(renderContext) {
|
|
|
25
26
|
function redirectRouteGenerate(renderContext) {
|
|
26
27
|
const {
|
|
27
28
|
params,
|
|
28
|
-
routeData: { redirect, redirectRoute }
|
|
29
|
+
routeData: { redirect, redirectRoute },
|
|
30
|
+
pipeline
|
|
29
31
|
} = renderContext;
|
|
30
32
|
if (typeof redirectRoute !== "undefined") {
|
|
31
|
-
|
|
33
|
+
const generate = getRouteGenerator(redirectRoute.segments, pipeline.manifest.trailingSlash);
|
|
34
|
+
return generate(params) || redirectRoute?.pathname || "/";
|
|
32
35
|
} else if (typeof redirect === "string") {
|
|
33
36
|
if (redirectIsExternal(redirect)) {
|
|
34
37
|
return redirect;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PaginateFunction } from '../../types/public/common.js';
|
|
2
2
|
import type { AstroConfig } from '../../types/public/index.js';
|
|
3
3
|
import type { RouteData } from '../../types/public/internal.js';
|
|
4
|
-
export declare function generatePaginateFunction(routeMatch: RouteData, base: AstroConfig['base']): (...args: Parameters<PaginateFunction>) => ReturnType<PaginateFunction>;
|
|
4
|
+
export declare function generatePaginateFunction(routeMatch: RouteData, base: AstroConfig['base'], trailingSlash: AstroConfig['trailingSlash']): (...args: Parameters<PaginateFunction>) => ReturnType<PaginateFunction>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
2
2
|
import { joinPaths } from "../path.js";
|
|
3
|
-
|
|
3
|
+
import { getRouteGenerator } from "../routing/manifest/generator.js";
|
|
4
|
+
function generatePaginateFunction(routeMatch, base, trailingSlash) {
|
|
4
5
|
return function paginateUtility(data, args = {}) {
|
|
6
|
+
const generate = getRouteGenerator(routeMatch.segments, trailingSlash);
|
|
5
7
|
let { pageSize: _pageSize, params: _params, props: _props } = args;
|
|
6
8
|
const pageSize = _pageSize || 10;
|
|
7
9
|
const paramName = "page";
|
|
@@ -27,23 +29,23 @@ function generatePaginateFunction(routeMatch, base) {
|
|
|
27
29
|
...additionalParams,
|
|
28
30
|
[paramName]: includesFirstPageNumber || pageNum > 1 ? String(pageNum) : void 0
|
|
29
31
|
};
|
|
30
|
-
const current = addRouteBase(
|
|
31
|
-
const next = pageNum === lastPage ? void 0 : addRouteBase(
|
|
32
|
+
const current = addRouteBase(generate({ ...params }), base);
|
|
33
|
+
const next = pageNum === lastPage ? void 0 : addRouteBase(generate({ ...params, page: String(pageNum + 1) }), base);
|
|
32
34
|
const prev = pageNum === 1 ? void 0 : addRouteBase(
|
|
33
|
-
|
|
35
|
+
generate({
|
|
34
36
|
...params,
|
|
35
37
|
page: !includesFirstPageNumber && pageNum - 1 === 1 ? void 0 : String(pageNum - 1)
|
|
36
38
|
}),
|
|
37
39
|
base
|
|
38
40
|
);
|
|
39
41
|
const first = pageNum === 1 ? void 0 : addRouteBase(
|
|
40
|
-
|
|
42
|
+
generate({
|
|
41
43
|
...params,
|
|
42
44
|
page: includesFirstPageNumber ? "1" : void 0
|
|
43
45
|
}),
|
|
44
46
|
base
|
|
45
47
|
);
|
|
46
|
-
const last = pageNum === lastPage ? void 0 : addRouteBase(
|
|
48
|
+
const last = pageNum === lastPage ? void 0 : addRouteBase(generate({ ...params, page: String(lastPage) }), base);
|
|
47
49
|
return {
|
|
48
50
|
params,
|
|
49
51
|
props: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComponentInstance } from '../../types/astro.js';
|
|
2
2
|
import type { Params, Props } from '../../types/public/common.js';
|
|
3
|
+
import type { AstroConfig } from '../../types/public/index.js';
|
|
3
4
|
import type { RouteData } from '../../types/public/internal.js';
|
|
4
5
|
import type { Logger } from '../logger/core.js';
|
|
5
6
|
import type { RouteCache } from './route-cache.js';
|
|
@@ -11,6 +12,7 @@ interface GetParamsAndPropsOptions {
|
|
|
11
12
|
logger: Logger;
|
|
12
13
|
serverLike: boolean;
|
|
13
14
|
base: string;
|
|
15
|
+
trailingSlash: AstroConfig['trailingSlash'];
|
|
14
16
|
}
|
|
15
17
|
export declare function getProps(opts: GetParamsAndPropsOptions): Promise<Props>;
|
|
16
18
|
/**
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
|
2
2
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
3
|
-
import { routeIsFallback } from "../
|
|
4
|
-
import { routeIsRedirect } from "../redirects/index.js";
|
|
3
|
+
import { routeIsFallback, routeIsRedirect } from "../routing/helpers.js";
|
|
5
4
|
import { callGetStaticPaths, findPathItemByKey } from "./route-cache.js";
|
|
6
5
|
async function getProps(opts) {
|
|
7
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
logger,
|
|
8
|
+
mod,
|
|
9
|
+
routeData: route,
|
|
10
|
+
routeCache,
|
|
11
|
+
pathname,
|
|
12
|
+
serverLike,
|
|
13
|
+
base,
|
|
14
|
+
trailingSlash
|
|
15
|
+
} = opts;
|
|
8
16
|
if (!route || route.pathname) {
|
|
9
17
|
return {};
|
|
10
18
|
}
|
|
@@ -15,12 +23,12 @@ async function getProps(opts) {
|
|
|
15
23
|
mod,
|
|
16
24
|
route,
|
|
17
25
|
routeCache,
|
|
18
|
-
logger,
|
|
19
26
|
ssr: serverLike,
|
|
20
|
-
base
|
|
27
|
+
base,
|
|
28
|
+
trailingSlash
|
|
21
29
|
});
|
|
22
30
|
const params = getParams(route, pathname);
|
|
23
|
-
const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger);
|
|
31
|
+
const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger, trailingSlash);
|
|
24
32
|
if (!matchedStaticPath && (serverLike ? route.prerender : true)) {
|
|
25
33
|
throw new AstroError({
|
|
26
34
|
...AstroErrorData.NoMatchingStaticPathFound,
|
|
@@ -36,7 +44,11 @@ async function getProps(opts) {
|
|
|
36
44
|
}
|
|
37
45
|
function getParams(route, pathname) {
|
|
38
46
|
if (!route.params.length) return {};
|
|
39
|
-
|
|
47
|
+
let path = pathname;
|
|
48
|
+
if (pathname.endsWith(".html")) {
|
|
49
|
+
path = path.slice(0, -5);
|
|
50
|
+
}
|
|
51
|
+
const paramsMatch = route.pattern.exec(path) || route.fallbackRoutes.map((fallbackRoute) => fallbackRoute.pattern.exec(path)).find((x) => x);
|
|
40
52
|
if (!paramsMatch) return {};
|
|
41
53
|
const params = {};
|
|
42
54
|
route.params.forEach((key, i) => {
|
|
@@ -7,11 +7,11 @@ interface CallGetStaticPathsOptions {
|
|
|
7
7
|
mod: ComponentInstance | undefined;
|
|
8
8
|
route: RouteData;
|
|
9
9
|
routeCache: RouteCache;
|
|
10
|
-
logger: Logger;
|
|
11
10
|
ssr: boolean;
|
|
12
11
|
base: AstroConfig['base'];
|
|
12
|
+
trailingSlash: AstroConfig['trailingSlash'];
|
|
13
13
|
}
|
|
14
|
-
export declare function callGetStaticPaths({ mod, route, routeCache,
|
|
14
|
+
export declare function callGetStaticPaths({ mod, route, routeCache, ssr, base, trailingSlash, }: CallGetStaticPathsOptions): Promise<GetStaticPathsResultKeyed>;
|
|
15
15
|
interface RouteCacheEntry {
|
|
16
16
|
staticPaths: GetStaticPathsResultKeyed;
|
|
17
17
|
}
|
|
@@ -31,5 +31,5 @@ export declare class RouteCache {
|
|
|
31
31
|
get(route: RouteData): RouteCacheEntry | undefined;
|
|
32
32
|
key(route: RouteData): string;
|
|
33
33
|
}
|
|
34
|
-
export declare function findPathItemByKey(staticPaths: GetStaticPathsResultKeyed, params: Params, route: RouteData, logger: Logger): GetStaticPathsItem | undefined;
|
|
34
|
+
export declare function findPathItemByKey(staticPaths: GetStaticPathsResultKeyed, params: Params, route: RouteData, logger: Logger, trailingSlash: AstroConfig['trailingSlash']): GetStaticPathsItem | undefined;
|
|
35
35
|
export {};
|
|
@@ -5,9 +5,9 @@ async function callGetStaticPaths({
|
|
|
5
5
|
mod,
|
|
6
6
|
route,
|
|
7
7
|
routeCache,
|
|
8
|
-
logger,
|
|
9
8
|
ssr,
|
|
10
|
-
base
|
|
9
|
+
base,
|
|
10
|
+
trailingSlash
|
|
11
11
|
}) {
|
|
12
12
|
const cached = routeCache.get(route);
|
|
13
13
|
if (!mod) {
|
|
@@ -29,14 +29,14 @@ async function callGetStaticPaths({
|
|
|
29
29
|
staticPaths = await mod.getStaticPaths({
|
|
30
30
|
// Q: Why the cast?
|
|
31
31
|
// A: So users downstream can have nicer typings, we have to make some sacrifice in our internal typings, which necessitate a cast here
|
|
32
|
-
paginate: generatePaginateFunction(route, base),
|
|
32
|
+
paginate: generatePaginateFunction(route, base, trailingSlash),
|
|
33
33
|
routePattern: route.route
|
|
34
34
|
});
|
|
35
|
-
validateGetStaticPathsResult(staticPaths,
|
|
35
|
+
validateGetStaticPathsResult(staticPaths, route);
|
|
36
36
|
const keyedStaticPaths = staticPaths;
|
|
37
37
|
keyedStaticPaths.keyed = /* @__PURE__ */ new Map();
|
|
38
38
|
for (const sp of keyedStaticPaths) {
|
|
39
|
-
const paramsKey = stringifyParams(sp.params, route);
|
|
39
|
+
const paramsKey = stringifyParams(sp.params, route, trailingSlash);
|
|
40
40
|
keyedStaticPaths.keyed.set(paramsKey, sp);
|
|
41
41
|
}
|
|
42
42
|
routeCache.set(route, { ...cached, staticPaths: keyedStaticPaths });
|
|
@@ -68,8 +68,8 @@ class RouteCache {
|
|
|
68
68
|
return `${route.route}_${route.component}`;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
function findPathItemByKey(staticPaths, params, route, logger) {
|
|
72
|
-
const paramsKey = stringifyParams(params, route);
|
|
71
|
+
function findPathItemByKey(staticPaths, params, route, logger, trailingSlash) {
|
|
72
|
+
const paramsKey = stringifyParams(params, route, trailingSlash);
|
|
73
73
|
const matchedStaticPath = staticPaths.keyed.get(paramsKey);
|
|
74
74
|
if (matchedStaticPath) {
|
|
75
75
|
return matchedStaticPath;
|