From eb7617d719e11f11d8b9fe6b5e83ff36608e253c Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 30 May 2023 17:41:24 -0400 Subject: [PATCH] Refactor --- packages/astro/src/core/app/index.ts | 2 +- packages/astro/src/core/build/generate.ts | 18 +++--------------- .../astro/src/core/build/plugins/plugin-ssr.ts | 4 ++-- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 0d1b0c680..5a849153d 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -177,7 +177,7 @@ export class App { } else { const importComponentInstance = this.#manifest.pageMap.get(route.component); if(!importComponentInstance) { - throw new Error(`Unexpected unable to find a component instance for route ${route.route}`); + throw new Error(`Unexpectedly unable to find a component instance for route ${route.route}`); } const built = await importComponentInstance(); return built.page(); diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index ff89db641..6f22d5914 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -150,12 +150,8 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn } } for(const pageData of eachRedirectPageData(internals)) { - // TODO MOVE - await generatePage(opts, internals, pageData, { - page: () => Promise.resolve(RedirectComponentInstance), - middleware: StaticMiddlewareInstance, - renderers: [] - }, builtPaths); + const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder); + await generatePage(opts, internals, pageData, entry, builtPaths); } } else { for (const [pageData, filePath] of eachPageDataFromEntryPoint(internals)) { @@ -166,15 +162,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn } for(const pageData of eachRedirectPageData(internals)) { const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder); - if(pageData.route.redirectRoute) { - const filePath = getEntryFilePathFromComponentPath(internals, pageData.route.redirectRoute.component); - } - - await generatePage(opts, internals, pageData, { - page: () => Promise.resolve(RedirectComponentInstance), - middleware: StaticMiddlewareInstance, - renderers: [] - }, builtPaths); + await generatePage(opts, internals, pageData, entry, builtPaths); } } diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 28265530c..50c08c642 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -15,7 +15,7 @@ import type { AstroBuildPlugin } from '../plugin'; import type { StaticBuildOptions } from '../types'; import { MIDDLEWARE_MODULE_ID } from './plugin-middleware.js'; import { routeIsRedirect } from '../../redirects/index.js'; -import { getVirtualModulePageIdFromPath } from './plugin-pages.js'; +import { getVirtualModulePageNameFromPath } from './plugin-pages.js'; import { RENDERERS_MODULE_ID } from './plugin-renderers.js'; export const SSR_VIRTUAL_MODULE_ID = '@astrojs-ssr-virtual-entry'; @@ -60,7 +60,7 @@ function vitePluginSSR( if(routeIsRedirect(pageData.route)) { continue; } - const virtualModuleName = getVirtualModulePageIdFromPath(path); + const virtualModuleName = getVirtualModulePageNameFromPath(path); let module = await this.resolve(virtualModuleName); if (module) { const variable = `_page${i}`;