Skip to content

Commit a23cce4

Browse files
committedOct 20, 2015
Applied coding guidelines to NodeModuleCollector
1 parent e643f99 commit a23cce4

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed
 

‎dist/exceptionless.node.js

+8-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/exceptionless.node.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/services/NodeModuleCollector.ts

+26-16
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ export class NodeModuleCollector implements IModuleCollector {
1414
public getModules(context:EventPluginContext): IModule[] {
1515
this.initialize();
1616

17-
if (!require.main) return [];
17+
if (!require.main) {
18+
return [];
19+
}
1820

19-
var modulePath = path.dirname(require.main.filename) + '/node_modules/';
20-
var pathLength = modulePath.length;
21+
let modulePath = path.dirname(require.main.filename) + '/node_modules/';
22+
let pathLength = modulePath.length;
2123

22-
var loadedKeys = Object.keys(require.cache);
23-
var loadedModules = {};
24+
let loadedKeys = Object.keys(require.cache);
25+
let loadedModules = {};
2426

2527
loadedKeys.forEach(key => {
26-
var id = key.substr(pathLength);
28+
let id = key.substr(pathLength);
2729
console.log(id);
2830
id = id.substr(0, id.indexOf('/'));
2931
loadedModules[id] = true;
@@ -35,28 +37,36 @@ export class NodeModuleCollector implements IModuleCollector {
3537
}
3638

3739
private initialize() {
38-
if (this.initialized) return;
40+
if (this.initialized) {
41+
return;
42+
}
43+
3944
this.initialized = true;
4045

41-
var output = child.spawnSync('npm', ['ls', '--depth=0', '--json']).stdout;
46+
let output = child.spawnSync('npm', ['ls', '--depth=0', '--json']).stdout;
4247

43-
if (!output) return;
48+
if (!output) {
49+
return;
50+
}
4451

45-
var json;
52+
let json;
4653
try {
4754
json = JSON.parse(output.toString());
55+
} catch (e) {
56+
return;
4857
}
49-
catch (e) { return; }
5058

51-
var items = json.dependencies;
52-
if (!items) return;
59+
let items = json.dependencies;
60+
if (!items) {
61+
return;
62+
}
5363

54-
var id = 0;
64+
let id = 0;
5565
this.installedModules = {};
5666

5767
Object.keys(items).forEach(key => {
58-
var item = items[key];
59-
var theModule = <IModule> {
68+
let item = items[key];
69+
let theModule = <IModule> {
6070
module_id: id++,
6171
name: key,
6272
version: item.version

0 commit comments

Comments
 (0)
Please sign in to comment.