From 3bacf60fc87dbcb509f76e6c25f84911b600dff2 Mon Sep 17 00:00:00 2001 From: Alexander Olsson Date: Wed, 30 Mar 2016 18:41:45 +0200 Subject: [PATCH] Use watchFile on Linux On linux, watch can not be used since closing the watcher triggers a callback in the new watcher which ends up being an infinite loop. Fixes #277 --- lib/atom-build.js | 6 +++++- spec/build-spec.js | 2 +- spec/build-visible-spec.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/atom-build.js b/lib/atom-build.js index 86deb9e7..055f3fa3 100644 --- a/lib/atom-build.js +++ b/lib/atom-build.js @@ -74,7 +74,11 @@ export default class CustomFile extends EventEmitter { settings() { const fs = require('fs'); this.fileWatchers.forEach(fw => fw.close()); - this.fileWatchers = this.files.map(file => fs.watch(file, () => this.emit('refresh'))); + // On Linux, closing a watcher triggers a new callback, which causes an infinite loop + // fallback to `watchFile` here which polls instead. + this.fileWatchers = this.files.map(file => + (require('os').platform() === 'linux' ? fs.watchFile : fs.watch)(file, () => this.emit('refresh')) + ); const config = []; this.files.map(getConfig).forEach(build => { diff --git a/spec/build-spec.js b/spec/build-spec.js index 3569c49a..3eb6b9b2 100644 --- a/spec/build-spec.js +++ b/spec/build-spec.js @@ -342,7 +342,7 @@ describe('Build', () => { })); }); - waits(waitTime); + waitsForPromise(() => specHelpers.refreshAwaitTargets()); runs(() => { atom.commands.dispatch(workspaceElement, 'build:trigger'); diff --git a/spec/build-visible-spec.js b/spec/build-visible-spec.js index 8baf175f..f788478d 100644 --- a/spec/build-visible-spec.js +++ b/spec/build-visible-spec.js @@ -113,7 +113,7 @@ describe('Visible', () => { }); // .atom-build.json is updated asynchronously... give it some time - waits(waitTime); + waitsForPromise(() => specHelpers.refreshAwaitTargets()); runs(() => { atom.commands.dispatch(workspaceElement, 'build:trigger');