Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup leftover layers #4853

Merged
merged 3 commits into from Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions integrations/tailwindcss-cli/tests/cli.test.js
Expand Up @@ -258,7 +258,7 @@ describe('Build command', () => {

expect(combined).toMatchInlineSnapshot(`
"
tailwindcss v2.1.2
tailwindcss v2.2.4
Usage:
tailwindcss build [options]
Expand Down Expand Up @@ -348,7 +348,7 @@ describe('Init command', () => {

expect(combined).toMatchInlineSnapshot(`
"
tailwindcss v2.1.2
tailwindcss v2.2.4
Usage:
tailwindcss init [options]
Expand Down
55 changes: 55 additions & 0 deletions integrations/tailwindcss-cli/tests/integration.test.js
Expand Up @@ -132,6 +132,61 @@ describe('watcher', () => {
return runningProcess.stop()
})

test('@layers are replaced and cleaned when the html file changes', async () => {
await writeInputFile('index.html', html`<div class="font-bold"></div>`)
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
html {
scroll-behavior: smooth;
}
}
`
)

let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w')

await waitForOutputFileCreation('main.css')

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)

await waitForOutputFileChange('main.css', async () => {
await appendToInputFile('index.html', html`<div class="font-normal"></div>`)
})

expect(await readOutputFile('main.css')).not.toIncludeCss(css`
@layer base {
html {
scroll-behavior: smooth;
}
}
`)

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
.font-normal {
font-weight: 400;
}
`
)

return runningProcess.stop()
})

test('classes are generated when the tailwind.config.js file changes', async () => {
await writeInputFile('index.html', html`<div class="font-bold md:font-medium"></div>`)

Expand Down
7 changes: 7 additions & 0 deletions src/jit/lib/expandTailwindAtRules.js
Expand Up @@ -238,5 +238,12 @@ export default function expandTailwindAtRules(context) {

// Clear the cache for the changed files
context.changedContent = []

// Cleanup any leftover @layer atrules
root.walkAtRules('layer', (rule) => {
if (Object.keys(layerNodes).includes(rule.params)) {
rule.remove()
}
})
}
}