mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
[ci] format
This commit is contained in:
parent
698c2d9bb5
commit
6382d7d238
8 changed files with 48 additions and 29 deletions
|
@ -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);
|
||||
|
|
|
@ -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<string, PageBuildData>): Map<string, PageBuildData> {
|
||||
export function getPageDatasWithPublicKey(
|
||||
pagesByKeys: Map<string, PageBuildData>
|
||||
): Map<string, PageBuildData> {
|
||||
// Create a map to store the pages with the public key, mimicking internal.pagesByKeys
|
||||
const pagesWithPublicKey = new Map<string, PageBuildData>();
|
||||
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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';
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)});`);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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, '.');
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue