Starts a watcher that lints the changed files

@param {string} src
171500
function startWatcherForLinting (src)
{
    watch(src,
        function (file)
        {
            if (file.path)
            {
                lintFiles(file.path);
            }
        }
    );
}
900585
function buildBrowser(file, watch) {
  const props = {
    entries: [paths.src + file + '.js'],
    debug : true,
    cache: {},
    packageCache: {},
    standalone: 'swapi'
  };

  const bundler = watch ? watchify(browserify(props)) : browserify(props);

  function rebundle() {
    let stream = bundler.transform('babelify')
      .bundle();
    return stream
      .pipe($.plumber())
      .on('error', (err) => { $.notify().write(err); })
      .pipe(source(file + '.browser.js'))
      .pipe(buffer())
      .pipe($.uglify())
      .pipe(gulp.dest(paths.dist));
  }

  bundler.on('update', function() {
    rebundle();
    $.util.log('Rebundle...');
  });

  return rebundle();
}
1156439
function(event, path) {
            emitter.emit("file:changed", {
                event: event,
                path: path,
                namespace: namespace
            });
        }
1199276
function watchModule (module, modulesDir) {

    const pathToModule = resolve(modulesDir, module);
    const pathToHandlers = resolve(HANDLER_BASE, module);


    modules[module] = {
        handlers: []
    };
    fs.readdir(pathToHandlers, (err, files) => {

        if (err) {
            return console.log(new Error('Failed to get handler files for module: ' + module));
        }

        files.forEach(file => {

            if (file.length < 3 || file.indexOf('bundle.') === 0 || file.substr(file.length - 3) !== '.js') {
                return;
            }

            modules[module].handlers.push(pathToHandlers + '/' + file);
        });

        let watchList = modules[module].handlers.concat([pathToModule]);
        let watcher = chokidar.watch(watchList, {
            ignored: /(^|[\/\\])\../,
            persistent: true
        });
        watcher.on('change', (path, stats) => {

            // rebundle based on the type of the file
            if (modules[module].handlers.indexOf(path) < 0) {
                modules[module].handlers.forEach(handler => bundleHandler(pathToHandlers, module, handler.substr(handler.lastIndexOf('/') + 1)));
            } else {
                bundleHandler(pathToHandlers, module, path.substr(path.lastIndexOf('/') + 1));
            }
        });
    });
}
739668
function watchPartial(path, callback) {
  
  // Don't watch partials again when reloading
  
  if (this.watchPartials && RELOADING === false) {
    
    var self = this;
    self.debug('Watching Partial for changes: %s', self.relPath(path, 'app/views'));
    
    var watcher = chokidar.watch(path, {interval: self.config.watchInterval || 100});
    
    watcher.on('change', function() {
      self.debug("Regeneraging view partial", self.relPath(path));
      callback.call(self, path);
    });
    
    watcher.on('unlink', function() {
      self.log(util.format("Stopped watching partial '%s' (renamed)", self.relPath(path)));
      watcher.close();
    });
    
    watcher.on('error', function(err) {
      self.log(util.format("Stopped watching partial '%s' (error)", self.relPath(path)));
      self.log(err.stack);
      watcher.close();
    });

  }

}
1351248
function watch(done) {
  var mainWatcher = gulp.watch([
    'src/**/*.js',
    'modules/**/*.js',
    'test/spec/**/*.js',
    '!test/spec/loaders/**/*.js'
  ]);
  var loaderWatcher = gulp.watch([
    'loaders/**/*.js',
    'test/spec/loaders/**/*.js'
  ]);

  connect.server({
    https: argv.https,
    port: port,
    root: './',
    livereload: true
  });

  mainWatcher.on('all', gulp.series(clean, gulp.parallel(lint, 'build-bundle-dev', test)));
  loaderWatcher.on('all', gulp.series(lint));
  done();
}
1320789
function watchFile(file, cb, partial) {
    setAbsolutePath(file);
    storeDirectory(file);
    if (!watched_files[file.fullPath]) {
      if (use_fs_watch) {
        (function() {
          watched_files[file.fullPath] = fs.watch(file.fullPath, function() {
            typeof cb === "function" && cb(file);
          });
          partial && cb(file);
        })(file, cb);
      } else {
        (function(file, cb) {
          watched_files[file.fullPath] = true;
          fs.watchFile(file.fullPath, {interval: 150}, function() {
            typeof cb === "function" && cb(file);
          });
          partial && cb(file);
        })(file, cb);
      }
    }
  }
