typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

[bug] watch mode triggers continuously

Open tmm1 opened this issue 7 months ago • 3 comments

❯ time tsgo tsc -noEmit -w -p src
build triggered due to config change
build starting at 2025-04-08 16:46:43.150158 -0700 PDT m=+0.937383709
build finished in 5.714491375s
build triggered due to config change
build starting at 2025-04-08 16:46:50.457319 -0700 PDT m=+8.244531876
build finished in 5.544717875s
build triggered due to config change
build starting at 2025-04-08 16:46:57.955792 -0700 PDT m=+15.742991834
build finished in 5.286759958s
build triggered due to config change
diff --git i/internal/execute/watcher.go w/internal/execute/watcher.go
index af20829e6..087daf754 100644
--- i/internal/execute/watcher.go
+++ w/internal/execute/watcher.go
@@ -1,6 +1,7 @@
 package execute
 
 import (
+	"fmt"
 	"time"
 
 	"github.com/microsoft/typescript-go/internal/compiler"
@@ -50,6 +51,7 @@ func (w *watcher) hasErrorsInTsConfig() bool {
 			return true
 		}
 		if w.options.CompilerOptions() != configParseResult.CompilerOptions() {
+			fmt.Fprint(w.sys.Writer(), "build triggered due to config change", w.sys.NewLine())
 			w.configModified = true
 		}
 		w.options = configParseResult
@@ -73,12 +75,14 @@ func (w *watcher) hasBeenModified(program *compiler.Program) bool {
 		currState[fileName] = s.ModTime()
 		if !filesModified {
 			if currState[fileName] != w.prevModified[fileName] {
+				fmt.Fprint(w.sys.Writer(), "build triggered from ", fileName, ": ", w.prevModified[fileName], " -> ", currState[fileName], w.sys.NewLine())
 				filesModified = true
 			}
-			delete(w.prevModified, fileName)
 		}
+		delete(w.prevModified, fileName)
 	}
 	if len(w.prevModified) > 0 {
+		fmt.Fprint(w.sys.Writer(), "build triggered due to ", len(w.prevModified), " files deleted", w.sys.NewLine())
 		filesModified = true
 	}
 	w.prevModified = currState

cc @iisaduan

tmm1 avatar Apr 08 '25 23:04 tmm1

Probably due to pointer compare here?

https://github.com/microsoft/typescript-go/blob/74c01ca0f30c0117e927760871ffc0fef23cff5f/internal/execute/watcher.go#L52

I tried to compare structs instead, but errors:

internal/execute/watcher.go:53:6: invalid operation: *w.options.CompilerOptions() != *configParseResult.CompilerOptions() (struct containing []string cannot be compared)

tmm1 avatar Apr 08 '25 23:04 tmm1

You could try reflect.DeepEqual, maybe. I haven't looked at this code to know if this is supposed to be a deep comparison.

jakebailey avatar Apr 09 '25 03:04 jakebailey

You could try reflect.DeepEqual, maybe. I haven't looked at this code to know if this is supposed to be a deep comparison.

That works, thanks!

https://github.com/microsoft/typescript-go/pull/781

tmm1 avatar Apr 09 '25 03:04 tmm1