From b17d83152fe3b382747266cb77e7183fc5d44c47 Mon Sep 17 00:00:00 2001 From: Michael Orenstein Date: Sun, 26 Feb 2017 21:41:17 +1000 Subject: [PATCH] Use chokidar instead of fs for watching files. --- package.json | 1 + src/pathwatcher-rx.js | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index aa005b1..0a133f5 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "dependencies": { "@paulcbetts/mime-types": "^2.1.10", "btoa": "^1.1.2", + "chokidar": "^1.6.1", "debug": "^2.5.1", "lru-cache": "^4.0.1", "mkdirp": "^0.5.1", diff --git a/src/pathwatcher-rx.js b/src/pathwatcher-rx.js index 17b0c21..63186e9 100644 --- a/src/pathwatcher-rx.js +++ b/src/pathwatcher-rx.js @@ -1,7 +1,7 @@ -import fs from 'fs'; import {Observable} from 'rxjs/Observable'; import {Subscription} from 'rxjs/Subscription'; import LRU from 'lru-cache'; +import chokidar from 'chokidar'; import 'rxjs/add/operator/publish'; @@ -9,9 +9,12 @@ export function watchPathDirect(directory) { return Observable.create((subj) => { let dead = false; - const watcher = fs.watch(directory, {}, (eventType, fileName) => { + const watcher = chokidar.watch(directory) + + watcher.on('change', (fileName) => { if (dead) return; - subj.next({eventType, fileName}); + + subj.next({fileName}); }); watcher.on('error', (e) => {