Skip to content

Commit ee945bb

Browse files
authoredMar 2, 2022
Add an explicit --poll option to the CLI (#7725)
* Refactor * Allow user to enable polling * Update changelog
1 parent f679362 commit ee945bb

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
3232
- Add `text-start` and `text-end` utilities ([#6656](https://github.com/tailwindlabs/tailwindcss/pull/6656))
3333
- Support customizing class name when using `darkMode: 'class'` ([#5800](https://github.com/tailwindlabs/tailwindcss/pull/5800))
34+
- Add `--poll` option to the CLI ([#7725](https://github.com/tailwindlabs/tailwindcss/pull/7725))
3435

3536
## [3.0.23] - 2022-02-16
3637

‎integrations/tailwindcss-cli/tests/cli.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ describe('Build command', () => {
291291
-i, --input Input file
292292
-o, --output Output file
293293
-w, --watch Watch for changes and rebuild as needed
294+
-p, --poll Use polling instead of filesystem events when watching
294295
--content Content paths to use for removing unused classes
295296
--postcss Load custom PostCSS configuration
296297
-m, --minify Minify the output

‎src/cli.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ let commands = {
161161
'--input': { type: String, description: 'Input file' },
162162
'--output': { type: String, description: 'Output file' },
163163
'--watch': { type: Boolean, description: 'Watch for changes and rebuild as needed' },
164+
'--poll': {
165+
type: Boolean,
166+
description: 'Use polling instead of filesystem events when watching',
167+
},
164168
'--content': {
165169
type: String,
166170
description: 'Content paths to use for removing unused classes',
@@ -187,6 +191,7 @@ let commands = {
187191
'-o': '--output',
188192
'-m': '--minify',
189193
'-w': '--watch',
194+
'-p': '--poll',
190195
},
191196
},
192197
}
@@ -367,8 +372,14 @@ async function build() {
367372
let input = args['--input']
368373
let output = args['--output']
369374
let shouldWatch = args['--watch']
375+
let shouldPoll = args['--poll']
376+
let shouldCoalesceWriteEvents = shouldPoll || process.platform === 'win32'
370377
let includePostCss = args['--postcss']
371378

379+
// Polling interval in milliseconds
380+
// Used only when polling or coalescing add/change events on Windows
381+
let pollInterval = 10
382+
372383
// TODO: Deprecate this in future versions
373384
if (!input && args['_'][1]) {
374385
console.error('[deprecation] Running tailwindcss without -i, please provide an input file.')
@@ -746,14 +757,15 @@ async function build() {
746757
}
747758

748759
watcher = chokidar.watch([...contextDependencies, ...extractFileGlobs(config)], {
760+
usePolling: shouldPoll,
761+
interval: shouldPoll ? pollInterval : undefined,
749762
ignoreInitial: true,
750-
awaitWriteFinish:
751-
process.platform === 'win32'
752-
? {
753-
stabilityThreshold: 50,
754-
pollInterval: 10,
755-
}
756-
: false,
763+
awaitWriteFinish: shouldCoalesceWriteEvents
764+
? {
765+
stabilityThreshold: 50,
766+
pollInterval: pollInterval,
767+
}
768+
: false,
757769
})
758770

759771
let chain = Promise.resolve()

0 commit comments

Comments
 (0)
Please sign in to comment.