summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/@types/astro.ts2
-rw-r--r--packages/astro/src/core/build/plugins/plugin-middleware.ts2
-rw-r--r--packages/astro/src/core/middleware/loadMiddleware.ts4
-rw-r--r--packages/astro/src/core/middleware/sequence.ts2
-rw-r--r--packages/astro/src/core/middleware/vite-plugin.ts32
-rw-r--r--packages/astro/src/integrations/index.ts11
6 files changed, 27 insertions, 26 deletions
diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts
index e1bf2cd8b..7f7e497b9 100644
--- a/packages/astro/src/@types/astro.ts
+++ b/packages/astro/src/@types/astro.ts
@@ -1701,7 +1701,7 @@ export interface AstroSettings {
*/
clientDirectives: Map<string, string>;
devOverlayPlugins: string[];
- middlewares: { pre: string[]; post: string[]; };
+ middlewares: { pre: string[]; post: string[] };
tsConfig: TSConfig | undefined;
tsConfigPath: string | undefined;
watchFiles: string[];
diff --git a/packages/astro/src/core/build/plugins/plugin-middleware.ts b/packages/astro/src/core/build/plugins/plugin-middleware.ts
index 7f3760612..bfc72e1a0 100644
--- a/packages/astro/src/core/build/plugins/plugin-middleware.ts
+++ b/packages/astro/src/core/build/plugins/plugin-middleware.ts
@@ -1,7 +1,7 @@
+import { vitePluginMiddlewareBuild } from '../../middleware/vite-plugin.js';
import type { BuildInternals } from '../internal.js';
import type { AstroBuildPlugin } from '../plugin.js';
import type { StaticBuildOptions } from '../types.js';
-import { vitePluginMiddlewareBuild } from '../../middleware/vite-plugin.js';
export { MIDDLEWARE_MODULE_ID } from '../../middleware/vite-plugin.js';
export function pluginMiddleware(
diff --git a/packages/astro/src/core/middleware/loadMiddleware.ts b/packages/astro/src/core/middleware/loadMiddleware.ts
index 46e1e32e2..4f524ee52 100644
--- a/packages/astro/src/core/middleware/loadMiddleware.ts
+++ b/packages/astro/src/core/middleware/loadMiddleware.ts
@@ -6,9 +6,7 @@ import { MIDDLEWARE_MODULE_ID } from './vite-plugin.js';
*
* If not middlewares were not set, the function returns an empty array.
*/
-export async function loadMiddleware(
- moduleLoader: ModuleLoader,
-) {
+export async function loadMiddleware(moduleLoader: ModuleLoader) {
try {
const module = await moduleLoader.import(MIDDLEWARE_MODULE_ID);
return module;
diff --git a/packages/astro/src/core/middleware/sequence.ts b/packages/astro/src/core/middleware/sequence.ts
index ca3dc90a0..d20641ee3 100644
--- a/packages/astro/src/core/middleware/sequence.ts
+++ b/packages/astro/src/core/middleware/sequence.ts
@@ -7,7 +7,7 @@ import { defineMiddleware } from './index.js';
* It accepts one or more middleware handlers and makes sure that they are run in sequence.
*/
export function sequence(...handlers: MiddlewareEndpointHandler[]): MiddlewareEndpointHandler {
- const filtered = handlers.filter(h => !!h);
+ const filtered = handlers.filter((h) => !!h);
const length = filtered.length;
if (!length) {
const handler: MiddlewareEndpointHandler = defineMiddleware((context, next) => {
diff --git a/packages/astro/src/core/middleware/vite-plugin.ts b/packages/astro/src/core/middleware/vite-plugin.ts
index d25012516..790c76129 100644
--- a/packages/astro/src/core/middleware/vite-plugin.ts
+++ b/packages/astro/src/core/middleware/vite-plugin.ts
@@ -1,23 +1,20 @@
import type { Plugin as VitePlugin } from 'vite';
import { normalizePath } from 'vite';
+import type { AstroSettings } from '../../@types/astro.js';
import { getOutputDirectory } from '../../prerender/utils.js';
-import { MIDDLEWARE_PATH_SEGMENT_NAME } from '../constants.js';
import { addRollupInput } from '../build/add-rollup-input.js';
import type { BuildInternals } from '../build/internal.js';
import type { StaticBuildOptions } from '../build/types.js';
-import type { AstroSettings } from '../../@types/astro.js';
+import { MIDDLEWARE_PATH_SEGMENT_NAME } from '../constants.js';
export const MIDDLEWARE_MODULE_ID = '@astro-middleware';
const EMPTY_MIDDLEWARE = '\0empty-middleware';
-export function vitePluginMiddleware({
- settings
-}: {
- settings: AstroSettings
-}): VitePlugin {
+export function vitePluginMiddleware({ settings }: { settings: AstroSettings }): VitePlugin {
let isCommandBuild = false;
let resolvedMiddlewareId: string | undefined = undefined;
- const hasIntegrationMiddleware = settings.middlewares.pre.length > 0 || settings.middlewares.post.length > 0;
+ const hasIntegrationMiddleware =
+ settings.middlewares.pre.length > 0 || settings.middlewares.post.length > 0;
return {
name: '@astro/plugin-middleware',
@@ -35,7 +32,7 @@ export function vitePluginMiddleware({
if (middlewareId) {
resolvedMiddlewareId = middlewareId.id;
return MIDDLEWARE_MODULE_ID;
- } else if(hasIntegrationMiddleware) {
+ } else if (hasIntegrationMiddleware) {
return MIDDLEWARE_MODULE_ID;
} else {
return EMPTY_MIDDLEWARE;
@@ -51,7 +48,7 @@ export function vitePluginMiddleware({
return 'export const onRequest = undefined';
} else if (id === MIDDLEWARE_MODULE_ID) {
// In the build, tell Vite to emit this file
- if(isCommandBuild) {
+ if (isCommandBuild) {
this.emitFile({
type: 'chunk',
preserveSignature: 'strict',
@@ -81,23 +78,26 @@ export const onRequest = sequence(
};
}
-function createMiddlewareImports(entrypoints: string[], prefix: string): {
- importsCode: string
- sequenceCode: string
+function createMiddlewareImports(
+ entrypoints: string[],
+ prefix: string
+): {
+ importsCode: string;
+ sequenceCode: string;
} {
let importsRaw = '';
let sequenceRaw = '';
let index = 0;
- for(const entrypoint of entrypoints) {
+ for (const entrypoint of entrypoints) {
const name = `_${prefix}_${index}`;
importsRaw += `import { onRequest as ${name} } from '${normalizePath(entrypoint)}';\n`;
- sequenceRaw += `${index > 0 ? ',' : ''}${name}`
+ sequenceRaw += `${index > 0 ? ',' : ''}${name}`;
index++;
}
return {
importsCode: importsRaw,
- sequenceCode: sequenceRaw
+ sequenceCode: sequenceRaw,
};
}
diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts
index 23d2160a4..8b40e5825 100644
--- a/packages/astro/src/integrations/index.ts
+++ b/packages/astro/src/integrations/index.ts
@@ -137,14 +137,17 @@ export async function runHookConfigSetup({
addedClientDirectives.set(name, buildClientDirectiveEntrypoint(name, entrypoint));
},
addMiddleware: ({ order, entrypoint }) => {
- if(typeof updatedSettings.middlewares[order] === 'undefined') {
+ if (typeof updatedSettings.middlewares[order] === 'undefined') {
throw new Error(
`The "${integration.name}" integration is trying to add middleware but did not specify an order.`
);
}
- logger.debug('middleware', `The integration ${integration.name} has added middleware that runs ${
- order === 'pre' ? 'before' : 'after'
- } any application middleware you define.`);
+ logger.debug(
+ 'middleware',
+ `The integration ${integration.name} has added middleware that runs ${
+ order === 'pre' ? 'before' : 'after'
+ } any application middleware you define.`
+ );
updatedSettings.middlewares[order].push(entrypoint);
},
logger: integrationLogger,