UNPKG

vigil

Version:

Simple, efficient file watching.

58 lines (52 loc) 1.31 kB
// Generated by CoffeeScript 1.11.1 var fs, patch, path; fs = require('fs'); path = require('path'); patch = require('./patch'); module.exports = function(cb) { var found, hooks, seen, updateHooks; hooks = {}; seen = {}; found = function(filename) { var dir; dir = path.dirname(filename); if (!seen[dir]) { seen[dir] = true; fs.stat(dir, function(err, stats) { if (stats == null) { return; } return cb(dir, stats); }); } return fs.stat(filename, function(err, stats) { if (stats == null) { return; } return cb(filename, stats); }); }; updateHooks = function() { var ext, handler, ref, results; ref = require.extensions; results = []; for (ext in ref) { handler = ref[ext]; results.push((function(ext, handler) { if (hooks[ext] !== require.extensions[ext]) { return hooks[ext] = require.extensions[ext] = function(module, filename) { if (!module.loaded) { found(module.filename); } handler(module, filename); return updateHooks(); }; } })(ext, handler)); } return results; }; updateHooks(); return patch(found); }; //# sourceMappingURL=vm.js.map