Skip to content

Commit

Permalink
chore: rebase and update
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 23, 2023
1 parent 7bacc21 commit 4217953
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 3 additions & 5 deletions packages/astro/src/core/build/plugins/plugin-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ export function vitePluginMiddleware(
return {
name: '@astro/plugin-middleware',
options(options) {
if (opts.settings.config.experimental.middleware) {
return addRollupInput(options, [MIDDLEWARE_MODULE_ID]);
}
return addRollupInput(options, [MIDDLEWARE_MODULE_ID]);
},

resolveId(id) {
if (id === MIDDLEWARE_MODULE_ID && opts.settings.config.experimental.middleware) {
if (id === MIDDLEWARE_MODULE_ID) {
return RESOLVED_MIDDLEWARE_MODULE_ID;
}
},

async load(id) {
if (id === RESOLVED_MIDDLEWARE_MODULE_ID && opts.settings.config.experimental.middleware) {
if (id === RESOLVED_MIDDLEWARE_MODULE_ID) {
const imports: string[] = [];
const exports: string[] = [];
let middlewareId = await this.resolve(
Expand Down
9 changes: 3 additions & 6 deletions packages/astro/src/core/build/plugins/plugin-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V

async load(id) {
if (id === resolvedPagesVirtualModuleId) {
let middlewareId = await this.resolve(
`${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}`
);

let importMap = '';
const imports: string[] = [];
const exports: string[] = [];
Expand All @@ -45,8 +41,9 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V
i++;
}

if (opts.settings.config.experimental.middleware) {
imports.push(`import * as _middleware from "${MIDDLEWARE_MODULE_ID}";`);
let middlewareModule = await this.resolve(MIDDLEWARE_MODULE_ID);
if (middlewareModule) {
imports.push(`import * as _middleware from "${middlewareModule.id}";`);
exports.push(`export const middleware = _middleware;`);
}

Expand Down

0 comments on commit 4217953

Please sign in to comment.