From 40cb98d22c283f6b9af079215fb33dfb4645d453 Mon Sep 17 00:00:00 2001 From: naugtur Date: Mon, 20 Sep 2021 09:52:32 +0200 Subject: [PATCH] expose isDirect on Vuln type, not just in JSON outpput --- lib/vuln.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 : {