From 11b31b5096ff68db03c57ab44bf525f89555c2f4 Mon Sep 17 00:00:00 2001 From: Luke Jackson Date: Tue, 11 Feb 2020 15:50:46 +0000 Subject: [PATCH] Implements custom recursive watch for linux (#39) * Implements custom recursive watch for linux * Only use custom watch on linux --- servor.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/servor.js b/servor.js index e284a01..d92d46f 100644 --- a/servor.js +++ b/servor.js @@ -7,6 +7,16 @@ const os = require('os'); const net = require('net'); const cwd = process.cwd(); +const watch = + process.platform === 'linux' + ? (path, cb) => { + if (fs.statSync(path).isDirectory()) { + fs.watch(path, cb); + fs.readdirSync(path).forEach(entry => watch(`${path}/${entry}`, cb)); + } + } + : (path, cb) => fs.watch(path, { recursive: true }, cb); + const fport = (p = 0) => new Promise((resolve, reject) => { const s = net.createServer(); @@ -122,7 +132,7 @@ module.exports = async ({ // Notify livereload clients on file change reload && - fs.watch(root, { recursive: true }, () => { + watch(root, () => { while (clients.length > 0) sendMessage(clients.pop(), 'message', 'reload'); });