From 06a857645ff6de1973bbf6ecb09039c2c642f3f6 Mon Sep 17 00:00:00 2001 From: Cheolwan Park Date: Thu, 18 May 2023 22:58:19 +0900 Subject: [PATCH 1/3] Implementing directory and file Ignore for dev command --- v2/cmd/wails/internal/dev/dev.go | 12 +++++++++--- v2/cmd/wails/internal/dev/watcher.go | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/v2/cmd/wails/internal/dev/dev.go b/v2/cmd/wails/internal/dev/dev.go index 8d11edbf730..dacfeedd43a 100644 --- a/v2/cmd/wails/internal/dev/dev.go +++ b/v2/cmd/wails/internal/dev/dev.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + gitignore "github.com/sabhiram/go-gitignore" "io" "net/http" "net/url" @@ -139,7 +140,8 @@ func Application(f *flags.Dev, logger *clilogger.CLILogger) error { } // create the project files watcher - watcher, err := initialiseWatcher(cwd) + ignorer := gitignore.CompileIgnoreLines(projectConfig.DevIgnorePatterns...) + watcher, err := initialiseWatcher(cwd, ignorer) if err != nil { return err } @@ -165,7 +167,7 @@ func Application(f *flags.Dev, logger *clilogger.CLILogger) error { }() // Watch for changes and trigger restartApp() - debugBinaryProcess = doWatcherLoop(buildOptions, debugBinaryProcess, f, watcher, exitCodeChannel, quitChannel, f.DevServerURL(), legacyUseDevServerInsteadofCustomScheme) + debugBinaryProcess = doWatcherLoop(buildOptions, debugBinaryProcess, f, watcher, ignorer, exitCodeChannel, quitChannel, f.DevServerURL(), legacyUseDevServerInsteadofCustomScheme) // Kill the current program if running and remove dev binary if err := killProcessAndCleanupBinary(debugBinaryProcess, appBinary); err != nil { @@ -337,7 +339,7 @@ func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process } // doWatcherLoop is the main watch loop that runs while dev is active -func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Process, f *flags.Dev, watcher *fsnotify.Watcher, exitCodeChannel chan int, quitChannel chan os.Signal, devServerURL *url.URL, legacyUseDevServerInsteadofCustomScheme bool) *process.Process { +func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Process, f *flags.Dev, watcher *fsnotify.Watcher, ignore *gitignore.GitIgnore, exitCodeChannel chan int, quitChannel chan os.Signal, devServerURL *url.URL, legacyUseDevServerInsteadofCustomScheme bool) *process.Process { // Main Loop var extensionsThatTriggerARebuild = sliceToMap(strings.Split(f.Extensions, ",")) var dirsThatTriggerAReload []string @@ -387,6 +389,10 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc } return false } + // Ignore ignored files + if ignore.MatchesPath(item.Name) { + continue + } // Handle write operations if item.Op&fsnotify.Write == fsnotify.Write { diff --git a/v2/cmd/wails/internal/dev/watcher.go b/v2/cmd/wails/internal/dev/watcher.go index 19caf0df8d1..801d7d50913 100644 --- a/v2/cmd/wails/internal/dev/watcher.go +++ b/v2/cmd/wails/internal/dev/watcher.go @@ -17,7 +17,7 @@ type Watcher interface { } // initialiseWatcher creates the project directory watcher that will trigger recompile -func initialiseWatcher(cwd string) (*fsnotify.Watcher, error) { +func initialiseWatcher(cwd string, ignorer *gitignore.GitIgnore) (*fsnotify.Watcher, error) { // Ignore dot files, node_modules and build directories by default ignoreDirs := getIgnoreDirs(cwd) @@ -34,6 +34,9 @@ func initialiseWatcher(cwd string) (*fsnotify.Watcher, error) { } for _, dir := range processDirectories(dirs.AsSlice(), ignoreDirs) { + if ignorer.MatchesPath(dir) { + continue + } err := watcher.Add(dir) if err != nil { return nil, err From 4a91c46fddb253a351c5cefc43c52d549ad2b1c8 Mon Sep 17 00:00:00 2001 From: ironpark Date: Thu, 27 Jul 2023 18:35:16 +0900 Subject: [PATCH 2/3] Add "ignore" option to project config for `wails dev` mode. --- v2/internal/project/project.go | 3 +++ website/src/pages/changelog.mdx | 1 + 2 files changed, 4 insertions(+) diff --git a/v2/internal/project/project.go b/v2/internal/project/project.go index 023ca1dfed2..4dbcf7674a0 100644 --- a/v2/internal/project/project.go +++ b/v2/internal/project/project.go @@ -27,6 +27,9 @@ type Project struct { DevBuildCommand string `json:"frontend:dev:build"` DevInstallCommand string `json:"frontend:dev:install"` DevWatcherCommand string `json:"frontend:dev:watcher"` + // List of path patterns ignored by the dev command's file watcher + DevIgnorePatterns []string `json:"ignore"` + // The url of the external wails dev server. If this is set, this server is used for the frontend. Default "" FrontendDevServerURL string `json:"frontend:dev:serverUrl"` diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 6ffd1d64c32..69969ae6996 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added smart functionality for the default context-menu in production with CSS styles to control it. Added by @mmghv in [PR](https://github.com/wailsapp/wails/pull/2748) - Added custom error formatting to allow passing structured errors back to the frontend. - Added sveltekit.mdx guide. Added by @figuerom16 in [PR](https://github.com/wailsapp/wails/pull/2771) +- Added "ignore" option to project config so that you can set certain folders, files not to trigger a build in `wails dev` mode. Added by @ironpark in [PR](https://github.com/wailsapp/wails/pull/2676) ### Changed From 3abd8fa787e48828adc9ab8349fda58735dfc9e9 Mon Sep 17 00:00:00 2001 From: ironpark Date: Mon, 31 Jul 2023 12:48:04 +0900 Subject: [PATCH 3/3] Add 'ignore' prop in docs,schemas file --- website/docs/reference/project-config.mdx | 2 ++ website/static/schemas/config.v2.json | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/website/docs/reference/project-config.mdx b/website/docs/reference/project-config.mdx index 8e763502bcc..ed01548a2e6 100644 --- a/website/docs/reference/project-config.mdx +++ b/website/docs/reference/project-config.mdx @@ -16,6 +16,8 @@ The project config resides in the `wails.json` file in the project directory. Th "assetdir": "", // Additional directories to trigger reloads (comma separated), this is only used for some advanced asset configurations "reloaddirs": "", + // Specifies a matching folder or file path that should not trigger a reload when changed. Each pattern follows gitignore's matching rules. + "ignore": [], // The directory where the build files reside. Defaults to 'build' "build:dir": "", // Relative path to the frontend directory. Defaults to 'frontend' diff --git a/website/static/schemas/config.v2.json b/website/static/schemas/config.v2.json index 22a74d56258..d47494aabfb 100644 --- a/website/static/schemas/config.v2.json +++ b/website/static/schemas/config.v2.json @@ -19,6 +19,13 @@ "type": "string", "description": "Additional directories to trigger reloads (comma separated). Often, this is only used for advanced asset configurations." }, + "ignore": { + "type": "array", + "description": "Specifies a matching folder or file path that should not trigger a reload when changed. Each pattern follows gitignore's matching rules.", + "examples": [ + ["*_test.go", "/cmd/cli/*.go"] + ] + }, "build:dir": { "type": "string", "description": "The directory where the build files reside.",