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,18 +1,18 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
3
|
import colors from "piccolore";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import {
|
|
5
|
+
isRunnableDevEnvironment,
|
|
6
|
+
normalizePath
|
|
7
|
+
} from "vite";
|
|
8
|
+
import * as z from "zod/v4";
|
|
8
9
|
import { AstroError } from "../core/errors/errors.js";
|
|
9
|
-
import { AstroErrorData
|
|
10
|
+
import { AstroErrorData } from "../core/errors/index.js";
|
|
10
11
|
import { isRelativePath } from "../core/path.js";
|
|
11
12
|
import {
|
|
12
13
|
COLLECTIONS_DIR,
|
|
13
14
|
CONTENT_LAYER_TYPE,
|
|
14
15
|
CONTENT_TYPES_FILE,
|
|
15
|
-
LIVE_CONTENT_TYPE,
|
|
16
16
|
VIRTUAL_MODULE_ID
|
|
17
17
|
} from "./consts.js";
|
|
18
18
|
import {
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
getEntryType,
|
|
27
27
|
reloadContentConfigObserver
|
|
28
28
|
} from "./utils.js";
|
|
29
|
+
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
|
|
29
30
|
async function createContentTypesGenerator({
|
|
30
31
|
contentConfigObserver,
|
|
31
32
|
fs,
|
|
@@ -43,27 +44,7 @@ async function createContentTypesGenerator({
|
|
|
43
44
|
const typeTemplateContent = await fs.promises.readFile(contentPaths.typesTemplate, "utf-8");
|
|
44
45
|
async function init() {
|
|
45
46
|
events.push({ name: "add", entry: contentPaths.config.url });
|
|
46
|
-
if (settings.config.legacy.collections) {
|
|
47
|
-
if (!fs.existsSync(contentPaths.contentDir)) {
|
|
48
|
-
return { typesGenerated: false, reason: "no-content-dir" };
|
|
49
|
-
}
|
|
50
|
-
const globResult = await glob("**", {
|
|
51
|
-
cwd: fileURLToPath(contentPaths.contentDir),
|
|
52
|
-
absolute: true
|
|
53
|
-
});
|
|
54
|
-
for (const fullPath of globResult) {
|
|
55
|
-
const entryURL = pathToFileURL(fullPath);
|
|
56
|
-
if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
|
|
57
|
-
const stat = fs.statSync(fullPath);
|
|
58
|
-
if (stat.isFile()) {
|
|
59
|
-
events.push({ name: "add", entry: entryURL });
|
|
60
|
-
} else if (stat.isDirectory()) {
|
|
61
|
-
events.push({ name: "addDir", entry: entryURL });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
47
|
await runEvents();
|
|
66
|
-
return { typesGenerated: true };
|
|
67
48
|
}
|
|
68
49
|
async function handleEvent(event) {
|
|
69
50
|
if (event.name === "addDir" || event.name === "unlinkDir") {
|
|
@@ -97,7 +78,11 @@ async function createContentTypesGenerator({
|
|
|
97
78
|
return { shouldGenerateTypes: false };
|
|
98
79
|
}
|
|
99
80
|
if (fileType === "config") {
|
|
100
|
-
await reloadContentConfigObserver({
|
|
81
|
+
await reloadContentConfigObserver({
|
|
82
|
+
fs,
|
|
83
|
+
settings,
|
|
84
|
+
environment: viteServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.astro]
|
|
85
|
+
});
|
|
101
86
|
return { shouldGenerateTypes: true };
|
|
102
87
|
}
|
|
103
88
|
const { entry } = event;
|
|
@@ -125,7 +110,7 @@ async function createContentTypesGenerator({
|
|
|
125
110
|
}
|
|
126
111
|
const collectionInfo2 = collectionEntryMap[collectionKey2];
|
|
127
112
|
if (collectionInfo2.type === "content") {
|
|
128
|
-
viteServer.hot.send({
|
|
113
|
+
viteServer.environments.client.hot.send({
|
|
129
114
|
type: "error",
|
|
130
115
|
err: new AstroError({
|
|
131
116
|
...AstroErrorData.MixedContentDataCollectionError,
|
|
@@ -164,7 +149,7 @@ async function createContentTypesGenerator({
|
|
|
164
149
|
}
|
|
165
150
|
const collectionInfo = collectionEntryMap[collectionKey];
|
|
166
151
|
if (collectionInfo.type === "data") {
|
|
167
|
-
viteServer.hot.send({
|
|
152
|
+
viteServer.environments.client.hot.send({
|
|
168
153
|
type: "error",
|
|
169
154
|
err: new AstroError({
|
|
170
155
|
...AstroErrorData.MixedContentDataCollectionError,
|
|
@@ -222,11 +207,7 @@ async function createContentTypesGenerator({
|
|
|
222
207
|
entry: pathToFileURL(rawEvent.entry),
|
|
223
208
|
name: rawEvent.name
|
|
224
209
|
};
|
|
225
|
-
if (
|
|
226
|
-
if (!event.entry.pathname.startsWith(contentPaths.contentDir.pathname)) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
} else if (contentPaths.config.url.pathname !== event.entry.pathname) {
|
|
210
|
+
if (contentPaths.config.url.pathname !== event.entry.pathname) {
|
|
230
211
|
return;
|
|
231
212
|
}
|
|
232
213
|
events.push(event);
|
|
@@ -263,58 +244,68 @@ async function createContentTypesGenerator({
|
|
|
263
244
|
logger,
|
|
264
245
|
settings
|
|
265
246
|
});
|
|
266
|
-
|
|
247
|
+
if (!isRunnableDevEnvironment(viteServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr])) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
invalidateVirtualMod(viteServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]);
|
|
267
251
|
}
|
|
268
252
|
}
|
|
269
253
|
return { init, queueEvent };
|
|
270
254
|
}
|
|
271
|
-
function invalidateVirtualMod(
|
|
272
|
-
const virtualMod =
|
|
255
|
+
function invalidateVirtualMod(environment) {
|
|
256
|
+
const virtualMod = environment.moduleGraph.getModuleById("\0" + VIRTUAL_MODULE_ID);
|
|
273
257
|
if (!virtualMod) return;
|
|
274
|
-
|
|
258
|
+
environment.moduleGraph.invalidateModule(virtualMod);
|
|
275
259
|
}
|
|
276
260
|
function normalizeConfigPath(from, to) {
|
|
277
261
|
const configPath = path.relative(from, to).replace(/\.ts$/, ".js");
|
|
278
262
|
const normalizedPath = configPath.replaceAll("\\", "/");
|
|
279
263
|
return `"${isRelativePath(configPath) ? "" : "./"}${normalizedPath}"`;
|
|
280
264
|
}
|
|
281
|
-
const
|
|
282
|
-
async function
|
|
283
|
-
const cached =
|
|
265
|
+
const createSchemaResultCache = /* @__PURE__ */ new Map();
|
|
266
|
+
async function getCreateSchemaResult(collection, collectionKey) {
|
|
267
|
+
const cached = createSchemaResultCache.get(collectionKey);
|
|
284
268
|
if (cached) {
|
|
285
269
|
return cached;
|
|
286
270
|
}
|
|
287
|
-
if (collection?.type === CONTENT_LAYER_TYPE && typeof collection.loader === "object" && collection.loader.schema) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
if (schema) {
|
|
293
|
-
schemaCache.set(collectionKey, await schema);
|
|
294
|
-
return schema;
|
|
295
|
-
}
|
|
271
|
+
if (collection?.type === CONTENT_LAYER_TYPE && typeof collection.loader === "object" && !collection.loader.schema && collection.loader.createSchema) {
|
|
272
|
+
const result = await collection.loader.createSchema();
|
|
273
|
+
createSchemaResultCache.set(collectionKey, result);
|
|
274
|
+
return result;
|
|
296
275
|
}
|
|
297
276
|
}
|
|
277
|
+
async function getContentLayerSchema(collection, collectionKey) {
|
|
278
|
+
if (collection?.type !== CONTENT_LAYER_TYPE || typeof collection.loader === "function") {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (collection.loader.schema) {
|
|
282
|
+
return collection.loader.schema;
|
|
283
|
+
}
|
|
284
|
+
const result = await getCreateSchemaResult(collection, collectionKey);
|
|
285
|
+
return result?.schema;
|
|
286
|
+
}
|
|
298
287
|
async function typeForCollection(collection, collectionKey) {
|
|
299
288
|
if (collection?.schema) {
|
|
300
|
-
return `InferEntrySchema<${collectionKey}
|
|
289
|
+
return { type: `InferEntrySchema<${collectionKey}>` };
|
|
301
290
|
}
|
|
302
|
-
if (collection?.type ===
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const ast = zodToTs.zodToTs(schema);
|
|
308
|
-
return zodToTs.printNode(ast.node);
|
|
309
|
-
} catch (err) {
|
|
310
|
-
if (err.message.includes("Cannot find package 'typescript'")) {
|
|
311
|
-
return "any";
|
|
312
|
-
}
|
|
313
|
-
throw err;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
291
|
+
if (!collection?.type || typeof collection.loader === "function") {
|
|
292
|
+
return { type: "any" };
|
|
293
|
+
}
|
|
294
|
+
if (collection.loader.schema) {
|
|
295
|
+
return { type: `InferLoaderSchema<${collectionKey}>` };
|
|
316
296
|
}
|
|
317
|
-
|
|
297
|
+
const result = await getCreateSchemaResult(collection, collectionKey);
|
|
298
|
+
if (!result) {
|
|
299
|
+
return { type: "any" };
|
|
300
|
+
}
|
|
301
|
+
const base = `loaders/${collectionKey.slice(1, -1)}`;
|
|
302
|
+
return {
|
|
303
|
+
type: `import("./${base}.js").Entry`,
|
|
304
|
+
injectedType: {
|
|
305
|
+
filename: `${base}.ts`,
|
|
306
|
+
content: result.types
|
|
307
|
+
}
|
|
308
|
+
};
|
|
318
309
|
}
|
|
319
310
|
async function writeContentFiles({
|
|
320
311
|
fs,
|
|
@@ -327,7 +318,6 @@ async function writeContentFiles({
|
|
|
327
318
|
logger,
|
|
328
319
|
settings
|
|
329
320
|
}) {
|
|
330
|
-
let contentTypesStr = "";
|
|
331
321
|
let dataTypesStr = "";
|
|
332
322
|
const collectionSchemasDir = new URL(COLLECTIONS_DIR, settings.dotAstroDir);
|
|
333
323
|
fs.mkdirSync(collectionSchemasDir, { recursive: true });
|
|
@@ -342,7 +332,7 @@ async function writeContentFiles({
|
|
|
342
332
|
const collectionConfig = contentConfig?.collections[JSON.parse(collectionKey)];
|
|
343
333
|
const collection = collectionEntryMap[collectionKey];
|
|
344
334
|
if (collectionConfig?.type && collection.type !== "unknown" && collectionConfig.type !== CONTENT_LAYER_TYPE && collection.type !== collectionConfig.type) {
|
|
345
|
-
viteServer.hot.send({
|
|
335
|
+
viteServer.environments.client.hot.send({
|
|
346
336
|
type: "error",
|
|
347
337
|
err: new AstroError({
|
|
348
338
|
...AstroErrorData.ContentCollectionTypeMismatchError,
|
|
@@ -359,86 +349,28 @@ async function writeContentFiles({
|
|
|
359
349
|
});
|
|
360
350
|
return;
|
|
361
351
|
}
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
)
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
contentTypesStr += `${collectionKey}: Record<string, {
|
|
352
|
+
const { type: dataType, injectedType } = await typeForCollection(
|
|
353
|
+
collectionConfig,
|
|
354
|
+
collectionKey
|
|
355
|
+
);
|
|
356
|
+
if (injectedType) {
|
|
357
|
+
if (settings.injectedTypes.some((t) => t.filename === CONTENT_TYPES_FILE)) {
|
|
358
|
+
const url = new URL(injectedType.filename, settings.dotAstroDir);
|
|
359
|
+
await fs.promises.mkdir(path.dirname(fileURLToPath(url)), { recursive: true });
|
|
360
|
+
await fs.promises.writeFile(url, injectedType.content, "utf-8");
|
|
361
|
+
} else {
|
|
362
|
+
settings.injectedTypes.push(injectedType);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
dataTypesStr += `${collectionKey}: Record<string, {
|
|
377
366
|
id: string;
|
|
378
|
-
|
|
379
|
-
body: string;
|
|
367
|
+
body?: string;
|
|
380
368
|
collection: ${collectionKey};
|
|
381
369
|
data: ${dataType};
|
|
382
|
-
render(): Render[".md"];
|
|
383
|
-
}>;
|
|
384
|
-
`;
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
contentTypesStr += `${collectionKey}: {
|
|
388
|
-
`;
|
|
389
|
-
for (const entryKey of collectionEntryKeys) {
|
|
390
|
-
const entryMetadata = collection.entries[entryKey];
|
|
391
|
-
const renderType = `{ render(): Render[${JSON.stringify(
|
|
392
|
-
path.extname(JSON.parse(entryKey))
|
|
393
|
-
)}] }`;
|
|
394
|
-
const slugType = JSON.stringify(entryMetadata.slug);
|
|
395
|
-
contentTypesStr += `${entryKey}: {
|
|
396
|
-
id: ${entryKey};
|
|
397
|
-
slug: ${slugType};
|
|
398
|
-
body: string;
|
|
399
|
-
collection: ${collectionKey};
|
|
400
|
-
data: ${dataType}
|
|
401
|
-
} & ${renderType};
|
|
402
|
-
`;
|
|
403
|
-
}
|
|
404
|
-
contentTypesStr += `};
|
|
405
|
-
`;
|
|
406
|
-
break;
|
|
407
|
-
case CONTENT_LAYER_TYPE:
|
|
408
|
-
const legacyTypes = collectionConfig?._legacy ? 'render(): Render[".md"];\n slug: string;\n body: string;\n' : "body?: string;\n";
|
|
409
|
-
dataTypesStr += `${collectionKey}: Record<string, {
|
|
410
|
-
id: string;
|
|
411
|
-
${legacyTypes} collection: ${collectionKey};
|
|
412
|
-
data: ${dataType};
|
|
413
370
|
rendered?: RenderedContent;
|
|
414
371
|
filePath?: string;
|
|
415
372
|
}>;
|
|
416
373
|
`;
|
|
417
|
-
break;
|
|
418
|
-
case "data":
|
|
419
|
-
if (collectionEntryKeys.length === 0) {
|
|
420
|
-
dataTypesStr += `${collectionKey}: Record<string, {
|
|
421
|
-
id: string;
|
|
422
|
-
collection: ${collectionKey};
|
|
423
|
-
data: ${dataType};
|
|
424
|
-
}>;
|
|
425
|
-
`;
|
|
426
|
-
} else {
|
|
427
|
-
dataTypesStr += `${collectionKey}: {
|
|
428
|
-
`;
|
|
429
|
-
for (const entryKey of collectionEntryKeys) {
|
|
430
|
-
dataTypesStr += `${entryKey}: {
|
|
431
|
-
id: ${entryKey};
|
|
432
|
-
collection: ${collectionKey};
|
|
433
|
-
data: ${dataType}
|
|
434
|
-
};
|
|
435
|
-
`;
|
|
436
|
-
}
|
|
437
|
-
dataTypesStr += `};
|
|
438
|
-
`;
|
|
439
|
-
}
|
|
440
|
-
break;
|
|
441
|
-
}
|
|
442
374
|
if (collectionConfig && (collectionConfig.schema || await getContentLayerSchema(collectionConfig, collectionKey))) {
|
|
443
375
|
await generateJSONSchema(fs, collectionConfig, collectionKey, collectionSchemasDir, logger);
|
|
444
376
|
contentCollectionsMap[collectionKey] = collection;
|
|
@@ -453,7 +385,13 @@ async function writeContentFiles({
|
|
|
453
385
|
const collectionConfig = contentConfig?.collections[JSON.parse(collectionKey)];
|
|
454
386
|
const key = JSON.parse(collectionKey);
|
|
455
387
|
contentCollectionManifest.collections.push({
|
|
456
|
-
hasSchema: Boolean(
|
|
388
|
+
hasSchema: Boolean(
|
|
389
|
+
// Is there a user provided schema or
|
|
390
|
+
collectionConfig?.schema || // Is it a loader object and
|
|
391
|
+
typeof collectionConfig?.loader !== "function" && // Is it a loader static schema or
|
|
392
|
+
(collectionConfig?.loader.schema || // is it a loader dynamic schema
|
|
393
|
+
createSchemaResultCache.has(collectionKey))
|
|
394
|
+
),
|
|
457
395
|
name: key
|
|
458
396
|
});
|
|
459
397
|
Object.keys(collection.entries).forEach((entryKey) => {
|
|
@@ -479,7 +417,7 @@ async function writeContentFiles({
|
|
|
479
417
|
typeTemplateContent = contentEntryType.contentModuleTypes + "\n" + typeTemplateContent;
|
|
480
418
|
}
|
|
481
419
|
}
|
|
482
|
-
typeTemplateContent = typeTemplateContent.replace("// @@
|
|
420
|
+
typeTemplateContent = typeTemplateContent.replace("// @@DATA_ENTRY_MAP@@", dataTypesStr).replace(
|
|
483
421
|
"'@@CONTENT_CONFIG_TYPE@@'",
|
|
484
422
|
contentConfig ? `typeof import(${configPathRelativeToCacheDir})` : "never"
|
|
485
423
|
).replace(
|
|
@@ -513,20 +451,13 @@ async function generateJSONSchema(fsMod, collectionConfig, collectionKey, collec
|
|
|
513
451
|
});
|
|
514
452
|
}
|
|
515
453
|
try {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
markdownDescription: true,
|
|
522
|
-
errorMessages: true,
|
|
523
|
-
// Fix for https://github.com/StefanTerdell/zod-to-json-schema/issues/110
|
|
524
|
-
dateStrategy: ["format:date-time", "format:date", "integer"]
|
|
525
|
-
}),
|
|
526
|
-
null,
|
|
527
|
-
2
|
|
528
|
-
)
|
|
454
|
+
const schema = z.toJSONSchema(zodSchemaForJson);
|
|
455
|
+
const schemaStr = JSON.stringify(schema, null, 2);
|
|
456
|
+
const schemaJsonPath = new URL(
|
|
457
|
+
`./${collectionKey.replace(/"/g, "")}.schema.json`,
|
|
458
|
+
collectionSchemasDir
|
|
529
459
|
);
|
|
460
|
+
await fsMod.promises.writeFile(schemaJsonPath, schemaStr);
|
|
530
461
|
} catch (err) {
|
|
531
462
|
logger.warn(
|
|
532
463
|
"content",
|