Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

astro: namespace for middleware and components #8101

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/neat-mugs-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'astro': minor
---


`astro:`namespace aliases for middleware and components
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`astro:`namespace aliases for middleware and components
`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.
2 changes: 1 addition & 1 deletion examples/middleware/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineMiddleware, sequence } from 'astro/middleware';
import { defineMiddleware, sequence } from 'astro:middleware';
import htmlMinifier from 'html-minifier';

const limit = 50;
Expand Down
8 changes: 8 additions & 0 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ declare module 'astro:transitions' {
export const ViewTransitions: ViewTransitionsModule['default'];
}

declare module 'astro:middleware' {
export * from 'astro/middleware';
}

declare module 'astro:components' {
export * from 'astro/components';
}

type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
interface ExportedMarkdownModuleEntities {
frontmatter: MD['frontmatter'];
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
*
* ```ts
* // src/middleware.ts
* import {defineMiddleware} from "astro/middleware";
* import {defineMiddleware} from "astro:middleware";
*
* export const onRequest = defineMiddleware((context, next) => {
* context.locals.greeting = "Hello!";
Expand Down
8 changes: 8 additions & 0 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
{
find: 'astro:components',
replacement: 'astro/components',
},
],
conditions: ['astro'],
// Astro imports in third-party packages should use the same version as root
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
* });
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Code component</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { Code } from 'astro/components';
import { Code } from 'astro:components';
---
<html>
<head>
Expand Down
Original file line number Diff line number Diff line change
@@ -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')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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/') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Testing</title></head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import {Code} from 'astro/components';
import {Code} from 'astro:components';
---
<html>
<head><title>Testing</title></head>
Expand Down
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.