Skip to content

Commit

Permalink
Fix not rebuilding files when change event is emit
Browse files Browse the repository at this point in the history
  • Loading branch information
natrys committed Oct 29, 2022
1 parent c936989 commit bb0e0a8
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/cli/build/watching.js
Expand Up @@ -62,12 +62,19 @@ export function createWatcher(args, { state, rebuild }) {
extension: path.extname(file).slice(1),
})

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

return chain
rebuild(changedContent.splice(0))
}

watcher.on('change', (file) => recordChangedFile(file))
watcher.on('change', (file) => {
// Some applications such as Vim/Neovim fire both rename and change events for atomic writes
// In that case change is preceded by rename, so the rebuild has already been queued
// Therefore it can be skipped for change
if (pendingRebuilds.has(file)) {
return
} else {
chain = chain.then(() => recordChangedFile(file))
}
})
watcher.on('add', (file) => recordChangedFile(file))

// Restore watching any files that are "removed"
Expand Down Expand Up @@ -109,17 +116,21 @@ export function createWatcher(args, { state, rebuild }) {

pendingRebuilds.add(filePath)

chain = chain.then(async () => {
let content
chain = chain
.then(async () => {
let content

try {
content = await readFileWithRetries(path.resolve(filePath))
} finally {
pendingRebuilds.delete(filePath)
}
try {
content = await readFileWithRetries(path.resolve(filePath))
} finally {
pendingRebuilds.delete(filePath)
}

return recordChangedFile(filePath, () => content)
})
return content
})
.then((content) => {
recordChangedFile(filePath, () => content)
})
})

return {
Expand Down

0 comments on commit bb0e0a8

Please sign in to comment.