From f5f874048bb733aace05f465143a0ce8931395c1 Mon Sep 17 00:00:00 2001 From: Marc Celani Date: Mon, 17 Jan 2022 16:18:41 -0600 Subject: [PATCH 1/2] Fix dropped watches --- src/compiler/sys.ts | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index b41e89e991567..0b802daf5637a 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1648,15 +1648,26 @@ namespace ts { } function callbackChangingToMissingFileSystemEntry(event: "rename" | "change", relativeName: string | undefined) { - // because relativeName is not guaranteed to be correct we need to check on each rename with few combinations - // Eg on ubuntu while watching app/node_modules the relativeName is "node_modules" which is neither relative nor full path - return event === "rename" && - (!relativeName || - relativeName === lastDirectoryPart || - (relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) !== -1 && relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) === relativeName.length - lastDirectoryPartWithDirectorySeparator!.length)) && - !fileSystemEntryExists(fileOrDirectory, entryKind) ? - invokeCallbackAndUpdateWatcher(watchMissingFileSystemEntry) : - callback(event, relativeName); + // On unix systems, fs.watch places a watch on an inode. When a rename occurs, it is possible that the underlying inode has changed. + // Just to be safe, always create a new watch on a rename event. + if (event === "rename") { + // because relativeName is not guaranteed to be correct we need to check on each rename with few combinations + // Eg on ubuntu while watching app/node_modules the relativeName is "node_modules" which is neither relative nor full path + if ((!relativeName || + relativeName === lastDirectoryPart || + (relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) !== -1 && relativeName.lastIndexOf(lastDirectoryPartWithDirectorySeparator!) === relativeName.length - lastDirectoryPartWithDirectorySeparator!.length)) && + !fileSystemEntryExists(fileOrDirectory, entryKind)) { + return invokeCallbackAndUpdateWatcher(watchMissingFileSystemEntry); + } + else { + if (watcher) { + sysLog(`sysLog:: ${relativeName}:: Resetting watch on present file after rename event`); + watcher.close(); + watcher = watchPresentFileSystemEntryWithFsWatchFile(); + } + } + } + return callback(event, relativeName); } /** From b61738bc12229e9112a95a365084bba0afbbbd5b Mon Sep 17 00:00:00 2001 From: Marc Celani Date: Mon, 11 Apr 2022 14:46:50 -0500 Subject: [PATCH 2/2] watchPresentFileSystemEntry --- src/compiler/sys.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 0b802daf5637a..2ca5c285d1216 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1663,7 +1663,7 @@ namespace ts { if (watcher) { sysLog(`sysLog:: ${relativeName}:: Resetting watch on present file after rename event`); watcher.close(); - watcher = watchPresentFileSystemEntryWithFsWatchFile(); + watcher = watchPresentFileSystemEntry(); } } }