diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index cd844cf0b7..827eadee8f 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -36,7 +36,7 @@ export async function collectPagesData( // with parallelized builds without guaranteeing that this is called first. for (const route of manifest.routes) { // Generate a unique key to identify each page in the build process. - const key = `${route.route}\x00${route.component}`; + const key = `${route.route}&${route.component}`; // static route: if (route.pathname) { const routeCollectionLogTimeout = setInterval(() => { diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index 010ff611ce..e9b9fa6ebf 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -17,8 +17,7 @@ import { } from './internal.js'; import { ASTRO_PAGE_MODULE_ID, ASTRO_PAGE_RESOLVED_MODULE_ID } from './plugins/plugin-pages.js'; import { RESOLVED_SPLIT_MODULE_ID } from './plugins/plugin-ssr.js'; -import { getVirtualModulePageName } from './plugins/util.js'; -import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js'; +import { getPageKeyFromVirtualModulePageName, getVirtualModulePageName } from './plugins/util.js'; import type { PageBuildData, StaticBuildOptions } from './types.js'; import { i18nHasFallback } from './util.js'; @@ -178,25 +177,20 @@ export class BuildPipeline extends Pipeline { retrieveRoutesToGenerate(): Map { const pages = new Map(); - for (const [entrypoint, filePath] of this.internals.entrySpecifierToBundleMap) { + for (const [virtualModulePageName, filePath] of this.internals.entrySpecifierToBundleMap) { // virtual pages can be emitted with different prefixes: // - the classic way are pages emitted with prefix ASTRO_PAGE_RESOLVED_MODULE_ID -> plugin-pages // - pages emitted using `functionPerRoute`, in this case pages are emitted with prefix RESOLVED_SPLIT_MODULE_ID if ( - entrypoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || - entrypoint.includes(RESOLVED_SPLIT_MODULE_ID) + virtualModulePageName.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || + virtualModulePageName.includes(RESOLVED_SPLIT_MODULE_ID) ) { - const [, pageName] = entrypoint.split(':'); - console.log('pageName', pageName); - // TODO: Change that – tmp function use only component name and not the route - const pageData = tmp( - this.internals.pagesByKeys, - pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.') - ); + const pageKey = getPageKeyFromVirtualModulePageName(ASTRO_PAGE_RESOLVED_MODULE_ID, virtualModulePageName) + const pageData = this.internals.pagesByKeys.get(pageKey); if (!pageData) { throw new Error( - "Build failed. Astro couldn't find the emitted page from " + pageName + ' pattern' + "Build failed. Astro couldn't find the emitted page from " + pageKey + ' pattern' ); } @@ -235,12 +229,3 @@ export class BuildPipeline extends Pipeline { return pages; } } - -/** - * TMP: This is a temporary function to get the page data from the pagesByKeys map. - */ -function tmp(pagesByKeys: Map, pageName: string) { - for (const pages of pagesByKeys.values()) { - if (pages.component == pageName) return pages; - } -} diff --git a/packages/astro/src/core/build/plugins/plugin-pages.ts b/packages/astro/src/core/build/plugins/plugin-pages.ts index 1e897cd6fe..99b0269563 100644 --- a/packages/astro/src/core/build/plugins/plugin-pages.ts +++ b/packages/astro/src/core/build/plugins/plugin-pages.ts @@ -21,10 +21,6 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V if (routeIsRedirect(pageData.route)) { continue; } - console.log('pageData', pageData.route.route); - console.log( - getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component, pageData.route.route) - ); inputs.add( getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component, pageData.route.route) ); diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 55b2beec98..877fc33359 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -173,8 +173,9 @@ function vitePluginSSRSplit( const contents: string[] = []; const exports: string[] = []; // TODO: Change that – broken usage of getVirtualModulePageName + // I should refactor getPathFromVirtualModulePageName const path = getPathFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, id); - const virtualModuleName = getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, path); + const virtualModuleName = getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, path, ""); let module = await this.resolve(virtualModuleName); if (module) { // we need to use the non-resolved ID in order to resolve correctly the virtual module diff --git a/packages/astro/src/core/build/plugins/util.ts b/packages/astro/src/core/build/plugins/util.ts index b21a90b253..8291c9f54f 100644 --- a/packages/astro/src/core/build/plugins/util.ts +++ b/packages/astro/src/core/build/plugins/util.ts @@ -53,9 +53,7 @@ export const ASTRO_PAGE_EXTENSION_POST_PATTERN = '@_@'; export function getVirtualModulePageName(virtualModulePrefix: string, path: string, route: string) { const extension = extname(path); return ( - virtualModulePrefix + - (route.startsWith('/') ? route.slice(1) : route) + - ASTRO_PAGE_EXTENSION_POST_PATTERN + + virtualModulePrefix + route + '&' + (extension.startsWith('.') ? path.slice(0, -extension.length) + extension.replace('.', ASTRO_PAGE_EXTENSION_POST_PATTERN) : path) @@ -70,10 +68,10 @@ export function getVirtualModulePageName(virtualModulePrefix: string, path: stri export function getPageKeyFromVirtualModulePageName(virtualModulePrefix: string, id: string) { const [route, path] = id .slice(virtualModulePrefix.length) - .split(ASTRO_PAGE_EXTENSION_POST_PATTERN); + .split("&"); const componentPath = path.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.'); - return `${route}\x00${componentPath}`; + return `${route}&${componentPath}`; } // TODO: Should this be removed? Or refactored in generate.ts ?