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