[ci] format

This commit is contained in:
matthewp 2022-08-23 17:28:38 +00:00 committed by fredkbot
parent 27ac6a03a1
commit 77f9afa44a
4 changed files with 32 additions and 29 deletions

View file

@ -189,16 +189,18 @@ export function* eachPageData(internals: BuildInternals) {
* and page-level CSS on bottom.
*/
export function sortedCSS(pageData: PageBuildData) {
return Array.from(pageData.css).sort((a, b) => {
let depthA = a[1].depth,
depthB = b[1].depth;
return Array.from(pageData.css)
.sort((a, b) => {
let depthA = a[1].depth,
depthB = b[1].depth;
if(depthA === -1) {
return -1;
} else if(depthB === -1) {
return 1;
} else {
return depthA > depthB ? -1 : 1;
}
}).map(([id]) => id);
if (depthA === -1) {
return -1;
} else if (depthB === -1) {
return 1;
} else {
return depthA > depthB ? -1 : 1;
}
})
.map(([id]) => id);
}

View file

@ -43,7 +43,10 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
function createNameForParentPages(id: string, ctx: { getModuleInfo: GetModuleInfo }): string {
const parents = Array.from(getTopLevelPages(id, ctx));
const proposedName = parents.map(([page]) => nameifyPage(page.id)).sort().join('-');
const proposedName = parents
.map(([page]) => nameifyPage(page.id))
.sort()
.join('-');
// We don't want absurdedly long chunk names, so if this is too long create a hashed version instead.
if (proposedName.length <= MAX_NAME_LENGTH) {
@ -134,15 +137,15 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
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.
if(pageData?.css.has(importedCssImport)) {
if (pageData?.css.has(importedCssImport)) {
// eslint-disable-next-line
const cssInfo = pageData?.css.get(importedCssImport)!;
if(depth < cssInfo.depth) {
if (depth < cssInfo.depth) {
cssInfo.depth = depth;
}
} else {
pageData?.css.set(importedCssImport, { depth });
}
}
}
}
}

View file

@ -14,9 +14,9 @@ describe('CSS production ordering', () => {
}
/**
*
* @param {import('./test-utils').Fixture} fixture
* @param {string} href
*
* @param {import('./test-utils').Fixture} fixture
* @param {string} href
* @returns {Promise<{ href: string; css: string; }>}
*/
async function getLinkContent(fixture, href) {
@ -27,22 +27,20 @@ describe('CSS production ordering', () => {
describe('SSG and SSR parity', () => {
let staticHTML, serverHTML;
let staticCSS, serverCSS;
const commonConfig = Object.freeze({
root: './fixtures/css-order/',
});
before(async () => {
let fixture = await loadFixture({ ...commonConfig });
await fixture.build();
staticHTML = await fixture.readFile('/one/index.html');
staticCSS = await Promise.all(
getLinks(staticHTML).map(href => getLinkContent(fixture, href))
getLinks(staticHTML).map((href) => getLinkContent(fixture, href))
);
});
before(async () => {
let fixture = await loadFixture({
...commonConfig,
@ -50,7 +48,7 @@ describe('CSS production ordering', () => {
output: 'server',
});
await fixture.build();
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/one');
const response = await app.render(request);
@ -62,11 +60,11 @@ describe('CSS production ordering', () => {
})
);
});
it('is in the same order for output: server and static', async () => {
const staticContent = staticCSS.map((o) => o.css);
const serverContent = serverCSS.map((o) => o.css);
expect(staticContent).to.deep.equal(serverContent);
});
});
@ -85,11 +83,11 @@ describe('CSS production ordering', () => {
let html = await fixture.readFile('/two/index.html');
const content = await Promise.all(
getLinks(html).map(href => getLinkContent(fixture, href))
getLinks(html).map((href) => getLinkContent(fixture, href))
);
expect(content).to.have.a.lengthOf(2, 'there are 2 stylesheets');
const [,last] = content;
const [, last] = content;
expect(last.css).to.match(/#00f/);
});

View file

@ -34,7 +34,7 @@ describe('MDX Page', () => {
const stylesheet = document.querySelector('link[rel="stylesheet"]');
expect(stylesheet).to.not.be.null;
})
});
});
describe('dev', () => {