0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-03 22:29:08 -05:00

[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) => {
return Array.from(pageData.css)
.sort((a, b) => {
let depthA = a[1].depth,
depthB = b[1].depth;
if(depthA === -1) {
if (depthA === -1) {
return -1;
} else if(depthB === -1) {
} else if (depthB === -1) {
return 1;
} else {
return depthA > depthB ? -1 : 1;
}
}).map(([id]) => id);
})
.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,10 +137,10 @@ 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 {

View file

@ -32,14 +32,12 @@ describe('CSS production ordering', () => {
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))
);
});
@ -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', () => {