0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

internals: getPageData function

This commit is contained in:
Goulven Clec'h 2024-04-24 23:27:19 +02:00
parent 96a6518aba
commit 87930176fc
4 changed files with 26 additions and 6 deletions

View file

@ -256,6 +256,7 @@ async function generatePage(
// prepare information we need
const { config, internals, logger } = pipeline;
const pageModulePromise = ssrEntry.page;
// TODO: Why do we need to get PageData from PageData?
const pageInfo = getPageDataByComponent(internals, pageData.route.component);
// Calculate information of the page, like scripts, links and styles
@ -617,7 +618,7 @@ function createBuildManifest(
}
/**
* TODO: Change that document & maybe refactor
* For a given pageData, returns the entry file pathaka a resolved virtual module in our internals' specifiers.
*/
function getEntryFilePath(internals: BuildInternals, pageData: RouteData) {
const id =

View file

@ -3,7 +3,8 @@ import type { RouteData, SSRResult } from '../../@types/astro.js';
import type { PageOptions } from '../../vite-plugin-astro/types.js';
import { prependForwardSlash, removeFileExtension } from '../path.js';
import { viteID } from '../util.js';
import type { AllPagesData, PageBuildData, StylesheetAsset, ViteID } from './types.js';
import type { PageBuildData, StylesheetAsset, ViteID } from './types.js';
import { makePageDataKey } from './plugins/util.js';
export interface BuildInternals {
/**
@ -215,11 +216,30 @@ export function* getPageDatasByClientOnlyID(
}
}
/**
* From its route and component, get the page data from the build internals.
* @param internals Build Internals with all the pages
* @param route The route of the page, used to identify the page
* @param component The component of the page, used to identify the page
*/
export function getPageData(
internals: BuildInternals,
route: string,
component: string
): PageBuildData | undefined {
let pageData = internals.pagesByKeys.get(makePageDataKey(route, component));
if (pageData) { return pageData;}
return undefined;
}
/**
* TODO: remove this function, obsolete.
* last usage in astro/packages/astro/src/core/build/generate.ts
*/
export function getPageDataByComponent(
internals: BuildInternals,
component: string
): PageBuildData | undefined {
// TODO: Refactor that
if (internals.pagesByKeys.has(component)) {
return internals.pagesByKeys.get(component);
}

View file

@ -12,7 +12,7 @@ import {
import {
type BuildInternals,
cssOrder,
getPageDataByComponent,
getPageData,
mergeInlineCss,
} from './internal.js';
import { ASTRO_PAGE_MODULE_ID, ASTRO_PAGE_RESOLVED_MODULE_ID } from './plugins/plugin-pages.js';
@ -131,7 +131,7 @@ export class BuildPipeline extends Pipeline {
settings,
} = this;
const links = new Set<never>();
const pageBuildData = getPageDataByComponent(internals, routeData.component);
const pageBuildData = getPageData(internals, routeData.route, routeData.component);
const scripts = createModuleScriptsSet(
pageBuildData?.hoistedScript ? [pageBuildData.hoistedScript] : [],
base,

View file

@ -203,7 +203,6 @@ 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);
}
}