Compiler supports configuring how to watch files and directories using the environment variables.
| ||Use |
| ||Use a dynamic queue where in the frequently modified files will be polled at shorter interval and the files unchanged will be polled less frequently|
| ||Use |
| ||This option is similar to |
| ||This option watches parent directory of the file with |
|default (no value specified)||If environment variable |
The watching of directory on platforms that don’t support recursive directory watching natively in node, is supported through recursively creating directory watcher for the child directories using different options selected by
TSC_WATCHDIRECTORY. Note that on platforms that support native recursive directory watching (e.g windows) the value of this environment variable is ignored.
| ||Use |
| ||Use dynamic polling queue to poll changes to the directory and child directories.|
|default (no value specified)||Use |
--watch implementation of the compiler relies on
fs.watchFile provided by node, both of these methods have pros and cons.
fs.watch uses file system events to notify the changes in the file/directory. But this is OS dependent and the notification is not completely reliable and does not work as expected on many OS. Also there could be limit on number of watches that can be created, eg. linux and we could exhaust it pretty quickly with programs that include large number of files. But because this uses file system events, there is not much CPU cycle involved. Compiler typically uses
fs.watch to watch directories (eg. source directories included by config file, directories in which module resolution failed etc) These can handle the missing precision in notifying about the changes. But recursive watching is supported on only Windows and OSX. That means we need something to replace the recursive nature on other OS.
fs.watchFile uses polling and thus involves CPU cycles. But this is the most reliable mechanism to get the update on the status of file/directory. Compiler typically uses
fs.watchFile to watch source files, config files and missing files (missing file references) that means the CPU usage depends on number of files in the program.
© 2012-2019 Microsoft
Licensed under the Apache License, Version 2.0.