Watch directories through polling when recursive options is not supported on the system #20207
+546
−306
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.
Issue: Currently if system doesn't support watching directories recursively, we aren't watching the sub folders of the watched directories. But we rely heavily on recursive directory watching, either for failed lookup locations of module resolutions, watching for node_modules/@types or to watch directories specified through tsconfig itself (eg when it doesn't have file list or uses recursive directory inclusion pattern) That means on systems that don't support directory watching, if the files are added/removed in the sub folders of the directory being watched, there is no indication of such and program would get out of sync.
Fix: Watch the directories and its sub folders through polling (like fs.watchFile) for the changes. Currently for any changes either in the directory that's watched recursively or its sub directories, the callback is invoked for the directory being watched recursively. It works especially because we don't end up spending time to find changes that might not be important to project/program.
We could poll the directories and subdirectories just once and keep refcount avoiding duplicate polling of children, but that can be done as next PR.
Fixes #19989, #20023