From 002c9e5fd9d54c9f2f646caefb20d0b053bd4e03 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Wed, 14 May 2014 11:01:59 +0900 Subject: [PATCH] Add a Node.js code watcher. It's not a separate process, so it can check require.cache for files it should watch. Currently unused due to missing SIGHUP handlers. --- lib/util/refresh.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/util/refresh.js diff --git a/lib/util/refresh.js b/lib/util/refresh.js new file mode 100644 index 00000000..c2be0ff0 --- /dev/null +++ b/lib/util/refresh.js @@ -0,0 +1,21 @@ +var fs = require('fs') + +var watchers = Object.create(null) + +function refresh() { + process.kill('SIGHUP') +} + +function collect() { + Object.keys(require.cache).forEach(function(path) { + if (!watchers[path]) { + if (path.indexOf('node_modules') === -1) { + watchers[path] = fs.watch(path, refresh) + } + } + }) +} + +module.exports = function() { + collect() +}