From c57e9497b5d4866742652acffbe365abc002fa51 Mon Sep 17 00:00:00 2001 From: Niklas Hanft Date: Wed, 20 Nov 2024 20:16:06 +0100 Subject: [PATCH] Add excludes feature and remove 10k file watcher hard limit Note: I tried watching node_modules, it will crash no matter how buffered your watcher is --- .nfs.yml | 2 ++ cmd/root.go | 6 +----- internal/config/v1/config.go | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.nfs.yml b/.nfs.yml index 0b1be88..bfe2535 100644 --- a/.nfs.yml +++ b/.nfs.yml @@ -11,6 +11,8 @@ pod: watch: - pattern: "./**/*.php" + excludes: + - "node_modules" hooks: - "yarn run build" - pattern: "*.go" diff --git a/cmd/root.go b/cmd/root.go index 6b70d1e..72afbbc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -43,7 +43,7 @@ var rootCmd = &cobra.Command{ for _, watchConfig := range config.WatchConfig { err = doublestar.GlobWalk(fsys, watchConfig.Pattern, func(path string, d fs.DirEntry) error { - for _, exclude := range v1.GlobalExclude { + for _, exclude := range watchConfig.Excludes { if strings.Contains(path, exclude) { return doublestar.SkipDir } @@ -64,10 +64,6 @@ var rootCmd = &cobra.Command{ slices.Sort(filesToWatch) slices.Compact(filesToWatch) - if len(filesToWatch) >= 10000 { - panic("Watching too many files") - } - fmt.Printf("Setup watchers for %d files.\n", len(filesToWatch)) for _, path := range filesToWatch { diff --git a/internal/config/v1/config.go b/internal/config/v1/config.go index af95d59..7c11d26 100644 --- a/internal/config/v1/config.go +++ b/internal/config/v1/config.go @@ -8,8 +8,9 @@ import ( var GlobalExclude = []string{"node_modules", ".git", ".nuxt", "test"} type NfsWatchConfig struct { - Pattern string - Hooks []string + Pattern string + Hooks []string + Excludes []string } type NfsPodConfig struct {