-
Notifications
You must be signed in to change notification settings - Fork 1
/
browser.js
34 lines (30 loc) · 881 Bytes
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var glob = require('glob');
var path = require('path');
var cwd = process.cwd();
var watch = require('glob-watcher');
module.exports = function browserRunner(browserGlob) {
glob(browserGlob, function (err, files) {
files.forEach(function(file) {
require(path.resolve(cwd, file));
});
});
var watcher = watch(browserGlob);
watcher.on('change', function(event) {
flush();
require(path.resolve(cwd, event.path));
});
}
function flush() {
Object.keys(require.cache).forEach((function (fname) {
if (fname.indexOf('node_modules') === -1) {
delete require.cache[fname];
}
var mods = ['tape'];
mods.forEach(function (mod) {
if (fname.indexOf(path.join(cwd, mod) + path.sep) > -1 ||
fname.indexOf(path.join(cwd, 'node_modules', mod) + path.sep) > -1) {
delete require.cache[fname];
}
})
}));
}