From eae90df3230f2cda70563eb36411baad39441970 Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Sun, 9 Oct 2022 05:27:24 -0400 Subject: [PATCH] fix for dev file watching missing some file updates due to platform oddities (#1946) --- v2/cmd/wails/internal/commands/dev/dev.go | 38 ++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/v2/cmd/wails/internal/commands/dev/dev.go b/v2/cmd/wails/internal/commands/dev/dev.go index 66b8079cb..e97c64350 100644 --- a/v2/cmd/wails/internal/commands/dev/dev.go +++ b/v2/cmd/wails/internal/commands/dev/dev.go @@ -574,7 +574,19 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc case err := <-watcher.Errors: LogDarkYellow(err.Error()) case item := <-watcher.Events: - // Check for file writes + isEligibleFile := func(fileName string) bool { + // Iterate all file patterns + ext := filepath.Ext(fileName) + if ext != "" { + ext = ext[1:] + if _, exists := extensionsThatTriggerARebuild[ext]; exists { + return true + } + } + return false + } + + // Handle write operations if item.Op&fsnotify.Write == fsnotify.Write { // Ignore directories itemName := item.Name @@ -582,15 +594,10 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc continue } - // Iterate all file patterns - ext := filepath.Ext(itemName) - if ext != "" { - ext = ext[1:] - if _, exists := extensionsThatTriggerARebuild[ext]; exists { - rebuild = true - timer.Reset(interval) - continue - } + if isEligibleFile(itemName) { + rebuild = true + timer.Reset(interval) + continue } for _, reloadDir := range dirsThatTriggerAReload { @@ -606,7 +613,8 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc timer.Reset(interval) } - // Check for new directories + + // Handle new fs entries that are created if item.Op&fsnotify.Create == fsnotify.Create { // If this is a folder, add it to our watch list if fs.DirExists(item.Name) { @@ -618,6 +626,14 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc } LogGreen("Added new directory to watcher: %s", item.Name) } + } else if isEligibleFile(item.Name) { + // Handle creation of new file. + // Note: On some platforms an update to a file is represented as + // REMOVE -> CREATE instead of WRITE, so this is not only new files + // but also updates to existing files + rebuild = true + timer.Reset(interval) + continue } } case <-timer.C: