Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix CLI not rebuilding files when rename event is emit
  • Loading branch information
natrys committed Oct 29, 2022
commit a632ecb882dc660bcbe983d2df52582263152dc6
36 changes: 23 additions & 13 deletions src/cli/build/watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ 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) => {
// 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)) {
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 +115,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