diff --git a/.changeset/neat-mugs-end.md b/.changeset/neat-mugs-end.md new file mode 100644 index 0000000000..dd65708a73 --- /dev/null +++ b/.changeset/neat-mugs-end.md @@ -0,0 +1,8 @@ +--- +'astro': minor +--- + + +`astro:`namespace aliases for middleware and components + +This adds aliases of `astro:middleware` and `astro:components` for the middleware and components modules. This is to make our documentation consistent between are various modules, where some are virtual modules and others are not. Going forward new built-in modules will use this namespace. diff --git a/examples/middleware/src/middleware.ts b/examples/middleware/src/middleware.ts index 9871e9d01e..eb76445354 100644 --- a/examples/middleware/src/middleware.ts +++ b/examples/middleware/src/middleware.ts @@ -1,4 +1,4 @@ -import { defineMiddleware, sequence } from 'astro/middleware'; +import { defineMiddleware, sequence } from 'astro:middleware'; import htmlMinifier from 'html-minifier'; const limit = 50; diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index 7f701b0c05..e6389d4155 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -119,6 +119,14 @@ declare module 'astro:transitions' { export const ViewTransitions: ViewTransitionsModule['default']; } +declare module 'astro:middleware' { + export * from 'astro/middleware/namespace'; +} + +declare module 'astro:components' { + export * from 'astro/components'; +} + type MD = import('./dist/@types/astro').MarkdownInstance>; interface ExportedMarkdownModuleEntities { frontmatter: MD['frontmatter']; diff --git a/packages/astro/package.json b/packages/astro/package.json index 91c59100d5..76e67fb922 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -23,6 +23,9 @@ ], "middleware": [ "./dist/core/middleware/index.d.ts" + ], + "middleware/namespace": [ + "./dist/core/middleware/namespace.d.ts" ] } }, @@ -70,6 +73,10 @@ "types": "./dist/core/middleware/index.d.ts", "default": "./dist/core/middleware/index.js" }, + "./middleware/namespace": { + "types": "./dist/core/middleware/namespace.d.ts", + "default": "./dist/core/middleware/namespace.js" + }, "./transitions": "./dist/transitions/index.js" }, "imports": { diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index f9568d4172..0449b89d47 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1920,7 +1920,7 @@ export interface APIContext = Record { * context.locals.greeting = "Hello!"; diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 5b2ebfa21b..f4938d2eba 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -170,6 +170,14 @@ export async function createVite( find: /^astro$/, replacement: fileURLToPath(new URL('../@types/astro', import.meta.url)), }, + { + find: 'astro:middleware', + replacement: 'astro/middleware/namespace', + }, + { + find: 'astro:components', + replacement: 'astro/components', + }, ], conditions: ['astro'], // Astro imports in third-party packages should use the same version as root diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index c717a2b030..9bac015190 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -658,7 +658,7 @@ export const ResponseSentError = { * * For example: * ```ts - * import {defineMiddleware} from "astro/middleware"; + * import {defineMiddleware} from "astro:middleware"; * export const onRequest = defineMiddleware((context, _) => { * // doesn't return anything or call `next` * context.locals.someData = false; @@ -678,7 +678,7 @@ export const MiddlewareNoDataOrNextCalled = { * * For example: * ```ts - * import {defineMiddleware} from "astro/middleware"; + * import {defineMiddleware} from "astro:middleware"; * export const onRequest = defineMiddleware(() => { * return "string" * }); @@ -698,7 +698,7 @@ export const MiddlewareNotAResponse = { * * For example: * ```ts - * import {defineMiddleware} from "astro/middleware"; + * import {defineMiddleware} from "astro:middleware"; * export const onRequest = defineMiddleware((context, next) => { * context.locals = 1541; * return next(); diff --git a/packages/astro/src/core/middleware/namespace.ts b/packages/astro/src/core/middleware/namespace.ts new file mode 100644 index 0000000000..e504f866c0 --- /dev/null +++ b/packages/astro/src/core/middleware/namespace.ts @@ -0,0 +1,4 @@ +export { + defineMiddleware, + sequence, +} from './index.js'; diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/basic.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/basic.astro index 9fba8620a6..ddbd92fede 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/basic.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/basic.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/css-theme.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/css-theme.astro index 8a4a8debf3..7434238495 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/css-theme.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/css-theme.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/custom-theme.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/custom-theme.astro index 80cafe5cce..45e92dccf3 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/custom-theme.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/custom-theme.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/imported.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/imported.astro index 02e6b4b03b..6ea6782d68 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/imported.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/imported.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; import riGrammar from '../assets/ri.tmLanguage.json' import serendipity from '../assets/serendipity-morning.json' diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/inline.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/inline.astro index 05422c8bf6..10c17f4e26 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/inline.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/inline.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/no-lang.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/no-lang.astro index ebc1b0810d..d0ae5f95f3 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/no-lang.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/no-lang.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-false.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-false.astro index ca1e238c71..aa4a58707b 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-false.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-false.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-null.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-null.astro index cff0190e8b..f72e093dda 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-null.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-null.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-true.astro b/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-true.astro index 82e8f65c2f..43ccb54521 100644 --- a/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-true.astro +++ b/packages/astro/test/fixtures/astro-component-code/src/pages/wrap-true.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Code component diff --git a/packages/astro/test/fixtures/code-component/src/pages/index.astro b/packages/astro/test/fixtures/code-component/src/pages/index.astro index 763f32caeb..d165a43086 100644 --- a/packages/astro/test/fixtures/code-component/src/pages/index.astro +++ b/packages/astro/test/fixtures/code-component/src/pages/index.astro @@ -1,5 +1,5 @@ --- -import { Code } from 'astro/components'; +import { Code } from 'astro:components'; --- diff --git a/packages/astro/test/fixtures/middleware-dev/src/middleware.js b/packages/astro/test/fixtures/middleware-dev/src/middleware.js index 2f9fc08b91..854c997c10 100644 --- a/packages/astro/test/fixtures/middleware-dev/src/middleware.js +++ b/packages/astro/test/fixtures/middleware-dev/src/middleware.js @@ -1,4 +1,4 @@ -import { sequence, defineMiddleware } from 'astro/middleware'; +import { sequence, defineMiddleware } from 'astro:middleware'; const first = defineMiddleware(async (context, next) => { if (context.request.url.includes('/lorem')) { diff --git a/packages/astro/test/fixtures/middleware-ssg/src/middleware.js b/packages/astro/test/fixtures/middleware-ssg/src/middleware.js index f28d89f670..04c0bfb3a4 100644 --- a/packages/astro/test/fixtures/middleware-ssg/src/middleware.js +++ b/packages/astro/test/fixtures/middleware-ssg/src/middleware.js @@ -1,4 +1,4 @@ -import { sequence, defineMiddleware } from 'astro/middleware'; +import { sequence, defineMiddleware } from 'astro:middleware'; const first = defineMiddleware(async (context, next) => { if (context.request.url.includes('/second')) { diff --git a/packages/astro/test/fixtures/ssr-redirect/src/middleware.ts b/packages/astro/test/fixtures/ssr-redirect/src/middleware.ts index a8de8d1306..57ce556781 100644 --- a/packages/astro/test/fixtures/ssr-redirect/src/middleware.ts +++ b/packages/astro/test/fixtures/ssr-redirect/src/middleware.ts @@ -1,4 +1,4 @@ -import { defineMiddleware } from 'astro/middleware'; +import { defineMiddleware } from 'astro:middleware'; export const onRequest = defineMiddleware(({ request }, next) => { if(new URL(request.url).pathname === '/middleware-redirect/') { diff --git a/packages/astro/test/fixtures/static-build-code-component/src/pages/index.astro b/packages/astro/test/fixtures/static-build-code-component/src/pages/index.astro index e2f564a3bc..c87ed5b088 100644 --- a/packages/astro/test/fixtures/static-build-code-component/src/pages/index.astro +++ b/packages/astro/test/fixtures/static-build-code-component/src/pages/index.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Testing diff --git a/packages/astro/test/fixtures/static-build-dir/src/pages/index.astro b/packages/astro/test/fixtures/static-build-dir/src/pages/index.astro index e2f564a3bc..c87ed5b088 100644 --- a/packages/astro/test/fixtures/static-build-dir/src/pages/index.astro +++ b/packages/astro/test/fixtures/static-build-dir/src/pages/index.astro @@ -1,5 +1,5 @@ --- -import {Code} from 'astro/components'; +import {Code} from 'astro:components'; --- Testing