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,22 +1,22 @@
|
|
|
1
1
|
import npath from "node:path";
|
|
2
|
+
import { isCSSRequest } from "vite";
|
|
2
3
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../core/constants.js";
|
|
3
4
|
import { unwrapId } from "../core/util.js";
|
|
4
5
|
import { hasSpecialQueries } from "../vite-plugin-utils/index.js";
|
|
5
|
-
import { isCSSRequest } from "./util.js";
|
|
6
6
|
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ".mdoc", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
|
|
7
7
|
const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
|
|
8
|
-
async function* crawlGraph(
|
|
8
|
+
async function* crawlGraph(environment, _id, isRootFile, scanned = /* @__PURE__ */ new Set()) {
|
|
9
9
|
const id = unwrapId(_id);
|
|
10
10
|
const importedModules = /* @__PURE__ */ new Set();
|
|
11
11
|
const moduleEntriesForId = isRootFile ? (
|
|
12
12
|
// "getModulesByFile" pulls from a delayed module cache (fun implementation detail),
|
|
13
13
|
// So we can get up-to-date info on initial server load.
|
|
14
14
|
// Needed for slower CSS preprocessing like Tailwind
|
|
15
|
-
|
|
15
|
+
environment.moduleGraph.getModulesByFile(id) ?? /* @__PURE__ */ new Set()
|
|
16
16
|
) : (
|
|
17
17
|
// For non-root files, we're safe to pull from "getModuleById" based on testing.
|
|
18
18
|
// TODO: Find better invalidation strategy to use "getModuleById" in all cases!
|
|
19
|
-
/* @__PURE__ */ new Set([
|
|
19
|
+
/* @__PURE__ */ new Set([environment.moduleGraph.getModuleById(id)])
|
|
20
20
|
);
|
|
21
21
|
for (const entry of moduleEntriesForId) {
|
|
22
22
|
if (!entry) {
|
|
@@ -37,10 +37,10 @@ async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ ne
|
|
|
37
37
|
const isPropagationStoppingPoint = importedModule.id.includes("?astroPropagatedAssets");
|
|
38
38
|
if (isFileTypeNeedingSSR && // Should not SSR a module with ?astroPropagatedAssets
|
|
39
39
|
!isPropagationStoppingPoint) {
|
|
40
|
-
const mod =
|
|
40
|
+
const mod = environment.moduleGraph.getModuleById(importedModule.id);
|
|
41
41
|
if (!mod?.ssrModule) {
|
|
42
42
|
try {
|
|
43
|
-
await
|
|
43
|
+
await environment.runner.import(importedModule.id);
|
|
44
44
|
} catch {
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -56,7 +56,7 @@ async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ ne
|
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
58
|
yield importedModule;
|
|
59
|
-
yield* crawlGraph(
|
|
59
|
+
yield* crawlGraph(environment, importedModule.id, false, scanned);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
function isImportedBy(parent, entry) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { normalizePath } from "vite";
|
|
3
4
|
const getConfigAlias = (settings) => {
|
|
@@ -30,6 +31,39 @@ const getConfigAlias = (settings) => {
|
|
|
30
31
|
}
|
|
31
32
|
return aliases;
|
|
32
33
|
};
|
|
34
|
+
const getViteResolveAlias = (settings) => {
|
|
35
|
+
const { tsConfig, tsConfigPath } = settings;
|
|
36
|
+
if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions) return [];
|
|
37
|
+
const { baseUrl, paths } = tsConfig.compilerOptions;
|
|
38
|
+
const effectiveBaseUrl = baseUrl ?? (paths ? "." : void 0);
|
|
39
|
+
if (!effectiveBaseUrl) return [];
|
|
40
|
+
const resolvedBaseUrl = path.resolve(path.dirname(tsConfigPath), effectiveBaseUrl);
|
|
41
|
+
const aliases = [];
|
|
42
|
+
if (paths) {
|
|
43
|
+
for (const [aliasPattern, values] of Object.entries(paths)) {
|
|
44
|
+
const resolvedValues = values.map((v) => path.resolve(resolvedBaseUrl, v));
|
|
45
|
+
const customResolver = (id) => {
|
|
46
|
+
for (const resolvedValue of resolvedValues) {
|
|
47
|
+
const resolved = resolvedValue.replace("*", id);
|
|
48
|
+
if (fs.existsSync(resolved)) {
|
|
49
|
+
return resolved;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
};
|
|
54
|
+
aliases.push({
|
|
55
|
+
// Build regex from alias pattern (e.g., '@styles/*' -> /^@styles\/(.+)$/)
|
|
56
|
+
// First, escape special regex chars. Then replace * with a capture group (.+)
|
|
57
|
+
find: new RegExp(
|
|
58
|
+
`^${aliasPattern.replace(/[\\^$+?.()|[\]{}]/g, "\\$&").replace(/\*/g, "(.+)")}$`
|
|
59
|
+
),
|
|
60
|
+
replacement: aliasPattern.includes("*") ? "$1" : aliasPattern,
|
|
61
|
+
customResolver
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return aliases;
|
|
66
|
+
};
|
|
33
67
|
function configAliasVitePlugin({
|
|
34
68
|
settings
|
|
35
69
|
}) {
|
|
@@ -39,8 +73,12 @@ function configAliasVitePlugin({
|
|
|
39
73
|
name: "astro:tsconfig-alias",
|
|
40
74
|
// use post to only resolve ids that all other plugins before it can't
|
|
41
75
|
enforce: "post",
|
|
42
|
-
|
|
43
|
-
|
|
76
|
+
config() {
|
|
77
|
+
return {
|
|
78
|
+
resolve: {
|
|
79
|
+
alias: getViteResolveAlias(settings)
|
|
80
|
+
}
|
|
81
|
+
};
|
|
44
82
|
},
|
|
45
83
|
async resolveId(id, importer, options) {
|
|
46
84
|
if (isVirtualId(id)) return;
|
|
@@ -58,36 +96,6 @@ function configAliasVitePlugin({
|
|
|
58
96
|
};
|
|
59
97
|
return plugin;
|
|
60
98
|
}
|
|
61
|
-
function patchCreateResolver(config, postPlugin) {
|
|
62
|
-
const _createResolver = config.createResolver;
|
|
63
|
-
config.createResolver = function(...args1) {
|
|
64
|
-
const resolver = _createResolver.apply(config, args1);
|
|
65
|
-
return async function(...args2) {
|
|
66
|
-
const id = args2[0];
|
|
67
|
-
const importer = args2[1];
|
|
68
|
-
const ssr = args2[3];
|
|
69
|
-
if (importer?.includes("node_modules")) {
|
|
70
|
-
return resolver.apply(_createResolver, args2);
|
|
71
|
-
}
|
|
72
|
-
const fakePluginContext = {
|
|
73
|
-
resolve: (_id, _importer) => resolver(_id, _importer, false, ssr)
|
|
74
|
-
};
|
|
75
|
-
const fakeResolveIdOpts = {
|
|
76
|
-
assertions: {},
|
|
77
|
-
isEntry: false,
|
|
78
|
-
ssr
|
|
79
|
-
};
|
|
80
|
-
const result = await resolver.apply(_createResolver, args2);
|
|
81
|
-
if (result) return result;
|
|
82
|
-
const resolved = await postPlugin.resolveId.apply(fakePluginContext, [
|
|
83
|
-
id,
|
|
84
|
-
importer,
|
|
85
|
-
fakeResolveIdOpts
|
|
86
|
-
]);
|
|
87
|
-
if (resolved) return resolved;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
99
|
function isVirtualId(id) {
|
|
92
100
|
return id.includes("\0") || id.startsWith("virtual:") || id.startsWith("astro:");
|
|
93
101
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { RoutesList } from '../types/astro.js';
|
|
3
|
+
interface AstroVitePluginOptions {
|
|
4
|
+
routesList: RoutesList;
|
|
5
|
+
command: 'dev' | 'build';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* This plugin tracks the CSS that should be applied by route.
|
|
9
|
+
*
|
|
10
|
+
* The virtual module should be used only during development.
|
|
11
|
+
* Per-route virtual modules are created to avoid invalidation loops.
|
|
12
|
+
*
|
|
13
|
+
* The second plugin imports all of the individual CSS modules in a map.
|
|
14
|
+
*
|
|
15
|
+
* @param routesList
|
|
16
|
+
*/
|
|
17
|
+
export declare function astroDevCssPlugin({ routesList, command }: AstroVitePluginOptions): Plugin[];
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { wrapId } from "../core/util.js";
|
|
2
|
+
import { isBuildableCSSRequest } from "../vite-plugin-astro-server/util.js";
|
|
3
|
+
import { getVirtualModulePageNameForComponent } from "../vite-plugin-pages/util.js";
|
|
4
|
+
import { getDevCSSModuleName } from "./util.js";
|
|
5
|
+
import { prependForwardSlash } from "@astrojs/internal-helpers/path";
|
|
6
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
7
|
+
const MODULE_DEV_CSS = "virtual:astro:dev-css";
|
|
8
|
+
const RESOLVED_MODULE_DEV_CSS = "\0" + MODULE_DEV_CSS;
|
|
9
|
+
const MODULE_DEV_CSS_PREFIX = "virtual:astro:dev-css:";
|
|
10
|
+
const RESOLVED_MODULE_DEV_CSS_PREFIX = "\0" + MODULE_DEV_CSS_PREFIX;
|
|
11
|
+
const MODULE_DEV_CSS_ALL = "virtual:astro:dev-css-all";
|
|
12
|
+
const RESOLVED_MODULE_DEV_CSS_ALL = "\0" + MODULE_DEV_CSS_ALL;
|
|
13
|
+
const ASTRO_CSS_EXTENSION_POST_PATTERN = "@_@";
|
|
14
|
+
function getComponentFromVirtualModuleCssName(virtualModulePrefix, id) {
|
|
15
|
+
return id.slice(virtualModulePrefix.length).replace(new RegExp(ASTRO_CSS_EXTENSION_POST_PATTERN, "g"), ".");
|
|
16
|
+
}
|
|
17
|
+
function* collectCSSWithOrder(id, mod, seen = /* @__PURE__ */ new Set()) {
|
|
18
|
+
seen.add(id);
|
|
19
|
+
const imported = Array.from(mod.importedModules);
|
|
20
|
+
if (isBuildableCSSRequest(id)) {
|
|
21
|
+
yield {
|
|
22
|
+
id: wrapId(mod.id ?? mod.url),
|
|
23
|
+
idKey: id,
|
|
24
|
+
content: "",
|
|
25
|
+
url: prependForwardSlash(wrapId(mod.url))
|
|
26
|
+
};
|
|
27
|
+
return;
|
|
28
|
+
} else if (id.endsWith("?raw")) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const imp of imported) {
|
|
32
|
+
if (imp.id && !seen.has(imp?.id)) {
|
|
33
|
+
yield* collectCSSWithOrder(imp.id, imp, seen);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function astroDevCssPlugin({ routesList, command }) {
|
|
38
|
+
let environment = void 0;
|
|
39
|
+
const cssContentCache = /* @__PURE__ */ new Map();
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
name: MODULE_DEV_CSS,
|
|
43
|
+
async configureServer(server) {
|
|
44
|
+
environment = server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
|
|
45
|
+
},
|
|
46
|
+
resolveId(id) {
|
|
47
|
+
if (id === MODULE_DEV_CSS) {
|
|
48
|
+
return RESOLVED_MODULE_DEV_CSS;
|
|
49
|
+
}
|
|
50
|
+
if (id.startsWith(MODULE_DEV_CSS_PREFIX)) {
|
|
51
|
+
return RESOLVED_MODULE_DEV_CSS_PREFIX + id.slice(MODULE_DEV_CSS_PREFIX.length);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
async load(id) {
|
|
55
|
+
if (id === RESOLVED_MODULE_DEV_CSS) {
|
|
56
|
+
return {
|
|
57
|
+
code: `export const css = new Set()`
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (id.startsWith(RESOLVED_MODULE_DEV_CSS_PREFIX)) {
|
|
61
|
+
const componentPath = getComponentFromVirtualModuleCssName(
|
|
62
|
+
RESOLVED_MODULE_DEV_CSS_PREFIX,
|
|
63
|
+
id
|
|
64
|
+
);
|
|
65
|
+
const cssWithOrder = /* @__PURE__ */ new Map();
|
|
66
|
+
const componentPageId = getVirtualModulePageNameForComponent(componentPath);
|
|
67
|
+
await environment?.runner?.import(componentPageId);
|
|
68
|
+
const resolved = await environment?.pluginContainer.resolveId(componentPageId);
|
|
69
|
+
if (!resolved?.id) {
|
|
70
|
+
return {
|
|
71
|
+
code: "export const css = new Set()"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const mod = environment?.moduleGraph.getModuleById(resolved.id);
|
|
75
|
+
if (!mod) {
|
|
76
|
+
return {
|
|
77
|
+
code: "export const css = new Set()"
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
for (const collected of collectCSSWithOrder(componentPageId, mod)) {
|
|
81
|
+
if (!cssWithOrder.has(collected.idKey)) {
|
|
82
|
+
const content = cssContentCache.get(collected.id) || collected.content;
|
|
83
|
+
cssWithOrder.set(collected.idKey, { ...collected, content });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const cssArray = Array.from(cssWithOrder.values());
|
|
87
|
+
const cleanedCss = cssArray.map(({ content, id: cssId, url }) => ({
|
|
88
|
+
content,
|
|
89
|
+
id: cssId,
|
|
90
|
+
url
|
|
91
|
+
}));
|
|
92
|
+
return {
|
|
93
|
+
code: `export const css = new Set(${JSON.stringify(cleanedCss)})`
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
async transform(code, id) {
|
|
98
|
+
if (command === "build") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (isBuildableCSSRequest(id)) {
|
|
102
|
+
const mod = environment?.moduleGraph.getModuleById(id);
|
|
103
|
+
if (mod) {
|
|
104
|
+
cssContentCache.set(id, code);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: MODULE_DEV_CSS_ALL,
|
|
111
|
+
resolveId(id) {
|
|
112
|
+
if (id === MODULE_DEV_CSS_ALL) {
|
|
113
|
+
return RESOLVED_MODULE_DEV_CSS_ALL;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
load(id) {
|
|
117
|
+
if (id === RESOLVED_MODULE_DEV_CSS_ALL) {
|
|
118
|
+
let code = `export const devCSSMap = new Map([`;
|
|
119
|
+
for (const route of routesList.routes) {
|
|
120
|
+
code += `
|
|
121
|
+
[${JSON.stringify(route.component)}, () => import(${JSON.stringify(getDevCSSModuleName(route.component))})],`;
|
|
122
|
+
}
|
|
123
|
+
code += "]);";
|
|
124
|
+
return {
|
|
125
|
+
code
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
export {
|
|
133
|
+
astroDevCssPlugin
|
|
134
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getVirtualModulePageName } from "../vite-plugin-pages/util.js";
|
|
2
|
+
const MODULE_DEV_CSS_PREFIX = "virtual:astro:dev-css:";
|
|
3
|
+
function getDevCSSModuleName(componentPath) {
|
|
4
|
+
return getVirtualModulePageName(MODULE_DEV_CSS_PREFIX, componentPath);
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
getDevCSSModuleName
|
|
8
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as vite from 'vite';
|
|
2
|
+
import type { AstroSettings } from '../types/astro.js';
|
|
3
|
+
import type { CrawlFrameworkPkgsResult } from 'vitefu';
|
|
4
|
+
interface Payload {
|
|
5
|
+
command: 'dev' | 'build';
|
|
6
|
+
settings: AstroSettings;
|
|
7
|
+
astroPkgsConfig: CrawlFrameworkPkgsResult;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* This plugin is responsible of setting up the environments of the vite server, such as
|
|
11
|
+
* dependencies, SSR, etc.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare function vitePluginEnvironment({ command, settings, astroPkgsConfig, }: Payload): vite.Plugin;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
2
|
+
import { convertPathToPattern } from "tinyglobby";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const ONLY_DEV_EXTERNAL = [
|
|
5
|
+
// Imported by `@astrojs/prism` which exposes `<Prism/>` that is processed by Vite
|
|
6
|
+
"prismjs/components/index.js",
|
|
7
|
+
// Imported by `astro/assets` -> `packages/astro/src/core/logger/core.ts`
|
|
8
|
+
"string-width",
|
|
9
|
+
// Imported by `astro:transitions` -> packages/astro/src/runtime/server/transition.ts
|
|
10
|
+
"cssesc"
|
|
11
|
+
];
|
|
12
|
+
const ALWAYS_NOEXTERNAL = [
|
|
13
|
+
// This is only because Vite's native ESM doesn't resolve "exports" correctly.
|
|
14
|
+
"astro",
|
|
15
|
+
// Vite fails on nested `.astro` imports without bundling
|
|
16
|
+
"astro/components",
|
|
17
|
+
// Handle recommended nanostores. Only @nanostores/preact is required from our testing!
|
|
18
|
+
// Full explanation and related bug report: https://github.com/withastro/astro/pull/3667
|
|
19
|
+
"@nanostores/preact",
|
|
20
|
+
// fontsource packages are CSS that need to be processed
|
|
21
|
+
"@fontsource/*"
|
|
22
|
+
];
|
|
23
|
+
function vitePluginEnvironment({
|
|
24
|
+
command,
|
|
25
|
+
settings,
|
|
26
|
+
astroPkgsConfig
|
|
27
|
+
}) {
|
|
28
|
+
const srcDirPattern = convertPathToPattern(fileURLToPath(settings.config.srcDir));
|
|
29
|
+
return {
|
|
30
|
+
name: "astro:environment",
|
|
31
|
+
configEnvironment(environmentName, _options) {
|
|
32
|
+
const finalEnvironmentOptions = {
|
|
33
|
+
optimizeDeps: {
|
|
34
|
+
include: [],
|
|
35
|
+
exclude: []
|
|
36
|
+
},
|
|
37
|
+
resolve: {
|
|
38
|
+
// Astro imports in third-party packages should use the same version as root
|
|
39
|
+
dedupe: ["astro"]
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.ssr || environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.astro || environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.prerender || environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.client) {
|
|
43
|
+
if (_options.resolve?.noExternal !== true) {
|
|
44
|
+
finalEnvironmentOptions.resolve.noExternal = [
|
|
45
|
+
...ALWAYS_NOEXTERNAL,
|
|
46
|
+
...astroPkgsConfig.ssr.noExternal
|
|
47
|
+
];
|
|
48
|
+
finalEnvironmentOptions.resolve.external = [
|
|
49
|
+
...command === "dev" ? ONLY_DEV_EXTERNAL : [],
|
|
50
|
+
...astroPkgsConfig.ssr.external
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
if (_options.optimizeDeps?.noDiscovery === false) {
|
|
54
|
+
finalEnvironmentOptions.optimizeDeps = {
|
|
55
|
+
entries: [`${srcDirPattern}**/*.{jsx,tsx,vue,svelte,html,astro}`],
|
|
56
|
+
include: [],
|
|
57
|
+
exclude: ["node-fetch"]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (environmentName === ASTRO_VITE_ENVIRONMENT_NAMES.client) {
|
|
62
|
+
finalEnvironmentOptions.optimizeDeps = {
|
|
63
|
+
include: [
|
|
64
|
+
// For the dev toolbar
|
|
65
|
+
"astro > html-escaper"
|
|
66
|
+
],
|
|
67
|
+
// Astro files can't be rendered on the client
|
|
68
|
+
entries: [`${srcDirPattern}**/*.{jsx,tsx,vue,svelte,html}`]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return finalEnvironmentOptions;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
vitePluginEnvironment
|
|
77
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
2
|
import type { BuildInternals } from '../core/build/internal.js';
|
|
3
|
-
import type { AstroBuildPlugin } from '../core/build/plugin.js';
|
|
4
3
|
export default function configHeadVitePlugin(): vite.Plugin;
|
|
5
|
-
export declare function astroHeadBuildPlugin(internals: BuildInternals):
|
|
4
|
+
export declare function astroHeadBuildPlugin(internals: BuildInternals): vite.Plugin;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { getParentModuleInfos, getTopLevelPageModuleInfos } from "../core/build/graph.js";
|
|
2
2
|
import { getAstroMetadata } from "../vite-plugin-astro/index.js";
|
|
3
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
3
4
|
const injectExp = /(?:^\/\/|\/\/!)\s*astro-head-inject/;
|
|
4
5
|
function configHeadVitePlugin() {
|
|
5
|
-
let
|
|
6
|
+
let environment;
|
|
6
7
|
function propagateMetadata(id, prop, value, seen = /* @__PURE__ */ new Set()) {
|
|
7
8
|
if (seen.has(id)) return;
|
|
8
9
|
seen.add(id);
|
|
9
|
-
const mod =
|
|
10
|
+
const mod = environment.moduleGraph.getModuleById(id);
|
|
10
11
|
const info = this.getModuleInfo(id);
|
|
11
12
|
if (info?.meta.astro) {
|
|
12
13
|
const astroMetadata = getAstroMetadata(info);
|
|
@@ -24,8 +25,8 @@ function configHeadVitePlugin() {
|
|
|
24
25
|
name: "astro:head-metadata",
|
|
25
26
|
enforce: "pre",
|
|
26
27
|
apply: "serve",
|
|
27
|
-
configureServer(
|
|
28
|
-
|
|
28
|
+
configureServer(server) {
|
|
29
|
+
environment = server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
|
|
29
30
|
},
|
|
30
31
|
resolveId(source, importer) {
|
|
31
32
|
if (importer) {
|
|
@@ -47,21 +48,10 @@ function configHeadVitePlugin() {
|
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
50
|
transform(source, id) {
|
|
50
|
-
if (!server) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
51
|
let info = this.getModuleInfo(id);
|
|
54
52
|
if (info && getAstroMetadata(info)?.containsHead) {
|
|
55
53
|
propagateMetadata.call(this, id, "containsHead", true);
|
|
56
54
|
}
|
|
57
|
-
if (info && getAstroMetadata(info)?.propagation === "self") {
|
|
58
|
-
const mod = server.moduleGraph.getModuleById(id);
|
|
59
|
-
for (const parent of mod?.importers ?? []) {
|
|
60
|
-
if (parent.id) {
|
|
61
|
-
propagateMetadata.call(this, parent.id, "propagation", "in-tree");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
55
|
if (injectExp.test(source)) {
|
|
66
56
|
propagateMetadata.call(this, id, "propagation", "in-tree");
|
|
67
57
|
}
|
|
@@ -70,54 +60,48 @@ function configHeadVitePlugin() {
|
|
|
70
60
|
}
|
|
71
61
|
function astroHeadBuildPlugin(internals) {
|
|
72
62
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
63
|
+
name: "astro:head-metadata-build",
|
|
64
|
+
applyToEnvironment(environment) {
|
|
65
|
+
return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr || environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender;
|
|
66
|
+
},
|
|
67
|
+
generateBundle(_opts, bundle) {
|
|
68
|
+
const map = internals.componentMetadata;
|
|
69
|
+
function getOrCreateMetadata(id) {
|
|
70
|
+
if (map.has(id)) return map.get(id);
|
|
71
|
+
const metadata = {
|
|
72
|
+
propagation: "none",
|
|
73
|
+
containsHead: false
|
|
74
|
+
};
|
|
75
|
+
map.set(id, metadata);
|
|
76
|
+
return metadata;
|
|
77
|
+
}
|
|
78
|
+
for (const [, output] of Object.entries(bundle)) {
|
|
79
|
+
if (output.type !== "chunk") continue;
|
|
80
|
+
for (const [id, mod] of Object.entries(output.modules)) {
|
|
81
|
+
const modinfo = this.getModuleInfo(id);
|
|
82
|
+
if (modinfo) {
|
|
83
|
+
const meta = getAstroMetadata(modinfo);
|
|
84
|
+
if (meta?.containsHead) {
|
|
85
|
+
for (const pageInfo of getTopLevelPageModuleInfos(id, this)) {
|
|
86
|
+
let metadata = getOrCreateMetadata(pageInfo.id);
|
|
87
|
+
metadata.containsHead = true;
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (meta?.containsHead) {
|
|
97
|
-
for (const pageInfo of getTopLevelPageModuleInfos(id, this)) {
|
|
98
|
-
let metadata = getOrCreateMetadata(pageInfo.id);
|
|
99
|
-
metadata.containsHead = true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (meta?.propagation === "self") {
|
|
103
|
-
for (const info of getParentModuleInfos(id, this)) {
|
|
104
|
-
let metadata = getOrCreateMetadata(info.id);
|
|
105
|
-
if (metadata.propagation !== "self") {
|
|
106
|
-
metadata.propagation = "in-tree";
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (mod.code && injectExp.test(mod.code)) {
|
|
112
|
-
for (const info of getParentModuleInfos(id, this)) {
|
|
113
|
-
getOrCreateMetadata(info.id).propagation = "in-tree";
|
|
114
|
-
}
|
|
115
|
-
}
|
|
89
|
+
}
|
|
90
|
+
if (meta?.propagation === "self") {
|
|
91
|
+
for (const info of getParentModuleInfos(id, this)) {
|
|
92
|
+
let metadata = getOrCreateMetadata(info.id);
|
|
93
|
+
if (metadata.propagation !== "self") {
|
|
94
|
+
metadata.propagation = "in-tree";
|
|
116
95
|
}
|
|
117
96
|
}
|
|
118
97
|
}
|
|
119
98
|
}
|
|
120
|
-
|
|
99
|
+
if (mod.code && injectExp.test(mod.code)) {
|
|
100
|
+
for (const info of getParentModuleInfos(id, this)) {
|
|
101
|
+
getOrCreateMetadata(info.id).propagation = "in-tree";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
121
105
|
}
|
|
122
106
|
}
|
|
123
107
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
1
2
|
function hmrReload() {
|
|
2
3
|
return {
|
|
3
4
|
name: "astro:hmr-reload",
|
|
@@ -5,7 +6,7 @@ function hmrReload() {
|
|
|
5
6
|
hotUpdate: {
|
|
6
7
|
order: "post",
|
|
7
8
|
handler({ modules, server, timestamp }) {
|
|
8
|
-
if (this.environment.name !==
|
|
9
|
+
if (this.environment.name !== ASTRO_VITE_ENVIRONMENT_NAMES.ssr) return;
|
|
9
10
|
let hasSsrOnlyModules = false;
|
|
10
11
|
const invalidatedModules = /* @__PURE__ */ new Set();
|
|
11
12
|
for (const mod of modules) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { prependForwardSlash } from "../core/path.js";
|
|
2
|
+
import { DEFAULT_COMPONENTS } from "../core/routing/default.js";
|
|
3
|
+
import { routeIsRedirect } from "../core/routing/index.js";
|
|
4
|
+
import { VIRTUAL_PAGE_MODULE_ID, VIRTUAL_PAGE_RESOLVED_MODULE_ID } from "./const.js";
|
|
5
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
6
|
+
function pluginPage({ routesList }) {
|
|
7
|
+
return {
|
|
8
|
+
name: "@astro/plugin-page",
|
|
9
|
+
applyToEnvironment(environment) {
|
|
10
|
+
return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr || environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender;
|
|
11
|
+
},
|
|
12
|
+
resolveId(id) {
|
|
13
|
+
if (id.startsWith(VIRTUAL_PAGE_MODULE_ID)) {
|
|
14
|
+
return VIRTUAL_PAGE_RESOLVED_MODULE_ID + id.slice(VIRTUAL_PAGE_MODULE_ID.length);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
async load(id) {
|
|
18
|
+
if (id.startsWith(VIRTUAL_PAGE_RESOLVED_MODULE_ID)) {
|
|
19
|
+
const componentPath = getComponentFromVirtualModulePageName(
|
|
20
|
+
VIRTUAL_PAGE_RESOLVED_MODULE_ID,
|
|
21
|
+
id
|
|
22
|
+
);
|
|
23
|
+
if (DEFAULT_COMPONENTS.some((component) => componentPath === component)) {
|
|
24
|
+
return { code: "" };
|
|
25
|
+
}
|
|
26
|
+
const routes = routesList.routes.filter((route) => route.component === componentPath);
|
|
27
|
+
for (const route of routes) {
|
|
28
|
+
if (routeIsRedirect(route)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const astroModuleId = prependForwardSlash(componentPath);
|
|
32
|
+
const imports = [];
|
|
33
|
+
const exports = [];
|
|
34
|
+
imports.push(`import * as _page from ${JSON.stringify(astroModuleId)};`);
|
|
35
|
+
exports.push(`export const page = () => _page`);
|
|
36
|
+
return { code: `${imports.join("\n")}
|
|
37
|
+
${exports.join("\n")}` };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getComponentFromVirtualModulePageName(virtualModulePrefix, id) {
|
|
44
|
+
return id.slice(virtualModulePrefix.length).replace(/@_@/g, ".");
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
pluginPage
|
|
48
|
+
};
|