-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (55 loc) · 1.67 KB
/
index.js
File metadata and controls
66 lines (55 loc) · 1.67 KB
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
/* module-stats
A utility for collecting usage information on a per module basis
Copyright 2013-2014 Concurix Corporation
*/
module.exports = ModuleStats
var xtend = require('xtend');
var Wrapper = require('./lib/wrapper');
var Archiver = require('./lib/archive');
var Aggregator = require('./lib/aggregate');
var path = require('path');
function ModuleStats(options) {
if (!(this instanceof ModuleStats)) return new ModuleStats(options);
// Force uniqueness of module-stats. This means first one wins, fwiw.
if (global.concurix == null) {
global.concurix = {};
}
if (global.concurix.moduleStats) {
return global.concurix.moduleStats;
}
var key = options.accountKey;
if (key == null) {
try {
key = "modulestats~" + require(path.resolve(".") + "/package.json").name;
}
catch (e) {
key = "modulestats~unknown";
}
}
var defaults = {
accountKey: key,
archiveInterval: process.env.NODE_ENV == 'production' ? 60000 : 2000,
};
this.options = xtend(defaults, options);
this.aggregator = Aggregator(this.options);
this.archiver = Archiver(this.aggregator, this.options);
this.wrapper = Wrapper(this.aggregator, this.options);
global.concurix.moduleStats = this;
}
ModuleStats.prototype.wrap = function wrap(name, obj, options) {
// options can override global options
if (obj != null) {
return this.wrapper.wrapExports(name, obj, options);
}
}
ModuleStats.prototype.blacklist = function blacklist(obj) {
if (obj != null) {
this.wrapper.blacklist(obj);
}
}
ModuleStats.prototype.start = function start() {
this.archiver.start();
}
ModuleStats.prototype.stop = function stop() {
this.archiver.finish();
}