diff --git a/lib/vuln.js b/lib/vuln.js index b40cd5a97..70596e0bb 100644 --- a/lib/vuln.js +++ b/lib/vuln.js @@ -78,6 +78,12 @@ class Vuln { } } + get isDirect () { + const edgesIn = [...this.nodes.values()].flatMap(n => [...n.edgesIn]) + const isDirect = edgesIn.some(e => e.from.isProjectRoot) + return isDirect + } + testSpec (spec) { const specObj = npa(spec) if (!specObj.registry) @@ -94,13 +100,10 @@ class Vuln { } toJSON () { - const edgesIn = [...this.nodes.values()].flatMap(n => [...n.edgesIn]) - const isDirect = edgesIn.some(e => e.from.isProjectRoot) - return { name: this.name, severity: this.severity, - isDirect, + isDirect: this.isDirect, // just loop over the advisories, since via is only Vuln objects, // and calculated advisories have all the info we need via: [...this.advisories].map(v => v.type === 'metavuln' ? v.dependency : {