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
package/dist/content/utils.js
CHANGED
|
@@ -5,10 +5,9 @@ import { parseFrontmatter } from "@astrojs/markdown-remark";
|
|
|
5
5
|
import { slug as githubSlug } from "github-slugger";
|
|
6
6
|
import colors from "piccolore";
|
|
7
7
|
import xxhash from "xxhash-wasm";
|
|
8
|
-
import
|
|
8
|
+
import * as z from "zod/v4";
|
|
9
9
|
import { AstroError, AstroErrorData, errorMap, MarkdownError } from "../core/errors/index.js";
|
|
10
10
|
import { isYAMLException } from "../core/errors/utils.js";
|
|
11
|
-
import { appendForwardSlash } from "../core/path.js";
|
|
12
11
|
import { normalizePath } from "../core/viteUtils.js";
|
|
13
12
|
import {
|
|
14
13
|
CONTENT_LAYER_TYPE,
|
|
@@ -18,11 +17,10 @@ import {
|
|
|
18
17
|
LIVE_CONTENT_TYPE,
|
|
19
18
|
PROPAGATED_ASSET_FLAG
|
|
20
19
|
} from "./consts.js";
|
|
21
|
-
import { glob } from "./loaders/glob.js";
|
|
22
20
|
import { createImage } from "./runtime-assets.js";
|
|
23
21
|
const entryTypeSchema = z.object({
|
|
24
22
|
id: z.string({
|
|
25
|
-
|
|
23
|
+
error: "Content entry `id` must be a string"
|
|
26
24
|
// Default to empty string so we can validate properly in the loader
|
|
27
25
|
})
|
|
28
26
|
}).passthrough();
|
|
@@ -32,20 +30,12 @@ const loaderReturnSchema = z.union([
|
|
|
32
30
|
z.string(),
|
|
33
31
|
z.object({
|
|
34
32
|
id: z.string({
|
|
35
|
-
|
|
33
|
+
error: "Content entry `id` must be a string"
|
|
36
34
|
}).optional()
|
|
37
35
|
}).passthrough()
|
|
38
36
|
)
|
|
39
37
|
]);
|
|
40
38
|
const collectionConfigParser = z.union([
|
|
41
|
-
z.object({
|
|
42
|
-
type: z.literal("content").optional().default("content"),
|
|
43
|
-
schema: z.any().optional()
|
|
44
|
-
}),
|
|
45
|
-
z.object({
|
|
46
|
-
type: z.literal("data"),
|
|
47
|
-
schema: z.any().optional()
|
|
48
|
-
}),
|
|
49
39
|
z.object({
|
|
50
40
|
type: z.literal(CONTENT_LAYER_TYPE),
|
|
51
41
|
schema: z.any().optional(),
|
|
@@ -53,32 +43,38 @@ const collectionConfigParser = z.union([
|
|
|
53
43
|
z.function(),
|
|
54
44
|
z.object({
|
|
55
45
|
name: z.string(),
|
|
56
|
-
load: z.function(
|
|
57
|
-
z.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
46
|
+
load: z.function({
|
|
47
|
+
input: [z.custom()],
|
|
48
|
+
output: z.custom()
|
|
49
|
+
}),
|
|
50
|
+
schema: z.any().transform((v) => {
|
|
51
|
+
if (typeof v === "function") {
|
|
52
|
+
console.warn(
|
|
53
|
+
`Your loader's schema is defined using a function. This is no longer supported and the schema will be ignored. Please update your loader to use the \`createSchema()\` utility instead, or report this to the loader author. In a future major version, this will cause the loader to break entirely.`
|
|
54
|
+
);
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
return v;
|
|
58
|
+
}).superRefine((v, ctx) => {
|
|
59
|
+
if (v !== void 0 && !("_zod" in v)) {
|
|
60
|
+
ctx.addIssue({
|
|
61
|
+
code: z.ZodIssueCode.custom,
|
|
62
|
+
message: "Invalid Zod schema"
|
|
63
|
+
});
|
|
64
|
+
return z.NEVER;
|
|
65
|
+
}
|
|
66
|
+
}).optional(),
|
|
67
|
+
createSchema: z.function({
|
|
68
|
+
input: [],
|
|
69
|
+
output: z.promise(
|
|
70
|
+
z.object({
|
|
71
|
+
schema: z.custom((v) => "_zod" in v),
|
|
72
|
+
types: z.string()
|
|
73
|
+
})
|
|
74
74
|
)
|
|
75
|
-
)
|
|
76
|
-
schema: z.any().optional(),
|
|
77
|
-
render: z.function(z.tuple([z.any()], z.unknown())).optional()
|
|
75
|
+
}).optional()
|
|
78
76
|
})
|
|
79
|
-
])
|
|
80
|
-
/** deprecated */
|
|
81
|
-
_legacy: z.boolean().optional()
|
|
77
|
+
])
|
|
82
78
|
}),
|
|
83
79
|
z.object({
|
|
84
80
|
type: z.literal(LIVE_CONTENT_TYPE).optional().default(LIVE_CONTENT_TYPE),
|
|
@@ -87,7 +83,7 @@ const collectionConfigParser = z.union([
|
|
|
87
83
|
})
|
|
88
84
|
]);
|
|
89
85
|
const contentConfigParser = z.object({
|
|
90
|
-
collections: z.record(collectionConfigParser)
|
|
86
|
+
collections: z.record(z.string(), collectionConfigParser)
|
|
91
87
|
});
|
|
92
88
|
function parseEntrySlug({
|
|
93
89
|
id,
|
|
@@ -104,25 +100,13 @@ function parseEntrySlug({
|
|
|
104
100
|
});
|
|
105
101
|
}
|
|
106
102
|
}
|
|
107
|
-
async function
|
|
108
|
-
let data;
|
|
109
|
-
if (collectionConfig.type === "content" || collectionConfig._legacy) {
|
|
110
|
-
const { slug, ...unvalidatedData } = entry.unvalidatedData;
|
|
111
|
-
data = unvalidatedData;
|
|
112
|
-
} else {
|
|
113
|
-
data = entry.unvalidatedData;
|
|
114
|
-
}
|
|
103
|
+
async function getEntryData(entry, collectionConfig, shouldEmitFile, pluginContext) {
|
|
104
|
+
let data = entry.unvalidatedData;
|
|
115
105
|
let schema = collectionConfig.schema;
|
|
116
|
-
const imageImports = /* @__PURE__ */ new Set();
|
|
117
106
|
if (typeof schema === "function") {
|
|
118
107
|
if (pluginContext) {
|
|
119
108
|
schema = schema({
|
|
120
|
-
image: createImage(
|
|
121
|
-
pluginContext,
|
|
122
|
-
shouldEmitFile,
|
|
123
|
-
entry._internal.filePath,
|
|
124
|
-
experimentalSvgEnabled
|
|
125
|
-
)
|
|
109
|
+
image: createImage(pluginContext, shouldEmitFile, entry._internal.filePath)
|
|
126
110
|
});
|
|
127
111
|
} else if (collectionConfig.type === CONTENT_LAYER_TYPE) {
|
|
128
112
|
schema = schema({
|
|
@@ -131,41 +115,37 @@ async function getEntryDataAndImages(entry, collectionConfig, shouldEmitFile, ex
|
|
|
131
115
|
if (val && !val.startsWith("./") && !val.startsWith("../") && !val.startsWith("/") && !val.startsWith("~") && !val.startsWith("@") && !val.includes("://")) {
|
|
132
116
|
normalizedPath = `./${val}`;
|
|
133
117
|
}
|
|
134
|
-
imageImports.add(normalizedPath);
|
|
135
118
|
return `${IMAGE_IMPORT_PREFIX}${normalizedPath}`;
|
|
136
119
|
})
|
|
137
120
|
});
|
|
138
121
|
}
|
|
139
122
|
}
|
|
140
123
|
if (schema) {
|
|
141
|
-
if (collectionConfig.type === "content" && typeof schema === "object" && "shape" in schema && schema.shape.slug) {
|
|
142
|
-
throw new AstroError({
|
|
143
|
-
...AstroErrorData.ContentSchemaContainsSlugError,
|
|
144
|
-
message: AstroErrorData.ContentSchemaContainsSlugError.message(entry.collection)
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
124
|
let formattedError;
|
|
148
125
|
const parsed = await schema.safeParseAsync(data, {
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
formattedError =
|
|
126
|
+
error(issue) {
|
|
127
|
+
if (issue.code === "custom" && issue.params?.isHoistedAstroError) {
|
|
128
|
+
formattedError = issue.params?.astroError;
|
|
152
129
|
}
|
|
153
|
-
return errorMap(
|
|
130
|
+
return errorMap(issue);
|
|
154
131
|
}
|
|
155
132
|
});
|
|
156
133
|
if (parsed.success) {
|
|
157
134
|
data = parsed.data;
|
|
158
135
|
} else {
|
|
159
136
|
if (!formattedError) {
|
|
160
|
-
const errorType = collectionConfig.type === "content" ? AstroErrorData.InvalidContentEntryFrontmatterError : AstroErrorData.InvalidContentEntryDataError;
|
|
161
137
|
formattedError = new AstroError({
|
|
162
|
-
...
|
|
163
|
-
message:
|
|
138
|
+
...AstroErrorData.InvalidContentEntryDataError,
|
|
139
|
+
message: AstroErrorData.InvalidContentEntryDataError.message(
|
|
140
|
+
entry.collection,
|
|
141
|
+
entry.id,
|
|
142
|
+
parsed.error
|
|
143
|
+
),
|
|
164
144
|
location: {
|
|
165
145
|
file: entry._internal?.filePath,
|
|
166
146
|
line: getYAMLErrorLine(
|
|
167
147
|
entry._internal?.rawData,
|
|
168
|
-
String(parsed.error.
|
|
148
|
+
String(parsed.error.issues[0].path[0])
|
|
169
149
|
),
|
|
170
150
|
column: 0
|
|
171
151
|
}
|
|
@@ -174,16 +154,6 @@ async function getEntryDataAndImages(entry, collectionConfig, shouldEmitFile, ex
|
|
|
174
154
|
throw formattedError;
|
|
175
155
|
}
|
|
176
156
|
}
|
|
177
|
-
return { data, imageImports: Array.from(imageImports) };
|
|
178
|
-
}
|
|
179
|
-
async function getEntryData(entry, collectionConfig, shouldEmitFile, experimentalSvgEnabled, pluginContext) {
|
|
180
|
-
const { data } = await getEntryDataAndImages(
|
|
181
|
-
entry,
|
|
182
|
-
collectionConfig,
|
|
183
|
-
shouldEmitFile,
|
|
184
|
-
experimentalSvgEnabled,
|
|
185
|
-
pluginContext
|
|
186
|
-
);
|
|
187
157
|
return data;
|
|
188
158
|
}
|
|
189
159
|
function getContentEntryExts(settings) {
|
|
@@ -370,19 +340,18 @@ function isDeferredModule(viteId) {
|
|
|
370
340
|
async function loadContentConfig({
|
|
371
341
|
fs,
|
|
372
342
|
settings,
|
|
373
|
-
|
|
343
|
+
environment
|
|
374
344
|
}) {
|
|
375
345
|
const contentPaths = getContentPaths(settings.config, fs);
|
|
376
|
-
let unparsedConfig;
|
|
377
346
|
if (!contentPaths.config.exists) {
|
|
378
347
|
return void 0;
|
|
379
348
|
}
|
|
380
349
|
const configPathname = fileURLToPath(contentPaths.config.url);
|
|
381
|
-
unparsedConfig = await
|
|
350
|
+
const unparsedConfig = await environment.runner.import(configPathname);
|
|
382
351
|
const config = contentConfigParser.safeParse(unparsedConfig);
|
|
383
352
|
if (config.success) {
|
|
384
353
|
const hasher = await xxhash();
|
|
385
|
-
const digest =
|
|
354
|
+
const digest = hasher.h64ToString(await fs.promises.readFile(configPathname, "utf-8"));
|
|
386
355
|
return { ...config.data, digest };
|
|
387
356
|
} else {
|
|
388
357
|
const message = config.error.issues.map((issue) => ` \u2192 ${colors.green(issue.path.join("."))}: ${colors.red(issue.message)}`).join("\n");
|
|
@@ -392,96 +361,21 @@ async function loadContentConfig({
|
|
|
392
361
|
${message}
|
|
393
362
|
`
|
|
394
363
|
);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
});
|
|
407
|
-
}
|
|
364
|
+
const liveCollections = Object.entries(unparsedConfig.collections ?? {}).filter(
|
|
365
|
+
([, collection]) => collection?.type === LIVE_CONTENT_TYPE
|
|
366
|
+
);
|
|
367
|
+
if (liveCollections.length > 0) {
|
|
368
|
+
throw new AstroError({
|
|
369
|
+
...AstroErrorData.LiveContentConfigError,
|
|
370
|
+
message: AstroErrorData.LiveContentConfigError.message(
|
|
371
|
+
"Live collections must be defined in a `src/live.config.ts` file.",
|
|
372
|
+
path.relative(fileURLToPath(settings.config.root), configPathname)
|
|
373
|
+
)
|
|
374
|
+
});
|
|
408
375
|
}
|
|
409
376
|
return void 0;
|
|
410
377
|
}
|
|
411
378
|
}
|
|
412
|
-
async function autogenerateCollections({
|
|
413
|
-
config,
|
|
414
|
-
settings,
|
|
415
|
-
fs
|
|
416
|
-
}) {
|
|
417
|
-
if (settings.config.legacy.collections) {
|
|
418
|
-
return config;
|
|
419
|
-
}
|
|
420
|
-
const contentDir = new URL("./content/", settings.config.srcDir);
|
|
421
|
-
const collections = config?.collections ?? {};
|
|
422
|
-
const contentExts = getContentEntryExts(settings);
|
|
423
|
-
const dataExts = getDataEntryExts(settings);
|
|
424
|
-
const contentPattern = globWithUnderscoresIgnored("", contentExts);
|
|
425
|
-
const dataPattern = globWithUnderscoresIgnored("", dataExts);
|
|
426
|
-
let usesContentLayer = false;
|
|
427
|
-
for (const collectionName of Object.keys(collections)) {
|
|
428
|
-
if (collections[collectionName]?.type === "content_layer" || collections[collectionName]?.type === "live") {
|
|
429
|
-
usesContentLayer = true;
|
|
430
|
-
continue;
|
|
431
|
-
}
|
|
432
|
-
const isDataCollection = collections[collectionName]?.type === "data";
|
|
433
|
-
const base = new URL(`${collectionName}/`, contentDir);
|
|
434
|
-
const _legacy = !isDataCollection || void 0;
|
|
435
|
-
collections[collectionName] = {
|
|
436
|
-
...collections[collectionName],
|
|
437
|
-
type: "content_layer",
|
|
438
|
-
_legacy,
|
|
439
|
-
loader: glob({
|
|
440
|
-
base,
|
|
441
|
-
pattern: isDataCollection ? dataPattern : contentPattern,
|
|
442
|
-
_legacy,
|
|
443
|
-
// Legacy data collections IDs aren't slugified
|
|
444
|
-
generateId: isDataCollection ? ({ entry }) => getDataEntryId({
|
|
445
|
-
entry: new URL(entry, base),
|
|
446
|
-
collection: collectionName,
|
|
447
|
-
contentDir
|
|
448
|
-
}) : void 0
|
|
449
|
-
// Zod weirdness has trouble with typing the args to the load function
|
|
450
|
-
})
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
if (!usesContentLayer && fs.existsSync(contentDir)) {
|
|
454
|
-
const orphanedCollections = [];
|
|
455
|
-
for (const entry of await fs.promises.readdir(contentDir, { withFileTypes: true })) {
|
|
456
|
-
const collectionName = entry.name;
|
|
457
|
-
if (["_", "."].includes(collectionName.at(0) ?? "")) {
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
if (entry.isDirectory() && !(collectionName in collections)) {
|
|
461
|
-
orphanedCollections.push(collectionName);
|
|
462
|
-
const base = new URL(`${collectionName}/`, contentDir);
|
|
463
|
-
collections[collectionName] = {
|
|
464
|
-
type: "content_layer",
|
|
465
|
-
loader: glob({
|
|
466
|
-
base,
|
|
467
|
-
pattern: contentPattern,
|
|
468
|
-
_legacy: true
|
|
469
|
-
})
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
if (orphanedCollections.length > 0) {
|
|
474
|
-
console.warn(
|
|
475
|
-
`
|
|
476
|
-
Auto-generating collections for folders in "src/content/" that are not defined as collections.
|
|
477
|
-
This is deprecated, so you should define these collections yourself in "src/content.config.ts".
|
|
478
|
-
The following collections have been auto-generated: ${orphanedCollections.map((name) => colors.green(name)).join(", ")}
|
|
479
|
-
`
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
return { ...config, collections };
|
|
484
|
-
}
|
|
485
379
|
async function reloadContentConfigObserver({
|
|
486
380
|
observer = globalContentConfigObserver,
|
|
487
381
|
...loadContentConfigOpts
|
|
@@ -489,10 +383,6 @@ async function reloadContentConfigObserver({
|
|
|
489
383
|
observer.set({ status: "loading" });
|
|
490
384
|
try {
|
|
491
385
|
let config = await loadContentConfig(loadContentConfigOpts);
|
|
492
|
-
config = await autogenerateCollections({
|
|
493
|
-
config,
|
|
494
|
-
...loadContentConfigOpts
|
|
495
|
-
});
|
|
496
386
|
if (config) {
|
|
497
387
|
observer.set({ status: "loaded", config });
|
|
498
388
|
} else {
|
|
@@ -527,14 +417,19 @@ function contentObservable(initialCtx) {
|
|
|
527
417
|
subscribe
|
|
528
418
|
};
|
|
529
419
|
}
|
|
530
|
-
function getContentPaths({
|
|
531
|
-
srcDir
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
420
|
+
function getContentPaths({ srcDir, root }, fs = fsMod) {
|
|
421
|
+
const configStats = searchConfig(fs, srcDir);
|
|
422
|
+
if (!configStats.exists) {
|
|
423
|
+
const legacyConfigStats = searchLegacyConfig(fs, srcDir);
|
|
424
|
+
if (legacyConfigStats.exists) {
|
|
425
|
+
const relativePath = path.relative(fileURLToPath(root), fileURLToPath(legacyConfigStats.url));
|
|
426
|
+
throw new AstroError({
|
|
427
|
+
...AstroErrorData.LegacyContentConfigError,
|
|
428
|
+
message: AstroErrorData.LegacyContentConfigError.message(relativePath)
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const liveConfigStats = searchLiveConfig(fs, srcDir);
|
|
538
433
|
const pkgBase = new URL("../../", import.meta.url);
|
|
539
434
|
return {
|
|
540
435
|
root: new URL("./", root),
|
|
@@ -546,13 +441,21 @@ function getContentPaths({
|
|
|
546
441
|
liveConfig: liveConfigStats
|
|
547
442
|
};
|
|
548
443
|
}
|
|
549
|
-
function searchConfig(fs, srcDir
|
|
444
|
+
function searchConfig(fs, srcDir) {
|
|
550
445
|
const paths = [
|
|
551
|
-
|
|
552
|
-
"content
|
|
446
|
+
"content.config.mjs",
|
|
447
|
+
"content.config.js",
|
|
448
|
+
"content.config.mts",
|
|
449
|
+
"content.config.ts"
|
|
450
|
+
];
|
|
451
|
+
return search(fs, srcDir, paths);
|
|
452
|
+
}
|
|
453
|
+
function searchLegacyConfig(fs, srcDir) {
|
|
454
|
+
const paths = [
|
|
455
|
+
"content/config.ts",
|
|
553
456
|
"content/config.js",
|
|
554
|
-
"content/config.
|
|
555
|
-
"content/config.
|
|
457
|
+
"content/config.mjs",
|
|
458
|
+
"content/config.mts"
|
|
556
459
|
];
|
|
557
460
|
return search(fs, srcDir, paths);
|
|
558
461
|
}
|
|
@@ -589,12 +492,6 @@ async function getEntrySlug({
|
|
|
589
492
|
});
|
|
590
493
|
return parseEntrySlug({ generatedSlug, frontmatterSlug, id, collection });
|
|
591
494
|
}
|
|
592
|
-
function getExtGlob(exts) {
|
|
593
|
-
return exts.length === 1 ? (
|
|
594
|
-
// Wrapping {...} breaks when there is only one extension
|
|
595
|
-
exts[0]
|
|
596
|
-
) : `{${exts.join(",")}}`;
|
|
597
|
-
}
|
|
598
495
|
function hasAssetPropagationFlag(id) {
|
|
599
496
|
try {
|
|
600
497
|
return new URL(id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG);
|
|
@@ -602,15 +499,6 @@ function hasAssetPropagationFlag(id) {
|
|
|
602
499
|
return false;
|
|
603
500
|
}
|
|
604
501
|
}
|
|
605
|
-
function globWithUnderscoresIgnored(relContentDir, exts) {
|
|
606
|
-
const extGlob = getExtGlob(exts);
|
|
607
|
-
const contentDir = relContentDir.length > 0 ? appendForwardSlash(relContentDir) : relContentDir;
|
|
608
|
-
return [
|
|
609
|
-
`${contentDir}**/*${extGlob}`,
|
|
610
|
-
`!${contentDir}**/_*/**/*${extGlob}`,
|
|
611
|
-
`!${contentDir}**/_*${extGlob}`
|
|
612
|
-
];
|
|
613
|
-
}
|
|
614
502
|
function posixifyPath(filePath) {
|
|
615
503
|
return filePath.split(path.sep).join("/");
|
|
616
504
|
}
|
|
@@ -654,12 +542,9 @@ export {
|
|
|
654
542
|
getEntryCollectionName,
|
|
655
543
|
getEntryConfigByExtMap,
|
|
656
544
|
getEntryData,
|
|
657
|
-
getEntryDataAndImages,
|
|
658
545
|
getEntrySlug,
|
|
659
546
|
getEntryType,
|
|
660
|
-
getExtGlob,
|
|
661
547
|
getSymlinkedContentCollections,
|
|
662
|
-
globWithUnderscoresIgnored,
|
|
663
548
|
globalContentConfigObserver,
|
|
664
549
|
hasAssetPropagationFlag,
|
|
665
550
|
hasContentFlag,
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as vite from 'vite';
|
|
2
|
+
import { type Plugin } from 'vite';
|
|
2
3
|
import type { BuildInternals } from '../core/build/internal.js';
|
|
3
|
-
import type { AstroBuildPlugin } from '../core/build/plugin.js';
|
|
4
|
-
import type { StaticBuildOptions } from '../core/build/types.js';
|
|
5
4
|
import type { AstroSettings } from '../types/astro.js';
|
|
6
5
|
export declare function astroContentAssetPropagationPlugin({ settings, }: {
|
|
7
6
|
settings: AstroSettings;
|
|
8
7
|
}): Plugin;
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Post-build hook that injects propagated styles into content collection chunks.
|
|
10
|
+
* Finds chunks with LINKS_PLACEHOLDER and STYLES_PLACEHOLDER, and replaces them
|
|
11
|
+
* with actual styles from propagatedStylesMap.
|
|
12
|
+
*/
|
|
13
|
+
export declare function contentAssetsBuildPostHook(base: string, internals: BuildInternals, { ssrOutputs, prerenderOutputs, mutate, }: {
|
|
14
|
+
ssrOutputs: vite.Rollup.RollupOutput[];
|
|
15
|
+
prerenderOutputs: vite.Rollup.RollupOutput[];
|
|
16
|
+
mutate: (chunk: vite.Rollup.OutputChunk, envs: ['server'], code: string) => void;
|
|
17
|
+
}): Promise<void>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
|
-
import { fileURLToPath
|
|
3
|
-
import {
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { isRunnableDevEnvironment } from "vite";
|
|
4
4
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
5
5
|
import { createViteLoader } from "../core/module-loader/vite.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { wrapId } from "../core/util.js";
|
|
7
|
+
import { isBuildableCSSRequest } from "../vite-plugin-astro-server/util.js";
|
|
8
|
+
import { crawlGraph } from "../vite-plugin-astro-server/vite.js";
|
|
8
9
|
import {
|
|
9
10
|
CONTENT_IMAGE_FLAG,
|
|
10
11
|
CONTENT_RENDER_FLAG,
|
|
@@ -13,6 +14,9 @@ import {
|
|
|
13
14
|
STYLES_PLACEHOLDER
|
|
14
15
|
} from "./consts.js";
|
|
15
16
|
import { hasContentFlag } from "./utils.js";
|
|
17
|
+
import { joinPaths, prependForwardSlash, slash } from "@astrojs/internal-helpers/path";
|
|
18
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
19
|
+
import { isAstroServerEnvironment } from "../environments.js";
|
|
16
20
|
function astroContentAssetPropagationPlugin({
|
|
17
21
|
settings
|
|
18
22
|
}) {
|
|
@@ -49,13 +53,19 @@ function astroContentAssetPropagationPlugin({
|
|
|
49
53
|
}
|
|
50
54
|
},
|
|
51
55
|
configureServer(server) {
|
|
52
|
-
|
|
56
|
+
if (!isRunnableDevEnvironment(server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr])) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
devModuleLoader = createViteLoader(
|
|
60
|
+
server,
|
|
61
|
+
server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]
|
|
62
|
+
);
|
|
53
63
|
},
|
|
54
|
-
async transform(_, id
|
|
64
|
+
async transform(_, id) {
|
|
55
65
|
if (hasContentFlag(id, PROPAGATED_ASSET_FLAG)) {
|
|
56
66
|
const basePath = id.split("?")[0];
|
|
57
67
|
let stringifiedLinks, stringifiedStyles;
|
|
58
|
-
if (
|
|
68
|
+
if (isAstroServerEnvironment(this.environment) && devModuleLoader) {
|
|
59
69
|
if (!devModuleLoader.getModuleById(basePath)?.ssrModule) {
|
|
60
70
|
await devModuleLoader.import(basePath);
|
|
61
71
|
}
|
|
@@ -63,7 +73,7 @@ function astroContentAssetPropagationPlugin({
|
|
|
63
73
|
styles,
|
|
64
74
|
urls,
|
|
65
75
|
crawledFiles: styleCrawledFiles
|
|
66
|
-
} = await getStylesForURL(
|
|
76
|
+
} = await getStylesForURL(basePath, devModuleLoader.getSSREnvironment());
|
|
67
77
|
for (const file of styleCrawledFiles) {
|
|
68
78
|
if (!file.includes("node_modules")) {
|
|
69
79
|
this.addWatchFile(file);
|
|
@@ -89,60 +99,94 @@ function astroContentAssetPropagationPlugin({
|
|
|
89
99
|
}
|
|
90
100
|
};
|
|
91
101
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
const INLINE_QUERY_REGEX = /(?:\?|&)inline(?:$|&)/;
|
|
103
|
+
async function getStylesForURL(filePath, environment) {
|
|
104
|
+
const importedCssUrls = /* @__PURE__ */ new Set();
|
|
105
|
+
const importedStylesMap = /* @__PURE__ */ new Map();
|
|
106
|
+
const crawledFiles = /* @__PURE__ */ new Set();
|
|
107
|
+
for await (const importedModule of crawlGraph(environment, filePath, false)) {
|
|
108
|
+
if (importedModule.file) {
|
|
109
|
+
crawledFiles.add(importedModule.file);
|
|
110
|
+
}
|
|
111
|
+
if (isBuildableCSSRequest(importedModule.url)) {
|
|
112
|
+
let css = "";
|
|
113
|
+
if (typeof importedModule.ssrModule?.default === "string") {
|
|
114
|
+
css = importedModule.ssrModule.default;
|
|
115
|
+
} else {
|
|
116
|
+
let modId = importedModule.url;
|
|
117
|
+
if (!INLINE_QUERY_REGEX.test(importedModule.url)) {
|
|
118
|
+
if (importedModule.url.includes("?")) {
|
|
119
|
+
modId = importedModule.url.replace("?", "?inline&");
|
|
104
120
|
} else {
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
for (const chunk of outputs) {
|
|
109
|
-
if (chunk.type === "chunk" && chunk.code.includes(LINKS_PLACEHOLDER)) {
|
|
110
|
-
const entryStyles = /* @__PURE__ */ new Set();
|
|
111
|
-
const entryLinks = /* @__PURE__ */ new Set();
|
|
112
|
-
for (const id of chunk.moduleIds) {
|
|
113
|
-
const _entryCss = internals.propagatedStylesMap.get(id);
|
|
114
|
-
if (_entryCss) {
|
|
115
|
-
for (const value of _entryCss) {
|
|
116
|
-
if (value.type === "inline") entryStyles.add(value.content);
|
|
117
|
-
if (value.type === "external") entryLinks.add(value.src);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
let newCode = chunk.code;
|
|
122
|
-
if (entryStyles.size) {
|
|
123
|
-
newCode = newCode.replace(
|
|
124
|
-
JSON.stringify(STYLES_PLACEHOLDER),
|
|
125
|
-
JSON.stringify(Array.from(entryStyles))
|
|
126
|
-
);
|
|
127
|
-
} else {
|
|
128
|
-
newCode = newCode.replace(JSON.stringify(STYLES_PLACEHOLDER), "[]");
|
|
129
|
-
}
|
|
130
|
-
if (entryLinks.size) {
|
|
131
|
-
newCode = newCode.replace(
|
|
132
|
-
JSON.stringify(LINKS_PLACEHOLDER),
|
|
133
|
-
JSON.stringify(Array.from(entryLinks).map(prependBase))
|
|
134
|
-
);
|
|
135
|
-
} else {
|
|
136
|
-
newCode = newCode.replace(JSON.stringify(LINKS_PLACEHOLDER), "[]");
|
|
137
|
-
}
|
|
138
|
-
mutate(chunk, ["server"], newCode);
|
|
121
|
+
modId += "?inline";
|
|
139
122
|
}
|
|
140
123
|
}
|
|
124
|
+
try {
|
|
125
|
+
const ssrModule = await environment.runner.import(modId);
|
|
126
|
+
css = ssrModule.default;
|
|
127
|
+
} catch {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
141
130
|
}
|
|
131
|
+
importedStylesMap.set(importedModule.url, {
|
|
132
|
+
id: wrapId(importedModule.id ?? importedModule.url),
|
|
133
|
+
url: wrapId(importedModule.url),
|
|
134
|
+
content: css
|
|
135
|
+
});
|
|
142
136
|
}
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
urls: importedCssUrls,
|
|
140
|
+
styles: [...importedStylesMap.values()],
|
|
141
|
+
crawledFiles
|
|
143
142
|
};
|
|
144
143
|
}
|
|
144
|
+
async function contentAssetsBuildPostHook(base, internals, {
|
|
145
|
+
ssrOutputs,
|
|
146
|
+
prerenderOutputs,
|
|
147
|
+
mutate
|
|
148
|
+
}) {
|
|
149
|
+
const outputs = ssrOutputs.flatMap((o) => o.output).concat(
|
|
150
|
+
...(Array.isArray(prerenderOutputs) ? prerenderOutputs : [prerenderOutputs]).flatMap(
|
|
151
|
+
(o) => o.output
|
|
152
|
+
)
|
|
153
|
+
);
|
|
154
|
+
for (const chunk of outputs) {
|
|
155
|
+
if (chunk.type !== "chunk") continue;
|
|
156
|
+
if (!chunk.code.includes(LINKS_PLACEHOLDER)) continue;
|
|
157
|
+
const entryStyles = /* @__PURE__ */ new Set();
|
|
158
|
+
const entryLinks = /* @__PURE__ */ new Set();
|
|
159
|
+
for (const id of chunk.moduleIds) {
|
|
160
|
+
const entryCss = internals.propagatedStylesMap.get(id);
|
|
161
|
+
if (entryCss) {
|
|
162
|
+
for (const value of entryCss) {
|
|
163
|
+
if (value.type === "inline") entryStyles.add(value.content);
|
|
164
|
+
if (value.type === "external")
|
|
165
|
+
entryLinks.add(prependForwardSlash(joinPaths(base, slash(value.src))));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let newCode = chunk.code;
|
|
170
|
+
if (entryStyles.size) {
|
|
171
|
+
newCode = newCode.replace(
|
|
172
|
+
JSON.stringify(STYLES_PLACEHOLDER),
|
|
173
|
+
JSON.stringify(Array.from(entryStyles))
|
|
174
|
+
);
|
|
175
|
+
} else {
|
|
176
|
+
newCode = newCode.replace(JSON.stringify(STYLES_PLACEHOLDER), "[]");
|
|
177
|
+
}
|
|
178
|
+
if (entryLinks.size) {
|
|
179
|
+
newCode = newCode.replace(
|
|
180
|
+
JSON.stringify(LINKS_PLACEHOLDER),
|
|
181
|
+
JSON.stringify(Array.from(entryLinks))
|
|
182
|
+
);
|
|
183
|
+
} else {
|
|
184
|
+
newCode = newCode.replace(JSON.stringify(LINKS_PLACEHOLDER), "[]");
|
|
185
|
+
}
|
|
186
|
+
mutate(chunk, ["server"], newCode);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
145
189
|
export {
|
|
146
|
-
|
|
147
|
-
|
|
190
|
+
astroContentAssetPropagationPlugin,
|
|
191
|
+
contentAssetsBuildPostHook
|
|
148
192
|
};
|