904819
function watchPaths(args) {
    var result = distinguishPaths(args.path)
    if (result.directories.length) {
      result.directories.forEach(function(directory) {
        watchDirectory(extend(args, {root: directory}));
      });
    }
    if (result.files.length)
      watchFiles(extend(args, {files: result.files}));
  }
537548
@Override public void start(Set<File> files, Consumer<Set<File>> callback) {
        if (isStarted()) {
            throw new IllegalStateException("start() should not be called more than once");
        }
        Set<File> filesCopy = ImmutableSet.copyOf(files);
        Preconditions.checkArgument(filesCopy.size() > 0, "must specify at least 1 file to watch for changes");
        this.callback = requireNonNull(callback);
        watchedFiles = filesCopy;
        executorService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1));
        future = executorService.scheduleAtFixedRate(
            this::scanFilesForChanges,
            initialDelay,
            interval,
            timeUnit);
    }
602846
function addWatcher(dirPath) {
    Debug._l(dirPath);
    /*fs.watchFile(dirPath, function (curr, prev) {
     //        console.log('the current mtime is: ' + curr.mtime);
     //        console.log('the previous mtime was: ' + prev.mtime);

     generateCache(id, dirPath);
     });*/
    var watch = Watcher(dirPath, function (filePath, isModified, isDeleted) {
        if (isModified) {
            Debug._l(generateIdFromFilePath(filePath));
            generateCache(filePath);
        }
        if (isDeleted) {
            removeCache(generateIdFromFilePath(filePath));
        }
    });

    return watch;
}
1189603
function lint() {
  var errorsFound = false;
  var stream = gulp.src(config.lintGlobs);

  if (isWatching) {
    stream = stream.pipe(watcher());
  }

  if (argv.fix) {
    options.fix = true;
  }

  return stream.pipe(eslint(options))
    .pipe(eslint.formatEach('stylish', function(msg) {
      errorsFound = true;
      util.log(util.colors.red(msg));
    }))
    .pipe(gulpIf(isFixed, gulp.dest('.')))
    .pipe(eslint.failAfterError())
    .on('end', function() {
      if (errorsFound && !options.fix) {
        util.log(util.colors.blue('Run `gulp lint --fix` to automatically ' +
            'fix some of these lint warnings/errors. This is a destructive ' +
            'operation (operates on the file system) so please make sure ' +
            'you commit before running.'));
      }
    });
}
1286864
function watch(sourcePath, patterns, commands) {
  var isBusy = false;
  var isPending = false;
  var runnable = function() {
    if (isBusy) return (isPending = true);
    isBusy = true;
    run(commands, function(err) {
      if (err) console.error(err.stack || err);
      isBusy = false;
      if (isPending) runnable(isPending = false);
    });
  };
  chokidar.watch(patterns, {
    cwd: sourcePath,
    ignoreInitial: true
  }).on('add', runnable).on('change', runnable).on('unlink', runnable);
}
875121
function watchCompiler(compiler, options={}){
  let watching = false
  log('Watch Building')
  const startWatchTime = Date.now()
  const watchConfig = { // watch options:
    //aggregateTimeout: 300, // wait so long for more changes
    //poll: true // use polling instead of native watchers
    // pass a number to set the polling interval
  }

  options.onRebuild = options.onRebuild || function(){}

  return new Promise(function(res,rej){  
    //webpack watch functionality
    compiler.watch(watchConfig, function(err,stats){
      if(err)return rej(err)

      if(watching){
        log('Rebuilt '+getServerTime())
        options.onRebuild(stats)
      }else{
        watching = true
        log('Watching '+(Date.now()-startWatchTime)/1000+' seconds')
        res( this )
      }
    });
  })
}
1031678
def watch_dir(path: str) -> None:
    """"""
    _compile_exclude_patterns()
    if config.autoreload or config.debug:
        # Add files to watch for autoreload
        p = pathlib.Path(path)
        p.resolve()
        _add_watch_path(p)
