diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index dbd1e915df..1963962ff2 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -44,6 +44,8 @@ import { getOutputFilename, isServerLikeOutput } from '../util.js'; import { getOutDirWithinCwd, getOutFile, getOutFolder } from './common.js'; import { cssOrder, mergeInlineCss } from './internal.js'; import { BuildPipeline } from './pipeline.js'; +import { ASTRO_PAGE_MODULE_ID } from './plugins/plugin-pages.js'; +import { getVirtualModulePageName } from './plugins/util.js'; import type { PageBuildData, SinglePageBuiltModule, @@ -51,8 +53,6 @@ import type { StylesheetAsset, } from './types.js'; import { getTimeStat, shouldAppendForwardSlash } from './util.js'; -import { getVirtualModulePageName } from './plugins/util.js'; -import { ASTRO_PAGE_MODULE_ID } from './plugins/plugin-pages.js'; function createEntryURL(filePath: string, outFolder: URL) { return new URL('./' + filePath + `?time=${Date.now()}`, outFolder); diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index 24389353ba..2c593fa8cf 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -3,8 +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 { PageBuildData, StylesheetAsset, ViteID } from './types.js'; import { makePageDataKey } from './plugins/util.js'; +import type { PageBuildData, StylesheetAsset, ViteID } from './types.js'; export interface BuildInternals { /** @@ -232,11 +232,13 @@ export function* getPageDatasByClientOnlyID( */ export function getPageData( internals: BuildInternals, - route: string, + route: string, component: string ): PageBuildData | undefined { let pageData = internals.pagesByKeys.get(makePageDataKey(route, component)); - if (pageData) { return pageData;} + if (pageData) { + return pageData; + } return undefined; } @@ -250,23 +252,25 @@ export function getPagesDatasByComponent( component: string ): PageBuildData[] { const pageDatas: PageBuildData[] = []; - internals.pagesByKeys.forEach((pageData) => { - if (component === pageData.component) pageDatas.push(pageData); - }) + internals.pagesByKeys.forEach((pageData) => { + if (component === pageData.component) pageDatas.push(pageData); + }); return pageDatas; } // TODO: Should be removed in the future. (Astro 5?) /** * Map internals.pagesByKeys to a new map with the public key instead of the internal key. - * This function is only used to avoid breaking changes in the Integrations API, after we changed the way + * This function is only used to avoid breaking changes in the Integrations API, after we changed the way * we identify pages, from the entrypoint component to an internal key. * If the page component is unique -> the public key is the component path. (old behavior) * If the page component is shared -> the public key is the internal key. (new behavior) * The new behavior on shared entrypoint it's not a breaking change, because it was not supported before. * @param pagesByKeys A map of all page data by their internal key */ -export function getPageDatasWithPublicKey(pagesByKeys: Map): Map { +export function getPageDatasWithPublicKey( + pagesByKeys: Map +): Map { // Create a map to store the pages with the public key, mimicking internal.pagesByKeys const pagesWithPublicKey = new Map(); @@ -378,7 +382,7 @@ export function mergeInlineCss( export function getPageDatasByHoistedScriptId( internals: BuildInternals, id: string -): PageBuildData[]{ +): PageBuildData[] { const set = internals.hoistedScriptIdToPagesMap.get(id); const pageDatas: PageBuildData[] = []; if (set) { diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index cfedc1f2d9..7661b6fc4d 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -23,8 +23,8 @@ import { getOutDirWithinCwd } from './common.js'; import { type BuildInternals, cssOrder, getPageData, mergeInlineCss } 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 type { PageBuildData, SinglePageBuiltModule, StaticBuildOptions } from './types.js'; import { getPagesFromVirtualModulePageName, getVirtualModulePageName } from './plugins/util.js'; +import type { PageBuildData, SinglePageBuiltModule, StaticBuildOptions } from './types.js'; import { i18nHasFallback } from './util.js'; /** diff --git a/packages/astro/src/core/build/plugins/plugin-css.ts b/packages/astro/src/core/build/plugins/plugin-css.ts index c996156021..718f81f879 100644 --- a/packages/astro/src/core/build/plugins/plugin-css.ts +++ b/packages/astro/src/core/build/plugins/plugin-css.ts @@ -145,7 +145,10 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] { if (pageData) { appendCSSToPage(pageData, meta, pagesToCss, depth, order); } - } else if (options.target === 'client' && internals.hoistedScriptIdToPagesMap.has(pageInfo.id)) { + } else if ( + options.target === 'client' && + internals.hoistedScriptIdToPagesMap.has(pageInfo.id) + ) { for (const pageData of getPageDatasByHoistedScriptId(internals, pageInfo.id)) { appendCSSToPage(pageData, meta, pagesToCss, -1, order); } @@ -242,7 +245,7 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] { pageData.styles.push({ ...orderingInfo, sheet }); sheetAddedToPage = true; } - }) + }); // Apply `moduleIdToPropagatedCss` information to `internals.propagatedStylesMap`. // NOTE: It's pretty much a copy over to `internals.propagatedStylesMap` as it should be diff --git a/packages/astro/src/core/build/plugins/plugin-pages.ts b/packages/astro/src/core/build/plugins/plugin-pages.ts index 71195a2e29..9b7faf07c6 100644 --- a/packages/astro/src/core/build/plugins/plugin-pages.ts +++ b/packages/astro/src/core/build/plugins/plugin-pages.ts @@ -21,9 +21,7 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V if (routeIsRedirect(pageData.route)) { continue; } - inputs.add( - getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component) - ); + inputs.add(getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component)); } return addRollupInput(options, Array.from(inputs)); @@ -38,8 +36,12 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V if (id.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) { const imports: string[] = []; const exports: string[] = []; - const pageDatas = getPagesFromVirtualModulePageName(internals, ASTRO_PAGE_RESOLVED_MODULE_ID, id); - for (const pageData of pageDatas) { + const pageDatas = getPagesFromVirtualModulePageName( + internals, + ASTRO_PAGE_RESOLVED_MODULE_ID, + id + ); + for (const pageData of pageDatas) { const resolvedPage = await this.resolve(pageData.moduleSpecifier); if (resolvedPage) { imports.push(`const page = () => import(${JSON.stringify(pageData.moduleSpecifier)});`); diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 97c7ea1cbe..0a10110cd2 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -153,9 +153,7 @@ function vitePluginSSRSplit( if (routeIsRedirect(pageData.route)) { continue; } - inputs.add( - getVirtualModulePageName(SPLIT_MODULE_ID, pageData.component) - ); + inputs.add(getVirtualModulePageName(SPLIT_MODULE_ID, pageData.component)); } return addRollupInput(opts, Array.from(inputs)); diff --git a/packages/astro/src/core/build/plugins/util.ts b/packages/astro/src/core/build/plugins/util.ts index c1552599d9..f1e2bf244a 100644 --- a/packages/astro/src/core/build/plugins/util.ts +++ b/packages/astro/src/core/build/plugins/util.ts @@ -74,17 +74,20 @@ export function getVirtualModulePageName(virtualModulePrefix: string, path: stri } /** - * From the VirtualModulePageName, and the internals, get all pageDatas that use this + * From the VirtualModulePageName, and the internals, get all pageDatas that use this * component as their entry point. * @param virtualModulePrefix The prefix used to create the virtual module * @param id Virtual module name */ -export function getPagesFromVirtualModulePageName(internals: BuildInternals, virtualModulePrefix: string, id: string): PageBuildData[] -{ +export function getPagesFromVirtualModulePageName( + internals: BuildInternals, + virtualModulePrefix: string, + id: string +): PageBuildData[] { const path = getComponentFromVirtualModulePageName(virtualModulePrefix, id); const pages: PageBuildData[] = []; - internals.pagesByKeys.forEach(pageData => { + internals.pagesByKeys.forEach((pageData) => { if (pageData.component === path) { pages.push(pageData); } @@ -100,7 +103,10 @@ export function getPagesFromVirtualModulePageName(internals: BuildInternals, vir * @param virtualModulePrefix The prefix at the beginning of the virtual module * @param id Virtual module name */ -export function getComponentFromVirtualModulePageName(virtualModulePrefix: string, id: string): string { +export function getComponentFromVirtualModulePageName( + virtualModulePrefix: string, + id: string +): string { return id.slice(virtualModulePrefix.length).replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, '.'); } diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index a73835f681..bdd50d3bfb 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -9,7 +9,11 @@ import * as vite from 'vite'; import type { RouteData } from '../../@types/astro.js'; import { PROPAGATED_ASSET_FLAG } from '../../content/consts.js'; import { hasAnyContentFlag } from '../../content/utils.js'; -import { type BuildInternals, createBuildInternals, getPageDatasWithPublicKey } from '../../core/build/internal.js'; +import { + type BuildInternals, + createBuildInternals, + getPageDatasWithPublicKey, +} from '../../core/build/internal.js'; import { emptyDir, removeEmptyDirs } from '../../core/fs/index.js'; import { appendForwardSlash, prependForwardSlash, removeFileExtension } from '../../core/path.js'; import { isModeServerWithNoAdapter, isServerLikeOutput } from '../../core/util.js'; @@ -376,7 +380,9 @@ async function cleanStaticOutput( const onDemandsFiles = new Set(); for (const pageData of internals.pagesByKeys.values()) { const { moduleSpecifier } = pageData; - const bundleId = internals.pageToBundleMap.get(moduleSpecifier) ?? internals.entrySpecifierToBundleMap.get(moduleSpecifier); + const bundleId = + internals.pageToBundleMap.get(moduleSpecifier) ?? + internals.entrySpecifierToBundleMap.get(moduleSpecifier); if (pageData.route.prerender && !pageData.hasSharedModules && !onDemandsFiles.has(bundleId)) { prerenderedFiles.add(bundleId); } else {