Fix watching of files on Linux when renames are involved (#9796)

* Fix watching files on Linux

* Update changelog
This commit is contained in:
Jordan Pittman 2022-11-10 12:33:42 -05:00 committed by GitHub
parent 757a8d64a8
commit 1482c7512a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Nothing yet!
### Fixed
- Fix watching of files on Linux when renames are involved ([#9796](https://github.com/tailwindlabs/tailwindcss/pull/9796))
## [3.2.3] - 2022-11-09

View File

@ -97,14 +97,15 @@ export function createWatcher(args, { state, rebuild }) {
*
* @param {*} file
* @param {(() => Promise<string>) | null} content
* @param {boolean} skipPendingCheck
* @returns {Promise<void>}
*/
function recordChangedFile(file, content = null) {
function recordChangedFile(file, content = null, skipPendingCheck = false) {
file = path.resolve(file)
// Applications like Vim/Neovim fire both rename and change events in succession for atomic writes
// In that case rebuild has already been queued by rename, so can be skipped in change
if (pendingRebuilds.has(file)) {
if (pendingRebuilds.has(file) && !skipPendingCheck) {
return Promise.resolve()
}
@ -198,8 +199,10 @@ export function createWatcher(args, { state, rebuild }) {
}
// This will push the rebuild onto the chain
// We MUST skip the rebuild check here otherwise the rebuild will never happen on Linux
// This is because the order of events and timing is different on Linux
// @ts-ignore: TypeScript isn't picking up that content is a string here
await recordChangedFile(filePath, () => content)
await recordChangedFile(filePath, () => content, true)
} catch {
// If reading the file fails, it's was probably a deleted temporary file
// So we can ignore it and no rebuild is needed