From bf2d6ea8555e3a4e40e4c8df34cbe1963282d1fd Mon Sep 17 00:00:00 2001 From: CHaBou Date: Sat, 3 Mar 2018 17:58:24 +0100 Subject: [PATCH] Fix config reload after vim edit (#2718) --- app/config.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/config.js b/app/config.js index bed91878a7ed..9f668d6b8faa 100644 --- a/app/config.js +++ b/app/config.js @@ -24,6 +24,7 @@ const _watch = function() { }, 100); }; + // Windows if (process.platform === 'win32') { // watch for changes on config every 2s on Windows // https://github.com/zeit/hyper/pull/1772 @@ -35,8 +36,24 @@ const _watch = function() { onChange(); } }); - } else { - _watcher = fs.watch(cfgPath); + return; + } + // macOS/Linux + setWatcher(); + function setWatcher() { + try { + _watcher = fs.watch(cfgPath, eventType => { + if (eventType === 'rename') { + _watcher.close(); + // Ensure that new file has been written + setTimeout(() => setWatcher(), 500); + } + }); + } catch (e) { + //eslint-disable-next-line no-console + console.error('Failed to watch config file:', cfgPath, e); + return; + } _watcher.on('change', onChange); _watcher.on('error', error => { //eslint-disable-next-line no-console