Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing directory and file Ignore for dev command #2676

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
12 changes: 9 additions & 3 deletions v2/cmd/wails/internal/dev/dev.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
gitignore "github.com/sabhiram/go-gitignore"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion v2/cmd/wails/internal/dev/watcher.go
Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions v2/internal/project/project.go
Expand Up @@ -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"`

Expand Down
2 changes: 2 additions & 0 deletions website/docs/reference/project-config.mdx
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/changelog.mdx
Expand Up @@ -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)
- Added ProgramName option to [linux.Options](/docs/reference/options#linux). Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2817)

### Changed
Expand Down
7 changes: 7 additions & 0 deletions website/static/schemas/config.v2.json
Expand Up @@ -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.",
Expand Down