UNPKG

1.16 kBJavaScriptView Raw
1'use strict';
2
3const NodeWatcher = require('./src/node_watcher');
4const PollWatcher = require('./src/poll_watcher');
5const WatchmanWatcher = require('./src/watchman_watcher');
6const WatchexecWatcher = require('./src/watchexec_watcher');
7
8function throwNoFSEventsSupports() {
9 throw new Error('Sane >= 4 no longer support the fsevents module.');
10}
11
12function 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
30module.exports = sane;
31sane.NodeWatcher = NodeWatcher;
32sane.PollWatcher = PollWatcher;
33sane.WatchmanWatcher = WatchmanWatcher;
34sane.WatchexecWatcher = WatchexecWatcher;
35
36Object.defineProperty(sane, 'FSEventsWatcher', {
37 get() {
38 return throwNoFSEventsSupports();
39 },
40});