From 710be505c9ddf416e77a75343d8cae9c497d72c6 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 22 Nov 2023 21:11:57 +0800 Subject: [PATCH] Refactor virtual modules exports (#9150) Co-authored-by: Nate Moore --- .changeset/sour-games-burn.md | 11 ++++++++++ packages/astro/client.d.ts | 20 +++++++++---------- .../astro/components/ViewTransitions.astro | 4 ++-- packages/astro/package.json | 14 ++----------- packages/astro/src/core/create-vite.ts | 2 +- .../astro/src/core/middleware/namespace.ts | 1 - packages/astro/src/i18n/vite-plugin-i18n.ts | 2 +- .../src/prefetch/vite-plugin-prefetch.ts | 6 +++--- .../transitions/vite-plugin-transitions.ts | 4 ++-- packages/astro/src/virtual-modules/README.md | 3 +++ packages/astro/src/virtual-modules/i18n.ts | 1 + .../astro/src/virtual-modules/middleware.ts | 1 + .../astro/src/virtual-modules/prefetch.ts | 1 + .../src/virtual-modules/transitions-router.ts | 1 + .../astro/src/virtual-modules/transitions.ts | 1 + 15 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 .changeset/sour-games-burn.md delete mode 100644 packages/astro/src/core/middleware/namespace.ts create mode 100644 packages/astro/src/virtual-modules/README.md create mode 100644 packages/astro/src/virtual-modules/i18n.ts create mode 100644 packages/astro/src/virtual-modules/middleware.ts create mode 100644 packages/astro/src/virtual-modules/prefetch.ts create mode 100644 packages/astro/src/virtual-modules/transitions-router.ts create mode 100644 packages/astro/src/virtual-modules/transitions.ts diff --git a/.changeset/sour-games-burn.md b/.changeset/sour-games-burn.md new file mode 100644 index 000000000000..64203dbd4e1a --- /dev/null +++ b/.changeset/sour-games-burn.md @@ -0,0 +1,11 @@ +--- +"astro": patch +--- + +Refactors virtual modules exports. This should not break your project unless you import Astro's internal modules, including: + +- `astro/middleware/namespace` +- `astro/transitions` +- `astro/transitions/router` +- `astro/prefetch` +- `astro/i18n` diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index f1cb0ff1188d..ee4c9df7e703 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -106,7 +106,7 @@ declare module '*.avif' { } declare module 'astro:transitions' { - type TransitionModule = typeof import('./dist/transitions/index.js'); + type TransitionModule = typeof import('./dist/virtual-modules/transitions.js'); export const slide: TransitionModule['slide']; export const fade: TransitionModule['fade']; @@ -115,24 +115,24 @@ declare module 'astro:transitions' { } declare module 'astro:transitions/client' { - type TransitionRouterModule = typeof import('./dist/transitions/router.js'); + type TransitionRouterModule = typeof import('./dist/virtual-modules/transitions-router.js'); export const supportsViewTransitions: TransitionRouterModule['supportsViewTransitions']; export const transitionEnabledOnThisPage: TransitionRouterModule['transitionEnabledOnThisPage']; export const navigate: TransitionRouterModule['navigate']; - export type Options = import('./dist/transitions/router.js').Options; + export type Options = import('./dist/virtual-modules/transitions-router.js').Options; } declare module 'astro:prefetch' { - export { prefetch, PrefetchOptions } from 'astro/prefetch'; + export { prefetch, PrefetchOptions } from 'astro/virtual-modules/prefetch.js'; } declare module 'astro:i18n' { - export type GetLocaleOptions = import('./dist/i18n/index.js').GetLocaleOptions; + export type GetLocaleOptions = import('./dist/virtual-modules/i18n.js').GetLocaleOptions; /** * @param {string} locale A locale * @param {string} [path=""] An optional path to add after the `locale`. - * @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path + * @param {import('./dist/virtual-modules/i18n.js').GetLocaleOptions} options Customise the generated path * @return {string} * * Returns a _relative_ path with passed locale. @@ -161,7 +161,7 @@ declare module 'astro:i18n' { * * @param {string} locale A locale * @param {string} [path=""] An optional path to add after the `locale`. - * @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path + * @param {import('./dist/virtual-modules/i18n.js').GetLocaleOptions} options Customise the generated path * @return {string} * * Returns an absolute path with the passed locale. The behaviour is subject to change based on `site` configuration. @@ -191,7 +191,7 @@ declare module 'astro:i18n' { /** * @param {string} [path=""] An optional path to add after the `locale`. - * @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path + * @param {import('./dist/virtual-modules/i18n.js').GetLocaleOptions} options Customise the generated path * @return {string[]} * * Works like `getRelativeLocaleUrl` but it emits the relative URLs for ALL locales: @@ -199,7 +199,7 @@ declare module 'astro:i18n' { export const getRelativeLocaleUrlList: (path?: string, options?: GetLocaleOptions) => string[]; /** * @param {string} [path=""] An optional path to add after the `locale`. - * @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path + * @param {import('./dist/virtual-modules/i18n.js').GetLocaleOptions} options Customise the generated path * @return {string[]} * * Works like `getAbsoluteLocaleUrl` but it emits the absolute URLs for ALL locales: @@ -208,7 +208,7 @@ declare module 'astro:i18n' { } declare module 'astro:middleware' { - export * from 'astro/middleware/namespace'; + export * from 'astro/virtual-modules/middleware.js'; } declare module 'astro:components' { diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 089d8d8e554e..1d2d72d8a7cd 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -29,8 +29,8 @@ const { fallback = 'animate', handleForms } = Astro.props;