mirror of
https://github.com/withastro/astro.git
synced 2025-04-14 23:51:49 -05:00
refactor getPageKeyFromVirtualModulePageName
This commit is contained in:
parent
9306c7113f
commit
03d4c5993b
4 changed files with 18 additions and 9 deletions
|
@ -5,7 +5,7 @@ import { type BuildInternals } from '../internal.js';
|
|||
import type { AstroBuildPlugin } from '../plugin.js';
|
||||
import type { StaticBuildOptions } from '../types.js';
|
||||
import { RENDERERS_MODULE_ID } from './plugin-renderers.js';
|
||||
import { getPathFromVirtualModulePageName, getVirtualModulePageName } from './util.js';
|
||||
import { getPageKeyFromVirtualModulePageName, getVirtualModulePageName } from './util.js';
|
||||
|
||||
export const ASTRO_PAGE_MODULE_ID = '@astro-page:';
|
||||
export const ASTRO_PAGE_RESOLVED_MODULE_ID = '\0' + ASTRO_PAGE_MODULE_ID;
|
||||
|
@ -30,8 +30,6 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V
|
|||
);
|
||||
}
|
||||
|
||||
console.log('inputs', inputs);
|
||||
|
||||
return addRollupInput(options, Array.from(inputs));
|
||||
}
|
||||
},
|
||||
|
@ -44,9 +42,9 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V
|
|||
if (id.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
|
||||
const imports: string[] = [];
|
||||
const exports: string[] = [];
|
||||
const pageName = getPathFromVirtualModulePageName(ASTRO_PAGE_RESOLVED_MODULE_ID, id);
|
||||
// TODO: Change that
|
||||
const pageData = tmp(internals.pagesByKeys, pageName);
|
||||
const pageData = internals.pagesByKeys.get(
|
||||
getPageKeyFromVirtualModulePageName(ASTRO_PAGE_RESOLVED_MODULE_ID, id)
|
||||
);
|
||||
if (pageData) {
|
||||
const resolvedPage = await this.resolve(pageData.moduleSpecifier);
|
||||
if (resolvedPage) {
|
||||
|
|
|
@ -172,7 +172,7 @@ function vitePluginSSRSplit(
|
|||
const imports: string[] = [];
|
||||
const contents: string[] = [];
|
||||
const exports: string[] = [];
|
||||
|
||||
// TODO: Change that
|
||||
const path = getPathFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, id);
|
||||
const virtualModuleName = getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, path);
|
||||
let module = await this.resolve(virtualModuleName);
|
||||
|
@ -206,6 +206,7 @@ function vitePluginSSRSplit(
|
|||
for (const moduleKey of Object.keys(chunk.modules)) {
|
||||
if (moduleKey.startsWith(RESOLVED_SPLIT_MODULE_ID)) {
|
||||
internals.ssrSplitEntryChunks.set(moduleKey, chunk);
|
||||
// TODO: Change that
|
||||
storeEntryPoint(moduleKey, options, internals, chunk.fileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,11 +63,20 @@ export function getVirtualModulePageName(virtualModulePrefix: string, path: stri
|
|||
}
|
||||
|
||||
/**
|
||||
* Reverts the virtual module naming convention to the original path.
|
||||
* See `getVirtualModulePageName`(above) for more information.
|
||||
* From the VirtualModulePageName, get the original pageData key.
|
||||
* @param virtualModulePrefix The prefix used to create the virtual module
|
||||
* @param id Virtual module name
|
||||
*/
|
||||
export function getPageKeyFromVirtualModulePageName(virtualModulePrefix: string, id: string) {
|
||||
const [route, path] = id
|
||||
.slice(virtualModulePrefix.length)
|
||||
.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
|
||||
|
||||
const componentPath = path.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.');
|
||||
return `${route}\x00${componentPath}`;
|
||||
}
|
||||
|
||||
// TODO: Should this be removed? Or refactored in generate.ts ?
|
||||
export function getPathFromVirtualModulePageName(virtualModulePrefix: string, id: string) {
|
||||
const pageName = id.slice(virtualModulePrefix.length);
|
||||
return pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.');
|
||||
|
|
|
@ -221,6 +221,7 @@ export async function loadFixture(inlineConfig) {
|
|||
return app;
|
||||
},
|
||||
loadEntryPoint: async (pagePath, routes, streaming) => {
|
||||
// TODO: Change that
|
||||
const virtualModule = getVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, pagePath);
|
||||
const filePath = makeSplitEntryPointFileName(virtualModule, routes);
|
||||
const url = new URL(`./server/${filePath}?id=${fixtureId}`, config.outDir);
|
||||
|
|
Loading…
Add table
Reference in a new issue