Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (root && opts.watch !== false) {
var urlsByFile = {}
fn.watcher = filewatcher({ delay: opts.delay })
// Stop the file system watcher so apps can exit gracefully when
// terminated by Ctrl+c (SIGINT) or a polite termination request (SIGTERM).
// You can also call the cleanUp() function directly to handle housekeeping
// in your own server (e.g., when it is asked to close).
fn.cleanUp = function (done) {
fn.watcher.removeAll()
done()
}
Graceful.timeout = 3000
Graceful.on('SIGINT', fn.cleanUp)
Graceful.on('SIGTERM', fn.cleanUp)
// when a file is modifed tell all clients to reload it
fn.watcher.on('change', function(file) {
fn.reload(urlsByFile[file])
})
// build a RegExp to match all watched file extensions
var exts = opts.watch || ['html', 'js', 'css']
, re = new RegExp('\\.(' + exts.join('|') + ')$')
// pass an `onfile` handler that watches matching files
opts = Object.create(opts, {
onfile: { value: function(path, stat) {
if (!re.test(path)) return