Skip to content

Commit

Permalink
Cleanup leftover layers (#4853)
Browse files Browse the repository at this point in the history
* update snapshots with correct version

* add test that verifies @layer is removed correctly

* cleanup leftover `@layer` nodes
  • Loading branch information
RobinMalfait committed Jul 1, 2021
1 parent fe27356 commit f4ea2cf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
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()
}
})
}
}

0 comments on commit f4ea2cf

Please sign in to comment.