Skip to content

Commit

Permalink
Fix watching of files on Linux when renames are involved (#9796)
Browse files Browse the repository at this point in the history
* Fix watching files on Linux

* Update changelog
  • Loading branch information
thecrypticace committed Nov 10, 2022
1 parent 757a8d6 commit 1482c75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/cli/build/watching.js
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1482c75

Please sign in to comment.