From 6ce836cccae279aa7e5380c26dcdd95426145709 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 30 Aug 2022 10:10:43 -0400 Subject: [PATCH 1/4] =?UTF-8?q?Don=E2=80=99t=20re-add=20files=20in=20the?= =?UTF-8?q?=20CLI=20watcher=20that=20are=20covered=20by=20dynamic=20patter?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They don’t have the same problem. As long as the parent directory is watched their add/change events will fire correctly --- src/cli.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/cli.js b/src/cli.js index 0797be2f211c..d74eab30aaeb 100644 --- a/src/cli.js +++ b/src/cli.js @@ -17,6 +17,7 @@ import getModuleDependencies from './lib/getModuleDependencies' import log from './util/log' import packageJson from '../package.json' import normalizePath from 'normalize-path' +import micromatch from 'micromatch' import { validateConfig } from './util/validateConfig.js' let env = { @@ -837,6 +838,24 @@ async function build() { } let config = refreshConfig(configPath) + let contentPatterns = refreshContentPatterns(config) + + /** + * @param {import('../types/config.js').RequiredConfig} config + * @return {{all: string[], dynamic: string[], static: string[]}} + **/ + function refreshContentPatterns(config) { + let globs = extractFileGlobs(config) + let tasks = fastGlob.generateTasks(globs, { absolute: true }) + let dynamic = tasks.filter((task) => task.dynamic).flatMap((task) => task.patterns) + let staticPatterns = tasks.filter((task) => !task.dynamic).flatMap((task) => task.patterns) + + return { + all: [...staticPatterns, ...dynamicPatterns], + dynamic, + ['static']: staticPatterns, + } + } if (input) { contextDependencies.add(path.resolve(input)) @@ -867,6 +886,7 @@ async function build() { env.DEBUG && console.time('Resolve config') context = null config = refreshConfig(configPath) + contentPatterns = refreshContentPatterns(config) env.DEBUG && console.timeEnd('Resolve config') env.DEBUG && console.time('Watch new files') @@ -924,7 +944,14 @@ async function build() { // Restore watching any files that are "removed" // This can happen when a file is pseudo-atomically replaced (a copy is created, overwritten, the old one is unlinked, and the new one is renamed) // TODO: An an optimization we should allow removal when the config changes - watcher.on('unlink', (file) => watcher.add(file)) + watcher.on('unlink', (file) => { + file = normalizePath(file) + + // Only re-add the file if it's not covered by a dynamic pattern + if (!micromatch.some([file], dynamicPatterns)) { + watcher.add(file) + } + }) // Some applications such as Visual Studio (but not VS Code) // will only fire a rename event for atomic writes and not a change event From f291c048d9fb6a0003b1422c41adf1cc1f2b8f99 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 30 Aug 2022 10:10:56 -0400 Subject: [PATCH 2/4] =?UTF-8?q?Ignore=20raw=20events=20for=20files=20that?= =?UTF-8?q?=20don=E2=80=99t=20match=20the=20content=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cli.js b/src/cli.js index d74eab30aaeb..3020fd96d67d 100644 --- a/src/cli.js +++ b/src/cli.js @@ -962,11 +962,16 @@ async function build() { return } - let watchedPath = path.resolve(meta.watchedPath) + let watchedPath = meta.watchedPath // Watched path might be the file itself // Or the directory it is in - filePath = watchedPath.endsWith(filePath) ? watchedPath : path.resolve(watchedPath, filePath) + filePath = watchedPath.endsWith(filePath) ? watchedPath : path.join(watchedPath, filePath) + + // Skip this event since the files it is for does not match any of the registered content globs + if (!micromatch.some([filePath], contentPatterns.all)) { + return + } // Skip since we've already queued a rebuild for this file that hasn't happened yet if (pendingRebuilds.has(filePath)) { From f7b57d8b4df5218274326124c8eb1acf6ba4f3cb Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 30 Aug 2022 11:09:13 -0400 Subject: [PATCH 3/4] fixup --- src/cli.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cli.js b/src/cli.js index 3020fd96d67d..52c3d08f6b8e 100644 --- a/src/cli.js +++ b/src/cli.js @@ -847,13 +847,12 @@ async function build() { function refreshContentPatterns(config) { let globs = extractFileGlobs(config) let tasks = fastGlob.generateTasks(globs, { absolute: true }) - let dynamic = tasks.filter((task) => task.dynamic).flatMap((task) => task.patterns) + let dynamicPatterns = tasks.filter((task) => task.dynamic).flatMap((task) => task.patterns) let staticPatterns = tasks.filter((task) => !task.dynamic).flatMap((task) => task.patterns) return { all: [...staticPatterns, ...dynamicPatterns], - dynamic, - ['static']: staticPatterns, + dynamic: dynamicPatterns, } } @@ -948,7 +947,7 @@ async function build() { file = normalizePath(file) // Only re-add the file if it's not covered by a dynamic pattern - if (!micromatch.some([file], dynamicPatterns)) { + if (!micromatch.some([file], contentPatterns.dynamic)) { watcher.add(file) } }) From b1b1a33b3931a3fda43527f488054e2f05195e2a Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 31 Aug 2022 12:56:28 -0400 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c16a989dd0b6..e611a5b90219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Sort tags before classes when `@applying` a selector with joined classes ([#9107](https://github.com/tailwindlabs/tailwindcss/pull/9107)) - Remove invalid `outline-hidden` utility ([#9147](https://github.com/tailwindlabs/tailwindcss/pull/9147)) - Honor the `hidden` attribute on elements in preflight ([#9174](https://github.com/tailwindlabs/tailwindcss/pull/9174)) -- Don't stop watching atomically renamed files ([#9173](https://github.com/tailwindlabs/tailwindcss/pull/9173)) +- Don't stop watching atomically renamed files ([#9173](https://github.com/tailwindlabs/tailwindcss/pull/9173), [#9215](https://github.com/tailwindlabs/tailwindcss/pull/9215)) - Re-use existing entries in the rule cache ([#9208](https://github.com/tailwindlabs/tailwindcss/pull/9208)) - Don't output duplicate utilities ([#9208](https://github.com/tailwindlabs/tailwindcss/pull/9208)) - Fix `fontFamily` config TypeScript types ([#9214](https://github.com/tailwindlabs/tailwindcss/pull/9214))