718512
function LintDirtyModulesPlugin(compiler, options) {
  this.startTime = Date.now();
  this.prevTimestamps = {};
  this.isFirstRun = true;
  this.compiler = compiler;
  this.options = options;

  // bind(this) is here to prevent context overriding by webpack
  compiler.plugin('emit', this.lint.bind(this));
}
294772
function watchAdditional(browserify, options) {
	var changingDeps = {};
	var pending = false;
	var updating = false;

	// watchify and sharing
	var sharedCache = browserify._options.cache;
	var sharedPkgcache = browserify._options.packageCache;

	var cache_target_paths = {};
	var mcached = new mutils.Cached(browserify);

	// watchfiles in watchify
	var watchify_on_files = {};
	browserify.on('bundle', function () {
		watchify_on_files = {};
	});
	browserify.on('file', function (file) {
		// NOTE : collect watch files of watchify
		watchify_on_files[file] = true;
	});

	browserify.on('bundle', function(bundle) {
		updating = true;

		var watched = false,
			ended = false;

		// NOTE : wait until browserify._recorded is update, for when used with the default options.
		var stream = through.obj(
			function transform(row, enc, next) { this.push(row); next(); }, // no-op
			function flush(done) {
				if (checkWatchify(browserify)) {
					var full_paths = mutils.toResolvePaths([].concat(options.files).concat(options.getFiles()));

					// add require target files
					mcached.collectRequirePaths(full_paths, function (collect_file_sources) {
						var collect_full_paths = Object.keys(collect_file_sources);
						// NOTE : keep wildcard path
						watchFile(_.uniq(full_paths.concat(collect_full_paths)));

						watched = true;
						oncomplete();
					});
				} else {
					watched = true;
				}
				done();
			});
		browserify.pipeline.get('record').push(stream);

		bundle.on('error', onend);
		bundle.on('end', onend);
		function onend () {
			ended = true;
			oncomplete();
		}

		function oncomplete () {
			if (!watched || !ended) return;

			if (checkWatchify(browserify)) {
				// unwatch the duplicated files from watchify
				var target_paths = _.uniq(
					Object.keys(browserify.pipeline.get('deps')._streams[0].visited)
						.concat(Object.keys(watchify_on_files)));

				unwatch(target_paths);
				target_paths.forEach(function (path) {
					cache_target_paths[path] = true;
				});
			}

			updating = false;
		}
	});


	var w = null;
	var runner = null;

	function watchFile(paths) {
		if (w) w.close();

		// TODO : support ignored

		w = chokidar.watch(paths);
		w.setMaxListeners(0);
		w.on('error', browserify.emit.bind(browserify, 'error'));
		w.on('change', function (file) {
			invalidate(file);
		});

		runner = new DelayRunner(DELAY);
	}

	function invalidate(id) {
		if (sharedCache) delete sharedCache[id];
		if (sharedPkgcache) delete sharedPkgcache[id];
		changingDeps[id] = true;

		var emit = true;
		emit = emit && !cache_target_paths[id];
		emit = emit && _.every(watchify_on_files, function (dummy, file) { return !putils.isEqualPath(id, file); });

		if (!updating && cache_target_paths[id]) {
			// remove expired path
			delete cache_target_paths[id];
		}

		if (emit) {
			// wait for the disk/editor to quiet down first:
			if (pending) clearTimeout(pending);
			pending = setTimeout(notify, DELAY);
		}
	}

	function notify() {
		if (updating) {
			pending = setTimeout(notify, DELAY);
		} else {
			pending = false;
			browserify.emit('update', Object.keys(changingDeps));
			changingDeps = {};
		}
	}

	function unwatch(paths) {
		// NOTE : do not work w.unwatch, if after immediate add.
		//        make a delay so
		runner.run(function () { w.unwatch(paths); });
	}

	function checkWatchify(browserify) {
		// XXX : _watcher is private field. judgement using watchify is not appropriate.
		//       but only this one :(
		return !!browserify._watcher;
	}

	return browserify;
}
865201
public static void watchFile(String file, SimpleHutoolWatcher watcher, boolean shouldFirstExecute) {
        if (shouldFirstExecute) {
            watcher.doSomething();
        }
        SimpleWatcher simpleWatcher = new SimpleWatcher() {
            @Override
            public void onModify(WatchEvent<?> event, Path currentPath) {
                watcher.onModify(event, currentPath);
                watcher.doSomething();
            }
        };
        try (WatchMonitor monitor = WatchMonitor.createAll(file, simpleWatcher)) {
            monitor.start();
        }
    }