[ci] format

This commit is contained in:
matthewp 2022-09-12 20:37:25 +00:00 committed by fredkbot
parent 6efafa4b0e
commit 8903edee88
5 changed files with 20 additions and 15 deletions

View file

@ -8,7 +8,7 @@ export function* walkParentInfos(
ctx: { getModuleInfo: GetModuleInfo },
depth = 0,
seen = new Set<string>(),
childId = '',
childId = ''
): Generator<[ModuleInfo, number, number], void, unknown> {
seen.add(id);
const info = ctx.getModuleInfo(id);

View file

@ -195,13 +195,13 @@ export function sortedCSS(pageData: PageBuildData) {
orderA = a[1].order,
orderB = b[1].order;
if(orderA === -1 && orderB >= 0) {
if (orderA === -1 && orderB >= 0) {
return 1;
} else if(orderB === -1 && orderA >= 0) {
} else if (orderB === -1 && orderA >= 0) {
return -1;
} else if(orderA > orderB) {
} else if (orderA > orderB) {
return 1;
} else if(orderA < orderB) {
} else if (orderA < orderB) {
return -1;
} else {
if (depthA === -1) {

View file

@ -18,7 +18,7 @@ export interface PageBuildData {
component: ComponentPath;
route: RouteData;
moduleSpecifier: string;
css: Map<string, { depth: number; order: number; }>;
css: Map<string, { depth: number; order: number }>;
hoistedScript: { type: 'inline' | 'external'; value: string } | undefined;
}
export type AllPagesData = Record<ComponentPath, PageBuildData>;

View file

@ -110,7 +110,12 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
importedCss: Set<string>;
};
const appendCSSToPage = (pageData: PageBuildData, meta: ViteMetadata, depth: number, order: number) => {
const appendCSSToPage = (
pageData: PageBuildData,
meta: ViteMetadata,
depth: number,
order: number
) => {
for (const importedCssImport of meta.importedCss) {
// CSS is prioritized based on depth. Shared CSS has a higher depth due to being imported by multiple pages.
// Depth info is used when sorting the links on the page.
@ -122,11 +127,11 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
}
// Update the order, preferring the lowest order we have.
if(cssInfo.order === -1) {
cssInfo.order = order;
} else if(order < cssInfo.order && order > -1) {
cssInfo.order = order;
}
if (cssInfo.order === -1) {
cssInfo.order = order;
} else if (order < cssInfo.order && order > -1) {
cssInfo.order = order;
}
} else {
pageData?.css.set(importedCssImport, { depth, order });
}

View file

@ -87,7 +87,7 @@ describe('CSS production ordering', () => {
);
expect(content).to.have.a.lengthOf(3, 'there are 3 stylesheets');
const [,found] = content;
const [, found] = content;
expect(found.css).to.match(/#00f/);
});
@ -97,11 +97,11 @@ describe('CSS production ordering', () => {
let twoHtml = await fixture.readFile('/two/index.html');
let threeHtml = await fixture.readFile('/three/index.html');
for(const html of [oneHtml, twoHtml, threeHtml]) {
for (const html of [oneHtml, twoHtml, threeHtml]) {
const content = await Promise.all(
getLinks(html).map((href) => getLinkContent(fixture, href))
);
const [first] = content;
expect(first.css).to.include('green', 'Came from the injected script');
}