-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use accumulated sort order when order production CSS (#5549)
* Use accumulated sort order when order production CSS * Adding a changeset * Fix lockfile issue
- Loading branch information
Showing
15 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Use accumulated sort order when order production CSS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('CSS ordering - import order with layouts', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/css-order-layout/', | ||
}); | ||
}); | ||
|
||
/** | ||
* | ||
* @param {string} html | ||
* @returns {string[]} | ||
*/ | ||
function getLinks(html) { | ||
let $ = cheerio.load(html); | ||
let out = []; | ||
$('link[rel=stylesheet]').each((i, el) => { | ||
out.push($(el).attr('href')); | ||
}); | ||
return out; | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} href | ||
* @returns {Promise<{ href: string; css: string; }>} | ||
*/ | ||
async function getLinkContent(href) { | ||
const css = await fixture.readFile(href); | ||
return { href, css }; | ||
} | ||
|
||
describe('Production', () => { | ||
before(async () => { | ||
await fixture.build(); | ||
}); | ||
|
||
it('Page level CSS is defined lower in the page', async () => { | ||
let html = await fixture.readFile('/index.html'); | ||
|
||
|
||
const content = await Promise.all(getLinks(html).map((href) => getLinkContent(href))); | ||
|
||
let specialButtonCSS = -1; | ||
let globalCSS = -1; | ||
for(let i = 0; i < content.length; i++) { | ||
if(content[i].css.indexOf('.SpecialButton') !== -1) { | ||
specialButtonCSS = i; | ||
} else if(content[i].css.indexOf('green') !== -1) { | ||
globalCSS = i; | ||
} | ||
} | ||
|
||
expect(globalCSS).to.equal(0, 'global css sorted on top') | ||
expect(specialButtonCSS).to.equal(1, 'component level css sorted last'); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/css-order-layout/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineConfig } from "astro/config"; | ||
|
||
export default defineConfig({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@test/css-order-layout", | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/astro/test/fixtures/css-order-layout/src/components/BlueButton.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
import Button from "./Button.astro"; | ||
/* | ||
TODO: | ||
- Improve keyboard navigation / focus handling ref: https://w3c.github.io/aria-practices/examples/disclosure/disclosure-navigation.html | ||
*/ | ||
--- | ||
|
||
<style> | ||
.SpecialButton { | ||
color: blue; | ||
} | ||
</style> | ||
|
||
<div>This button should be blue</div> | ||
<Button class="SpecialButton" /> |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/css-order-layout/src/components/Button.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
type Props = { | ||
class?: string; | ||
}; | ||
const { class: className } = Astro.props as Props; | ||
--- | ||
|
||
<button class:list={["btn", className]} type="button"> button</button> |
5 changes: 5 additions & 0 deletions
5
packages/astro/test/fixtures/css-order-layout/src/components/MainHead.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
import "../styles/global.css"; | ||
--- | ||
|
||
<meta charset="UTF-8" /> |
14 changes: 14 additions & 0 deletions
14
packages/astro/test/fixtures/css-order-layout/src/layouts/Main.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
import MainHead from "../components/MainHead.astro"; | ||
import BlueButton from "../components/BlueButton.astro"; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<MainHead /> | ||
</head> | ||
<body> | ||
<BlueButton /> | ||
<slot /> | ||
</body> | ||
</html> |
14 changes: 14 additions & 0 deletions
14
packages/astro/test/fixtures/css-order-layout/src/layouts/Second.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
import MainHead from "../components/MainHead.astro"; | ||
import BlueButton from "../components/BlueButton.astro"; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<MainHead /> | ||
</head> | ||
<body> | ||
<BlueButton /> | ||
<slot /> | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
packages/astro/test/fixtures/css-order-layout/src/pages/admin.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
import MainHead from "../components/MainHead.astro"; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<MainHead /> | ||
</head> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/css-order-layout/src/pages/beta.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
import SecondLayout from "../layouts/Second.astro"; | ||
--- | ||
|
||
<SecondLayout> | ||
|
||
<div> | ||
Subpage (<a href='/'>Home</a>) | ||
</div> | ||
|
||
</SecondLayout> |
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/css-order-layout/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
import MainLayout from "../layouts/Main.astro"; | ||
--- | ||
|
||
<MainLayout> | ||
|
||
<div> | ||
Home (<a href='/beta'>Subpage</a>) | ||
</div> | ||
|
||
</MainLayout> |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/css-order-layout/src/styles/global.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.btn { | ||
color: green; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.