| 6365 | var toCanonicalName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames); |
| 6366 | return nonPollingWatchFile; |
| 6367 | function nonPollingWatchFile(fileName, callback, _pollingInterval, fallbackOptions) { |
| 6368 | var filePath = toCanonicalName(fileName); |
| 6369 | fileWatcherCallbacks.add(filePath, callback); |
| 6370 | var dirPath = ts.getDirectoryPath(filePath) || "."; |
| 6371 | var watcher = dirWatchers.get(dirPath) || |
| 6372 | createDirectoryWatcher(ts.getDirectoryPath(fileName) || ".", dirPath, fallbackOptions); |
| 6373 | watcher.referenceCount++; |
| 6374 | return { |
| 6375 | close: function () { |
| 6376 | if (watcher.referenceCount === 1) { |
| 6377 | watcher.close(); |
| 6378 | dirWatchers.delete(dirPath); |
| 6379 | } |
| 6380 | else { |
| 6381 | watcher.referenceCount--; |
| 6382 | } |
| 6383 | fileWatcherCallbacks.remove(filePath, callback); |
| 6384 | } |
| 6385 | }; |
| 6386 | } |
| 6387 | function createDirectoryWatcher(dirName, dirPath, fallbackOptions) { |
| 6388 | var watcher = fsWatch(dirName, 1 /* FileSystemEntryKind.Directory */, function (_eventName, relativeFileName) { |
| 6389 | // When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined" |