Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
feat(vuln): expose isDirect
Browse files Browse the repository at this point in the history
Co-authored-by: isaacs <i@izs.me>
PR-URL: #323
Credit: @naugtur
Close: #323
Reviewed-by: @isaacs
  • Loading branch information
naugtur and isaacs committed Sep 28, 2021
1 parent 6baafaa commit 50c293d
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/vuln.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ class Vuln {
}
}

get isDirect () {
for (const node of this.nodes.values()) {
for (const edge of node.edgesIn) {
if (edge.from.isProjectRoot || edge.from.isWorkspace) {
return true
}
}
}
return false
}

testSpec (spec) {
const specObj = npa(spec)
if (!specObj.registry) {
Expand All @@ -101,10 +112,10 @@ class Vuln {
}

toJSON () {
// sort so that they're always in a consistent order
return {
name: this.name,
severity: this.severity,
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 : {
Expand Down
Loading

0 comments on commit 50c293d

Please sign in to comment.