How to use the chokidar.FSWatcher function in chokidar

To help you get started, we’ve selected a few chokidar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bahmni / openmrs-module-bahmniapps / clinical-ui / node_modules / testacular / lib / watcher.js View on Github external
exports.watch = function(patterns, excludes, fileList) {
  var options = {
    ignorePermissionErrors: true,
    ignored: createIgnore(excludes)
  };
  var chokidarWatcher = new chokidar.FSWatcher(options);

  watchPatterns(patterns, chokidarWatcher);

  var bind = function(fn) {
    return function(path) {
      return fn.call(fileList, helper.normalizeWinPath(path));
    };
  };

  // register events
  chokidarWatcher.on('add', bind(fileList.addFile))
                 .on('change', bind(fileList.changeFile))
                 .on('unlink', bind(fileList.removeFile));

  return chokidarWatcher;
};
github parcel-bundler / parcel / packages / core / watcher / src / child.js View on Github external
function init(options: EncodedFSWatcherOptions) {
  let decodedOptions = decodeOptions(options);
  watcher = new FSWatcher(decodedOptions);
  watcher.on('all', sendEvent);
  sendEvent('ready');

  // only used for testing
  watcher.once('ready', async () => {
    // Wait an additional macrotask. This seems to be necessary before changes
    // can be picked up.
    await new Promise(resolve => setImmediate(resolve));
    sendEvent('_chokidarReady');
  });
}
github johandb / svg-drawing-tool / node_modules / @angular-devkit / core / node / host.js View on Github external
return new rxjs_1.Observable(obs => {
            const watcher = new FSWatcher({ persistent: true }).add(src_1.getSystemPath(path));
            watcher
                .on('change', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 0 /* Changed */,
                });
            })
                .on('add', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 1 /* Created */,
                });
            })
                .on('unlink', path => {
github seccubus / seccubus / angular-seccubus.old / bak / node_modules / @angular-devkit / core / node / host.js View on Github external
return new Observable_1.Observable(obs => {
            const watcher = new FSWatcher({ persistent: true }).add(this._getSystemPath(path));
            watcher
                .on('change', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 0 /* Changed */,
                });
            })
                .on('add', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 1 /* Created */,
                });
            })
                .on('unlink', path => {
github johandb / svg-drawing-tool / node_modules / @angular-devkit / core / node / host.js View on Github external
return new rxjs_1.Observable(obs => {
            const opts = { persistent: false };
            const watcher = new FSWatcher(opts).add(src_1.getSystemPath(path));
            watcher
                .on('change', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 0 /* Changed */,
                });
            })
                .on('add', path => {
                obs.next({
                    path: src_1.normalize(path),
                    time: new Date(),
                    type: 1 /* Created */,
                });
            })
                .on('unlink', path => {
github openshift / console / frontend / node_modules / karma / lib / watcher.js View on Github external
exports.watch = function(patterns, excludes, fileList, usePolling, emitter) {
  var watchedPatterns = getWatchedPatterns(patterns);
  var options = {
    usePolling: usePolling,
    ignorePermissionErrors: true,
    ignoreInitial: true,
    ignored: createIgnore(watchedPatterns, excludes)
  };
  var chokidarWatcher = new chokidar.FSWatcher(options);

  watchPatterns(watchedPatterns, chokidarWatcher);

  var bind = function(fn) {
    return function(path) {
      return fn.call(fileList, helper.normalizeWinPath(path));
    };
  };

  // register events
  chokidarWatcher.on('add', bind(fileList.addFile))
                 .on('change', bind(fileList.changeFile))
                 .on('unlink', bind(fileList.removeFile))
                 // If we don't subscribe; unhandled errors from Chokidar will bring Karma down
                 // (see GH Issue #959)
                 .on('error', function(e) {
github derbyjs / derby / old-libs / files-old.js View on Github external
function watch(dir, type, onChange) {
  var extension = extensions[type];
  var hashes = {};
  var watcher = new chokidar.FSWatcher;

  watcher
    .on('add', checkModified)
    .on('change', checkModified)
    .on('unlink', checkModified)
    .on('error', function(err) {
      console.error('Watch error\n', err);
    })

  files(dir, extension).forEach(function(path) {
    fs.readFile(path, 'utf8', function(err, file) {
      if (err) return console.error('Watch error\n', err);
      hashes[path] = hashFile(file);
      watcher.add(path);
    });
  });
github machawk1 / wail / wail-core / fs / index.js View on Github external
import chokidar from 'chokidar'
import walk from 'klaw'
import fs from 'fs-extra'
import directorySize from './directorySize'
import pathExists from './pathExists'
import pathIs from './pathIs'
import completeAssign from '../util/completeAssign'

const base = {
  walk,
  chokidarWatch: chokidar.watch,
  FSWatcher: chokidar.FSWatcher
}

export default completeAssign(base, fs, directorySize, pathExists, pathIs)
github markfinger / react-render / webpack-service / lib / Bundle.js View on Github external
Bundle.prototype.watchFile = function watchFile(filename, cb) {
  if (!Bundle._fileWatcher) {
    Bundle._fileWatcher = new chokidar.FSWatcher();
    Bundle._fileWatcher.on('change', this._onFileChange);
  }

  if (Bundle._watchedFiles[filename]) {
    Bundle._watchedFiles[filename].push(cb);
  } else {
    Bundle._watchedFiles[filename] = [cb];
    Bundle._fileWatcher.add(filename);
  }
};
github popeindustries / buddy / lib / cache / index.js View on Github external
constructor() {
    super();

    this.fileCaches = new Set();
    this.resolverCaches = new Set();
    this._fileWatcher = new FSWatcher({
      ignored: /[\/\\]\./,
      persistent: true
    });

    this._fileWatcher.on('change', this.onWatchChange.bind(this));
    this._fileWatcher.on('unlink', this.onWatchDelete.bind(this));
    this._fileWatcher.on('error', this.onWatchError.bind(this));
    this.createCaches = this.createCaches.bind(this);
    this.clear = this.clear.bind(this);
    this.debouncedEmit = debounce(this.emit, 100, { trailing: true });
  }

chokidar

Minimal and efficient cross-platform file watching library

MIT
Latest version published 2 months ago

Package Health Score

91 / 100
Full package analysis