From 8cf8eb1720fe61c48020a42456470ec85e25b4ea Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 1 Aug 2019 14:01:57 -0700 Subject: [PATCH] Add some logging to the sys.watchFile and sys.watchDirectory --- src/compiler/sys.ts | 5 +++++ src/compiler/watchUtilities.ts | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index ac710e6992b..4418737ec96 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -379,6 +379,9 @@ namespace ts { /*@internal*/ export const ignoredPaths = ["/node_modules/.", "/.git", "/.#"]; + /*@internal*/ + export let sysLog: (s: string) => void = noop; + /*@internal*/ export interface RecursiveDirectoryWatcherHost { watchDirectory: HostWatchDirectory; @@ -1053,6 +1056,7 @@ namespace ts { * @param createWatcher */ function invokeCallbackAndUpdateWatcher(createWatcher: () => FileWatcher) { + sysLog(`sysLog:: ${fileOrDirectory}:: Changing watcher to ${createWatcher === watchPresentFileSystemEntry ? "Present" : "Missing"}FileSystemEntryWatcher`); // Call the callback for current directory callback("rename", ""); @@ -1115,6 +1119,7 @@ namespace ts { * Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point */ function watchPresentFileSystemEntryWithFsWatchFile(): FileWatcher { + sysLog(`sysLog:: ${fileOrDirectory}:: Changing to fsWatchFile`); return fallbackPollingWatchFile(fileOrDirectory, createFileWatcherCallback(callback), pollingInterval); } diff --git a/src/compiler/watchUtilities.ts b/src/compiler/watchUtilities.ts index 7c11dcf2856..41642ca43b4 100644 --- a/src/compiler/watchUtilities.ts +++ b/src/compiler/watchUtilities.ts @@ -370,6 +370,9 @@ namespace ts { const createFileWatcher: CreateFileWatcher = getCreateFileWatcher(watchLogLevel, watchFile); const createFilePathWatcher: CreateFileWatcher = watchLogLevel === WatchLogLevel.None ? watchFilePath : createFileWatcher; const createDirectoryWatcher: CreateFileWatcher = getCreateFileWatcher(watchLogLevel, watchDirectory); + if (watchLogLevel === WatchLogLevel.Verbose && sysLog === noop) { + sysLog = s => log(s); + } return { watchFile: (host, file, callback, pollingInterval, detailInfo1, detailInfo2) => createFileWatcher(host, file, callback, pollingInterval, /*passThrough*/ undefined, detailInfo1, detailInfo2, watchFile, log, "FileWatcher", getDetailWatchInfo),