Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <f@zenc.io>
- Loading branch information
Showing
12 changed files
with
150 additions
and
19 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/playground/css/postcss-caching/blue-app/imported.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 @@ | ||
.postcss-a { | ||
color: pink; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/playground/css/postcss-caching/blue-app/index.html
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,12 @@ | ||
<div class="wrapper"> | ||
<h1>CSS</h1> | ||
|
||
<p>Imported css string:</p> | ||
<pre class="imported-css"></pre> | ||
|
||
<p class="postcss-a">This should be blue</p> | ||
|
||
<p class="postcss-b">This should be black</p> | ||
</div> | ||
|
||
<script type="module" src="./main.js"></script> |
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 @@ | ||
import css from './imported.css' | ||
text('.imported-css', css) | ||
|
||
function text(el, text) { | ||
document.querySelector(el).textContent = text | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/playground/css/postcss-caching/blue-app/package.json
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 @@ | ||
{ | ||
"name": "blue-app", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/playground/css/postcss-caching/blue-app/postcss.config.js
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,15 @@ | ||
module.exports = { | ||
plugins: [replacePinkWithBlue] | ||
} | ||
|
||
function replacePinkWithBlue() { | ||
return { | ||
postcssPlugin: 'replace-pink-with-blue', | ||
Declaration(decl) { | ||
if (decl.value === 'pink') { | ||
decl.value = 'blue' | ||
} | ||
} | ||
} | ||
} | ||
replacePinkWithBlue.postcss = true |
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,29 @@ | ||
import { getColor } from '../../testUtils' | ||
import { createServer } from 'vite' | ||
import path from 'path' | ||
|
||
test('postcss config', async () => { | ||
const port = 5005 | ||
const blueAppDir = path.join(__dirname, 'blue-app') | ||
const greenAppDir = path.join(__dirname, 'green-app') | ||
|
||
process.chdir(blueAppDir) | ||
const blueApp = await createServer() | ||
await blueApp.listen(port) | ||
await page.goto(`http://localhost:${port}`) | ||
const blueA = await page.$('.postcss-a') | ||
expect(await getColor(blueA)).toBe('blue') | ||
const blueB = await page.$('.postcss-b') | ||
expect(await getColor(blueB)).toBe('black') | ||
await blueApp.close() | ||
|
||
process.chdir(greenAppDir) | ||
const greenApp = await createServer() | ||
await greenApp.listen(port) | ||
await page.goto(`http://localhost:${port}`) | ||
const greenA = await page.$('.postcss-a') | ||
expect(await getColor(greenA)).toBe('black') | ||
const greenB = await page.$('.postcss-b') | ||
expect(await getColor(greenB)).toBe('green') | ||
await greenApp.close() | ||
}) |
3 changes: 3 additions & 0 deletions
3
packages/playground/css/postcss-caching/green-app/imported.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 @@ | ||
.postcss-b { | ||
color: pink; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/playground/css/postcss-caching/green-app/index.html
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,12 @@ | ||
<div class="wrapper"> | ||
<h1>CSS</h1> | ||
|
||
<p>Imported css string:</p> | ||
<pre class="imported-css"></pre> | ||
|
||
<p class="postcss-a">This should be black</p> | ||
|
||
<p class="postcss-b">This should be green</p> | ||
</div> | ||
|
||
<script type="module" src="./main.js"></script> |
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 @@ | ||
import css from './imported.css' | ||
text('.imported-css', css) | ||
|
||
function text(el, text) { | ||
document.querySelector(el).textContent = text | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/playground/css/postcss-caching/green-app/package.json
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 @@ | ||
{ | ||
"name": "green-app", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/playground/css/postcss-caching/green-app/postcss.config.js
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,15 @@ | ||
module.exports = { | ||
plugins: [replacePinkWithGreen] | ||
} | ||
|
||
function replacePinkWithGreen() { | ||
return { | ||
postcssPlugin: 'replace-pink-with-green', | ||
Declaration(decl) { | ||
if (decl.value === 'pink') { | ||
decl.value = 'green' | ||
} | ||
} | ||
} | ||
} | ||
replacePinkWithGreen.postcss = true |
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