From 402a7607c6bd2461a2e88558453e7d67098771d3 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Sat, 24 Jun 2017 17:35:26 -0700 Subject: [PATCH] try optional dependency --- src/fsevents_watcher.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fsevents_watcher.js b/src/fsevents_watcher.js index 17aa59b..121c4da 100644 --- a/src/fsevents_watcher.js +++ b/src/fsevents_watcher.js @@ -4,7 +4,13 @@ var fs = require('fs'); var path = require('path'); var common = require('./common'); var EventEmitter = require('events').EventEmitter; -var fsevents = require('fsevents'); +var fsevents; + +try { + fsevents = require('fsevents'); +} catch (e) { + // Ignore. +} /** * Constants @@ -31,6 +37,12 @@ module.exports = FSEventsWatcher; */ function FSEventsWatcher(dir, opts) { + if (!fsevents) { + throw new Error( + '`fsevents` unavailable (this watcher can only be used on Darwin)' + ); + } + common.assignOptions(this, opts); this.root = path.resolve(dir);