Fix config reload after vim edit (#2718)

This commit is contained in:
CHaBou 2018-03-03 17:58:24 +01:00 committed by GitHub
parent 24b83615d4
commit bf2d6ea855
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,7 @@ const _watch = function() {
}, 100); }, 100);
}; };
// Windows
if (process.platform === 'win32') { if (process.platform === 'win32') {
// watch for changes on config every 2s on Windows // watch for changes on config every 2s on Windows
// https://github.com/zeit/hyper/pull/1772 // https://github.com/zeit/hyper/pull/1772
@ -35,8 +36,24 @@ const _watch = function() {
onChange(); onChange();
} }
}); });
} else { return;
_watcher = fs.watch(cfgPath); }
// 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('change', onChange);
_watcher.on('error', error => { _watcher.on('error', error => {
//eslint-disable-next-line no-console //eslint-disable-next-line no-console