Skip to content

Prevent emitted files from retriggering native watch builds - #65475

Open
Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/wildcard-watch-filtering
Open

Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/wildcard-watch-filtering

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Caught this in an audit.

Fixes #64037 (which I did not realize before making this fix)

Recursive wildcard roots describe directories, not arbitrary event
paths. Treating every descendant as a directory lets emitted outputs
and unrelated files retrigger compilation indefinitely.

Filter individual events by dependency membership, supported extensions,
and expected output paths. Retain structural events using filesystem
checks and cached dependency ancestors, so moved-in and removed source
directories still refresh the program without scanning dependencies per
delete event.

Cover ignored creates/deletes and genuine source/directory changes with
command-line watch integration tests.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Watch mode can miss valid new inputs due to inconsistent extension casing and suppression of files never emitted, while regression tests do not cover same-directory output loops.

3 open issues
What changed in this PR

Updates the native compiler’s single-project watch mode to prevent emitted files from triggering repeated builds, addressing #64037.

Changes:

  • Filters file events using tracked dependencies, supported extensions, and predicted output paths.
  • Tracks dependency directories so directory deletions invalidate the build.
  • Adds tests for output filtering, new source discovery, and directory events.
File Description
tsc/​internal/​execute/​watcher.go Adds output-aware event filtering and dependency-directory tracking.
tsc/​internal/​execute/​tsctests/​watch_shallow_test.go Tests ignored file events and relevant source and directory changes.

Review effort: Balanced

"gotest.tools/v3/assert"
)

func TestWatchWildcardFiltersFiles(t *testing.T) {
if w.config.ConfigFile != nil && w.config.PossiblyMatchesFileName(tspath.RootedFilePathFromPath(eventPath)) {
return true
if !w.emittedFiles.Has(p) &&
slices.ContainsFunc(supportedExtensions, p.ExtensionIsOneOf) &&
if w.sys.FS().DirectoryExists(tspath.RootedDirectoryPathFromPath(eventPath)) {
if w.wm.IsPathUnderWatch(eventPath) {
return true
paths := outputpaths.GetOutputPathsFor(file, program.Options(), program, outputpaths.ForceEmitPaths{})

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

npx tsc -w is triggering itself after each build

3 participants