Skip to content

Commit d04527a

Browse files
committed
Fixed #14
1 parent aafb4a8 commit d04527a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

audit.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ var actualAudits = 0;
8484
*/
8585
var dependencies = [];
8686

87+
/**
88+
* Map of dependencies to audit. This ensures we only audit a dependency
89+
* once.
90+
*/
91+
var auditLookup = {};
92+
8793
/**
8894
* Count encountered vulnerabilities
8995
*/
@@ -297,7 +303,15 @@ function getDependencyList(depMap) {
297303
// Only add a dependency once
298304
if(lookup[name + o.version] == undefined) {
299305
lookup[name + o.version] = true;
300-
results.push({"pm": pm, "name": name, "version": o.version});
306+
// We need both the local and global "auditLookup" tables.
307+
// The global lookup is used to ensure we only audit a
308+
// dependency once, but cannot be done at the same level
309+
// as the local lookup since the sub-dependencies are not
310+
// available at all locations of the dependency tree (depMap).
311+
if (auditLookup[name + o.version] == undefined) {
312+
auditLookup[name + o.version] = true;
313+
results.push({"pm": pm, "name": name, "version": o.version});
314+
}
301315
if(o.dependencies) {
302316
var deps = getDependencyList(o.dependencies);
303317
@@ -311,7 +325,10 @@ function getDependencyList(depMap) {
311325
// Only add a dependency once
312326
if(lookup[name + o] == undefined) {
313327
lookup[name + o] = true;
314-
results.push({"pm": pm, "name": name, "version": o});
328+
if (auditLookup[name + o] == undefined) {
329+
auditLookup[name + o] = true;
330+
results.push({"pm": pm, "name": name, "version": o});
331+
}
315332
}
316333
}
317334
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "auditjs",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"description": "Audit dependencies to identify known vulnerabilities and maintenance problems",
55
"main": "audit-package.js",
66
"bin": "./audit.js",

0 commit comments

Comments
 (0)