mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
better key and fix build
This commit is contained in:
parent
7e7469f5c2
commit
57137fd5a8
5 changed files with 13 additions and 33 deletions
|
@ -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(() => {
|
||||
|
|
|
@ -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<PageBuildData, string> {
|
||||
const pages = new Map<PageBuildData, string>();
|
||||
|
||||
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<string, any>, pageName: string) {
|
||||
for (const pages of pagesByKeys.values()) {
|
||||
if (pages.component == pageName) return pages;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ?
|
||||
|
|
Loading…
Reference in a new issue