Watch the physical directory of files reached through a symlinked directory - #64449
Closed
Joaquín Sorianello (joac) wants to merge 2 commits into
Closed
Joaquín Sorianello (joac) wants to merge 2 commits into
Joaquín Sorianello (joac) wants to merge 2 commits into
Conversation
…ectory Since the file watcher stopped following symlinks during its directory walk (typescript-go#4376), `tsc --watch` never sees edits to program files that live behind a symlinked directory inside the project, such as `src/common -> ../../common/src` in monorepos that share sources this way. The recursive watch on `src` covers the logical path, but the OS subscription is on the physical `src` directory, which does not contain the symlink target. When computing desired watches, resolve the real path of each seen file's directory. If it differs from the logical directory, watch the physical directory (non-recursively, like other uncovered directories) and remember the mapping. When draining events, rewrite paths under such a physical directory back to the logical path, which is the name the program knows the file by, so the existing relevance check and single-file fast path work unchanged. Fixes microsoft#64448.
Copilot started reviewing on behalf of
Joaquín Sorianello (joac)
September 25, 2026 18:51
View session
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The cross-platform filesystem watcher behavior and path remapping warrant final human review despite the focused regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
This PR restores watch-mode updates for source files reached through symlinked project directories by adding physical directory watches and translating their events back to logical program paths.
Changes:
- Detects logical source directories whose real paths differ and watches their physical directories.
- Remaps physical watcher events to logical paths before relevance and incremental-update checks.
- Adds a
tscWatchregression scenario and reference baseline.
| File | Description |
|---|---|
tsc/internal/execute/watcher.go |
Adds physical-directory watches and symlink event-path remapping. |
tsc/internal/execute/tsctests/tscwatch_test.go |
Adds the symlinked-source watch regression scenario. |
tsc/testdata/baselines/reference/tscWatch/commandLineWatch/watch-detects-change-in-file-under-symlinked-directory.js |
Captures expected watch registration and rebuild behavior. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Author
|
This was already fixed on #64404 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64448
Problem
Since the file watcher stopped following symlinks during its directory walk (typescript-go#4376),
tsc --watchnever sees edits to program files that live behind a symlinked directory inside the project, e.g.src/common -> ../../common/srcin monorepos that share sources this way. The recursive watch onsrccovers the logical path, but the OS subscription is on the physicalsrcdirectory, which does not contain the symlink target. TypeScript 6.0.3 detected these edits; 7.0.2 and@nextdo not (repro in the issue).Change (
internal/execute/watcher.go)computeDesiredWatches, resolve the real path of each seen file's directory (memoised per directory). When it differs from the logical directory, watch the physical directory, non-recursively like other uncovered directories, and record the physical → logical mapping keyed by canonical path.DoCycle, right after draining events, rewrite events reported under such a physical directory back to the logical path. That is the name the program knows the file by, so the relevance check and the single-file fast path work unchanged.node_modulesresolved through realpath) take the existing code path; no behaviour change for them.Tests
tscWatchscenario "watch detects change in file under symlinked directory" with baseline. It shows the physicalshared/srcdirectory being watched and an edit behind the symlink producing a rebuild with the expected new error. Withwatcher.gostashed, the scenario fails.tsc --watch7.x does not detect edits to files under a symlinked directory inside the project (6.0.3 did) #64448, using builds of this commit with and without the change: the unfixed build misses edits made through the real path and through the symlink, the fixed build detects both.Notes for review
Realpathper distinct seen-file directory on each reconcile after a full build, memoised per directory.Checklist
tsc --watch7.x does not detect edits to files under a symlinked directory inside the project (6.0.3 did) #64448mainbranchnpx hereby test: allinternal/executepackages pass; the only failures in the full run areinternal/fswatch/TestFSEventsExpansionAliasessub-cases (FSEvents Unicode-normalisation tests) which fail on this machine onmainas well, with a different sub-case each run, and are untouched by this changenpx hereby lint(0 issues)npx hereby check:format