index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. const NodeWatcher = require('./src/node_watcher');
  3. const PollWatcher = require('./src/poll_watcher');
  4. const WatchmanWatcher = require('./src/watchman_watcher');
  5. const WatchexecWatcher = require('./src/watchexec_watcher');
  6. function throwNoFSEventsSupports() {
  7. throw new Error('Sane >= 4 no longer support the fsevents module.');
  8. }
  9. function sane(dir, options) {
  10. options = options || {};
  11. if (options.watcher) {
  12. const WatcherClass = require(options.watcher);
  13. return new WatcherClass(dir, options);
  14. } else if (options.poll) {
  15. return new PollWatcher(dir, options);
  16. } else if (options.watchman) {
  17. return new WatchmanWatcher(dir, options);
  18. } else if (options.watchexec) {
  19. return new WatchexecWatcher(dir, options);
  20. } else if (options.fsevents) {
  21. throwNoFSEventsSupports();
  22. } else {
  23. return new NodeWatcher(dir, options);
  24. }
  25. }
  26. module.exports = sane;
  27. sane.NodeWatcher = NodeWatcher;
  28. sane.PollWatcher = PollWatcher;
  29. sane.WatchmanWatcher = WatchmanWatcher;
  30. sane.WatchexecWatcher = WatchexecWatcher;
  31. Object.defineProperty(sane, 'FSEventsWatcher', {
  32. get() {
  33. return throwNoFSEventsSupports();
  34. },
  35. });