MCPcopy Index your code
hub / github.com/nodejs/node / fsWatch

Function fsWatch

test/fixtures/snapshot/typescript.js:7232–7333  ·  view source on GitHub ↗
(fileOrDirectory, entryKind, callback, recursive, fallbackPollingInterval, fallbackOptions)

Source from the content-addressed store, hash-verified

7230 }
7231 }
7232 function fsWatch(fileOrDirectory, entryKind, callback, recursive, fallbackPollingInterval, fallbackOptions) {
7233 var options;
7234 var lastDirectoryPartWithDirectorySeparator;
7235 var lastDirectoryPart;
7236 if (isLinuxOrMacOs) {
7237 lastDirectoryPartWithDirectorySeparator = fileOrDirectory.substr(fileOrDirectory.lastIndexOf(ts.directorySeparator));
7238 lastDirectoryPart = lastDirectoryPartWithDirectorySeparator.slice(ts.directorySeparator.length);
7239 }
7240 /** Watcher for the file system entry depending on whether it is missing or present */
7241 var watcher = !fileSystemEntryExists(fileOrDirectory, entryKind) ?
7242 watchMissingFileSystemEntry() :
7243 watchPresentFileSystemEntry();
7244 return {
7245 close: function () {
7246 // Close the watcher (either existing file system entry watcher or missing file system entry watcher)
7247 watcher.close();
7248 watcher = undefined;
7249 }
7250 };
7251 /**
7252 * Invoke the callback with rename and update the watcher if not closed
7253 * @param createWatcher
7254 */
7255 function invokeCallbackAndUpdateWatcher(createWatcher) {
7256 sysLog("sysLog:: ".concat(fileOrDirectory, ":: Changing watcher to ").concat(createWatcher === watchPresentFileSystemEntry ? "Present" : "Missing", "FileSystemEntryWatcher"));
7257 // Call the callback for current directory
7258 callback("rename", "");
7259 // If watcher is not closed, update it
7260 if (watcher) {
7261 watcher.close();
7262 watcher = createWatcher();
7263 }
7264 }
7265 /**
7266 * Watch the file or directory that is currently present
7267 * and when the watched file or directory is deleted, switch to missing file system entry watcher
7268 */
7269 function watchPresentFileSystemEntry() {
7270 // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
7271 // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
7272 if (options === undefined) {
7273 if (fsSupportsRecursiveFsWatch) {
7274 options = { persistent: true, recursive: !!recursive };
7275 }
7276 else {
7277 options = { persistent: true };
7278 }
7279 }
7280 if (hitSystemWatcherLimit) {
7281 sysLog("sysLog:: ".concat(fileOrDirectory, ":: Defaulting to fsWatchFile"));
7282 return watchPresentFileSystemEntryWithFsWatchFile();
7283 }
7284 try {
7285 var presentWatcher = _fs.watch(fileOrDirectory, options, isLinuxOrMacOs ?
7286 callbackChangingToMissingFileSystemEntry :
7287 callback);
7288 // Watch the missing file or directory or error
7289 presentWatcher.on("error", function () { return invokeCallbackAndUpdateWatcher(watchMissingFileSystemEntry); });

Callers 4

createDirectoryWatcherFunction · 0.85
watchFileFunction · 0.85
watchDirectoryFunction · 0.85

Calls 5

fileSystemEntryExistsFunction · 0.85
sliceMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…