-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
77 lines (58 loc) · 1.93 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var createDebug = require('debug'),
debugModulePath = require.resolve('debug'),
debugModule = require.cache[debugModulePath];
// Yo dawg, heard you like debug...
var hotDebugDebug = createDebug('hot-debug');
// Limit this so we don't leak memory if someone goes crazy and creates instances at runtime.
var maxChangeListeners = +process.env.DEBUG_MAX_HOT || 1024;
var changeListeners = [];
module.exports = debugModule.exports = createHotDebug;
Object.keys(createDebug).forEach(function (n) {
if ( n === 'enable' || n === 'disable' ) return;
// Settings must be set on the orignal object
Object.defineProperty(createHotDebug, n, {
get: function () {
return createDebug[n];
},
set: function (v) {
createDebug[n] = v;
}
});
});
createHotDebug.enable = function () {
var r = createDebug.enable.apply(this, arguments);
notifyListeners();
return r;
}
createHotDebug.disable = function () {
// Workaround for https://github.com/visionmedia/debug/issues/150
createDebug.names = [];
createDebug.skips = [];
var r = createDebug.disable.apply(this, arguments);
notifyListeners();
return r;
}
function createHotDebug(namespace) {
hotDebugDebug("createHotDebug: %s", namespace);
var debug = createDebug.apply(this, arguments);
if ( changeListeners.length >= maxChangeListeners ) {
hotDebugDebug("createHotDebug: maxChangeListeners reached (%d) - %s will not be hot", maxChangeListeners, namespace);
return debug;
}
listener.namespace = namespace;
changeListeners.push(listener);
function listener() {
var wasEnabled = debug.enabled;
debug.enabled = createDebug.enabled(namespace);
if ( wasEnabled !== debug.enabled ) {
hotDebugDebug("%s: enabled state changed: was %s, now %s", namespace, wasEnabled, debug.enabled);
}
}
return debug;
}
function notifyListeners() {
hotDebugDebug('notifyListeners: notifying %d listeners', changeListeners.length);
changeListeners.forEach(function (listener) {
listener();
});
}