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

Fix missing PostCSS dependencies in the CLI #9617

Merged
merged 5 commits into from
Oct 20, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix missing `supports` in types ([#9616](https://github.com/tailwindlabs/tailwindcss/pull/9616))
- Fix missing PostCSS dependencies in the CLI ([#9617](https://github.com/tailwindlabs/tailwindcss/pull/9617))

## [3.2.0] - 2022-10-19

Expand Down
25 changes: 25 additions & 0 deletions integrations/tailwindcss-cli/tests/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,31 @@ describe('Build command', () => {
`
)

await writeInputFile(
'imported.css',
css`
@layer utilities {
.something-cool {
color: blue;
}
}
`
)

await runningProcess.onStderr(function ready(message) {
return message.includes('Done in')
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
@media (min-width: 768px) {
.md\:something-cool {
color: blue;
}
}
`
)

return runningProcess.stop()
})

Expand Down
101 changes: 101 additions & 0 deletions integrations/tailwindcss-cli/tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,105 @@ describe('watcher', () => {

return runningProcess.stop()
})

test('classes are generated (and kept) when the index.html file changes (and removed when css/config files are changed)', async () => {
let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w')

// Start with a simple single class
await writeInputFile('index.html', html`<div class="font-bold"></div>`)
await runningProcess.onStderr(ready)
expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)

// Add another class
await writeInputFile('index.html', html`<div class="flex font-bold"></div>`)
await runningProcess.onStderr(ready)
expect(await readOutputFile('main.css')).toIncludeCss(
css`
.flex {
display: flex;
}

.font-bold {
font-weight: 700;
}
`
)

// Remove a class, because of performance reasons both classes will still be in the css file
await writeInputFile('index.html', html`<div class="font-bold"></div>`)
await runningProcess.onStderr(ready)
expect(await readOutputFile('main.css')).toIncludeCss(
css`
.flex {
display: flex;
}

.font-bold {
font-weight: 700;
}
`
)

// Save the index.css file, this should trigger a fresh context
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`
)
await runningProcess.onStderr(ready)

// Only 1 class should stay, because we started from scratch
expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)

// Add another class
await writeInputFile('index.html', html`<div class="flex font-bold"></div>`)
await runningProcess.onStderr(ready)
expect(await readOutputFile('main.css')).toIncludeCss(
css`
.flex {
display: flex;
}

.font-bold {
font-weight: 700;
}
`
)

// Remove a class, because of performance reasons both classes will still be in the css file
await writeInputFile('index.html', html`<div class="font-bold"></div>`)
await runningProcess.onStderr(ready)

// If everything goes right, then both classes should still be here (because of the performance
// improvement). If we didn't solve the bug where from now on every save is a fresh context
// then this only has 1 class. So let's hope there are 2!
expect(await readOutputFile('main.css')).toIncludeCss(
css`
.flex {
display: flex;
}

.font-bold {
font-weight: 700;
}
`
)

return runningProcess.stop()
})
})
20 changes: 20 additions & 0 deletions src/cli/build/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@ export async function createProcessor(args, cliConfigPath) {

return readInput()
.then((css) => processor.process(css, { ...postcssOptions, from: input, to: output }))
.then((result) => {
if (!state.watcher) {
return result
}

env.DEBUG && console.time('Recording PostCSS dependencies')
for (let message of result.messages) {
if (message.type === 'dependency') {
state.contextDependencies.add(message.file)
}
}
env.DEBUG && console.timeEnd('Recording PostCSS dependencies')

// TODO: This needs to be in a different spot
env.DEBUG && console.time('Watch new files')
state.watcher.refreshWatchedFiles()
env.DEBUG && console.timeEnd('Watch new files')

return result
})
.then((result) => {
if (!output) {
process.stdout.write(result.css)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/build/watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function createWatcher(args, { state, rebuild }) {
extension: path.extname(file).slice(1),
})

chain = chain.then(() => rebuild(changedContent))
chain = chain.then(() => rebuild(changedContent.splice(0)))

return chain
}
Expand Down