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

feat: expose isDirect boolean for direct dependencies on the Vuln type #323

Merged
merged 1 commit into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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