Skip to content

Commit 3a97644

Browse files
y1d7ngfwouts
andauthored
fix(css): cachedPostcssConfig reused for multiple builds (#3906)
* fix(css): cachedPostcssConfig reused for multiple builds * fix: add tests to demonstrate that PostCSS configs are not reused across projects * fix: run everything in a single Jest test to ensure module cache isn't cleared Co-authored-by: François Wouts <[email protected]>
1 parent 558e2a0 commit 3a97644

File tree

12 files changed

+150
-19
lines changed

12 files changed

+150
-19
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.postcss-a {
2+
color: pink;
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="wrapper">
2+
<h1>CSS</h1>
3+
4+
<p>Imported css string:</p>
5+
<pre class="imported-css"></pre>
6+
7+
<p class="postcss-a">This should be blue</p>
8+
9+
<p class="postcss-b">This should be black</p>
10+
</div>
11+
12+
<script type="module" src="./main.js"></script>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import css from './imported.css'
2+
text('.imported-css', css)
3+
4+
function text(el, text) {
5+
document.querySelector(el).textContent = text
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "blue-app",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"debug": "node --inspect-brk ../../vite/bin/vite",
9+
"serve": "vite preview"
10+
}
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
plugins: [replacePinkWithBlue]
3+
}
4+
5+
function replacePinkWithBlue() {
6+
return {
7+
postcssPlugin: 'replace-pink-with-blue',
8+
Declaration(decl) {
9+
if (decl.value === 'pink') {
10+
decl.value = 'blue'
11+
}
12+
}
13+
}
14+
}
15+
replacePinkWithBlue.postcss = true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { getColor } from '../../testUtils'
2+
import { createServer } from 'vite'
3+
import path from 'path'
4+
5+
test('postcss config', async () => {
6+
const port = 5005
7+
const blueAppDir = path.join(__dirname, 'blue-app')
8+
const greenAppDir = path.join(__dirname, 'green-app')
9+
10+
process.chdir(blueAppDir)
11+
const blueApp = await createServer()
12+
await blueApp.listen(port)
13+
await page.goto(`http://localhost:${port}`)
14+
const blueA = await page.$('.postcss-a')
15+
expect(await getColor(blueA)).toBe('blue')
16+
const blueB = await page.$('.postcss-b')
17+
expect(await getColor(blueB)).toBe('black')
18+
await blueApp.close()
19+
20+
process.chdir(greenAppDir)
21+
const greenApp = await createServer()
22+
await greenApp.listen(port)
23+
await page.goto(`http://localhost:${port}`)
24+
const greenA = await page.$('.postcss-a')
25+
expect(await getColor(greenA)).toBe('black')
26+
const greenB = await page.$('.postcss-b')
27+
expect(await getColor(greenB)).toBe('green')
28+
await greenApp.close()
29+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.postcss-b {
2+
color: pink;
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="wrapper">
2+
<h1>CSS</h1>
3+
4+
<p>Imported css string:</p>
5+
<pre class="imported-css"></pre>
6+
7+
<p class="postcss-a">This should be black</p>
8+
9+
<p class="postcss-b">This should be green</p>
10+
</div>
11+
12+
<script type="module" src="./main.js"></script>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import css from './imported.css'
2+
text('.imported-css', css)
3+
4+
function text(el, text) {
5+
document.querySelector(el).textContent = text
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "green-app",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"debug": "node --inspect-brk ../../vite/bin/vite",
9+
"serve": "vite preview"
10+
}
11+
}

0 commit comments

Comments
 (0)