Skip to content

Commit 6a4c8ff

Browse files
wraithgarlukekarrys
authored andcommitted
* properly track which vuln was printed to remove duplicates
1 parent c33b533 commit 6a4c8ff

File tree

8 files changed

+54
-39
lines changed

8 files changed

+54
-39
lines changed

node_modules/npm-audit-report/lib/colors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ module.exports = color => {
1919
magenta,
2020
yellow,
2121
white,
22-
severity
22+
severity,
2323
}
2424
}

node_modules/npm-audit-report/lib/exit-code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const severities = new Map(Object.entries([
55
'moderate',
66
'high',
77
'critical',
8-
'none'
8+
'none',
99
]).map(s => s.reverse()))
1010

1111
module.exports = (data, level) =>

node_modules/npm-audit-report/lib/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const reporters = {
44
install: require('./reporters/install'),
55
detail: require('./reporters/detail'),
66
json: require('./reporters/json'),
7-
quiet: require('./reporters/quiet')
7+
quiet: require('./reporters/quiet'),
88
}
99

1010
const exitCode = require('./exit-code.js')
@@ -20,20 +20,22 @@ module.exports = Object.assign((data, options = {}) => {
2020
// CLI defaults this to `null` so the defaulting method above doesn't work
2121
const auditLevel = options.auditLevel || 'low'
2222

23-
if (!data)
23+
if (!data) {
2424
throw Object.assign(
2525
new TypeError('ENOAUDITDATA'),
2626
{
2727
code: 'ENOAUDITDATA',
28-
message: 'missing audit data'
28+
message: 'missing audit data',
2929
}
3030
)
31+
}
3132

32-
if (typeof data.toJSON === 'function')
33+
if (typeof data.toJSON === 'function') {
3334
data = data.toJSON()
35+
}
3436

3537
return {
3638
report: reporters[reporter](data, { color, unicode, indent }),
37-
exitCode: exitCode(data, auditLevel)
39+
exitCode: exitCode(data, auditLevel),
3840
}
3941
}, { reporters })

node_modules/npm-audit-report/lib/reporters/detail.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@ const install = require('./install.js')
66
module.exports = (data, { color }) => {
77
const summary = install.summary(data, { color })
88
const none = data.metadata.vulnerabilities.total === 0
9-
return none ? summary : fullReport(data, {color, summary})
9+
return none ? summary : fullReport(data, { color, summary })
1010
}
1111

1212
const fullReport = (data, { color, summary }) => {
1313
const c = colors(color)
1414
const output = [c.white('# npm audit report'), '']
1515

1616
const printed = new Set()
17-
for (const [name, vuln] of Object.entries(data.vulnerabilities)) {
17+
for (const [, vuln] of Object.entries(data.vulnerabilities)) {
1818
// only print starting from the top-level advisories
19-
if (vuln.via.filter(v => typeof v !== 'string').length !== 0)
20-
output.push(printVuln(vuln, c, data.vulnerabilities))
19+
if (vuln.via.filter(v => typeof v !== 'string').length !== 0) {
20+
output.push(printVuln(vuln, c, data.vulnerabilities, printed))
21+
}
2122
}
2223

2324
output.push(summary)
2425

2526
return output.join('\n')
2627
}
2728

28-
const printVuln = (vuln, c, vulnerabilities, printed = new Set(), indent = '') => {
29-
if (printed.has(vuln))
29+
const printVuln = (vuln, c, vulnerabilities, printed, indent = '') => {
30+
if (printed.has(vuln)) {
3031
return null
32+
}
3133

3234
printed.add(vuln)
3335
const output = []
@@ -59,7 +61,7 @@ const printVuln = (vuln, c, vulnerabilities, printed = new Set(), indent = '') =
5961
`${c.yellow('fix available')} via \`npm audit fix --force\``,
6062
`Will install ${fa.name}@${fa.version}` +
6163
`, which is ${fa.isSemVerMajor ? 'a breaking change' :
62-
'outside the stated dependency range' }`
64+
'outside the stated dependency range'}`
6365
)
6466
}
6567
}
@@ -70,10 +72,10 @@ const printVuln = (vuln, c, vulnerabilities, printed = new Set(), indent = '') =
7072
}
7173

7274
for (const effect of vuln.effects) {
73-
const vuln = vulnerabilities[effect]
74-
const e = printVuln(vuln, c, vulnerabilities, printed, ' ')
75-
if (e)
75+
const e = printVuln(vulnerabilities[effect], c, vulnerabilities, printed, ' ')
76+
if (e) {
7677
output.push(...e.split('\n'))
78+
}
7779
}
7880

7981
if (indent === '') {

node_modules/npm-audit-report/lib/reporters/install.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const colors = require('../colors.js')
33
const calculate = (data, { color }) => {
44
const c = colors(color)
55
const output = []
6-
const { metadata: { vulnerabilities }} = data
6+
const { metadata: { vulnerabilities } } = data
77
const vulnCount = vulnerabilities.total
88

99
let someFixable = false
@@ -14,7 +14,7 @@ const calculate = (data, { color }) => {
1414
if (vulnCount === 0) {
1515
output.push(`found ${c.green('0')} vulnerabilities`)
1616
} else {
17-
for (const [name, vuln] of Object.entries(data.vulnerabilities)) {
17+
for (const [, vuln] of Object.entries(data.vulnerabilities)) {
1818
const { fixAvailable } = vuln
1919
someFixable = someFixable || fixAvailable === true
2020
someUnfixable = someUnfixable || fixAvailable === false
@@ -45,7 +45,7 @@ const calculate = (data, { color }) => {
4545
if (someFixable) {
4646
output.push('', 'To address ' +
4747
(someForceFixable || someUnfixable ? 'issues that do not require attention'
48-
: 'all issues') + ', run:\n npm audit fix')
48+
: 'all issues') + ', run:\n npm audit fix')
4949
}
5050

5151
if (someForceFixable) {
@@ -66,10 +66,10 @@ const calculate = (data, { color }) => {
6666
return {
6767
summary,
6868
report: vulnCount > 0 ? `${summary}\n\nRun \`npm audit\` for details.`
69-
: summary
69+
: summary,
7070
}
7171
}
7272

7373
module.exports = Object.assign((data, opt) => calculate(data, opt).report, {
74-
summary: (data, opt) => calculate(data, opt).summary
74+
summary: (data, opt) => calculate(data, opt).summary,
7575
})
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
{
22
"name": "npm-audit-report",
3-
"version": "2.1.5",
3+
"version": "3.0.0",
44
"description": "Given a response from the npm security api, render it into a variety of security reports",
55
"main": "lib/index.js",
66
"scripts": {
77
"test": "tap",
88
"snap": "tap",
99
"preversion": "npm test",
1010
"postversion": "npm publish",
11-
"prepublishOnly": "git push origin --follow-tags"
11+
"prepublishOnly": "git push origin --follow-tags",
12+
"lint": "eslint \"**/*.js\"",
13+
"postlint": "template-oss-check",
14+
"template-oss-apply": "template-oss-apply --force",
15+
"lintfix": "npm run lint -- --fix",
16+
"posttest": "npm run lint"
1217
},
1318
"tap": {
1419
"check-coverage": true,
@@ -20,33 +25,39 @@
2025
"report",
2126
"audit"
2227
],
23-
"author": "Adam Baldwin",
28+
"author": "GitHub Inc.",
2429
"license": "ISC",
2530
"dependencies": {
2631
"chalk": "^4.0.0"
2732
},
2833
"devDependencies": {
34+
"@npmcli/eslint-config": "^3.0.1",
35+
"@npmcli/template-oss": "3.1.2",
2936
"require-inject": "^1.4.4",
30-
"tap": "^14.10.7"
37+
"tap": "^16.0.0"
3138
},
3239
"directories": {
3340
"lib": "lib",
3441
"test": "test"
3542
},
3643
"repository": {
3744
"type": "git",
38-
"url": "git+https://github.com/npm/npm-audit-report.git"
45+
"url": "https://github.com/npm/npm-audit-report.git"
3946
},
4047
"bugs": {
4148
"url": "https://github.com/npm/npm-audit-report/issues"
4249
},
4350
"homepage": "https://github.com/npm/npm-audit-report#readme",
4451
"files": [
45-
"index.js",
46-
"lib",
52+
"bin/",
53+
"lib/",
4754
"reporters"
4855
],
4956
"engines": {
50-
"node": ">=10"
57+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
58+
},
59+
"templateOSS": {
60+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
61+
"version": "3.1.2"
5162
}
5263
}

package-lock.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
"ms": "^2.1.2",
133133
"node-gyp": "^9.0.0",
134134
"nopt": "^5.0.0",
135-
"npm-audit-report": "^2.1.5",
135+
"npm-audit-report": "^3.0.0",
136136
"npm-install-checks": "^4.0.0",
137137
"npm-package-arg": "^9.0.1",
138138
"npm-pick-manifest": "^7.0.0",
@@ -5325,15 +5325,15 @@
53255325
}
53265326
},
53275327
"node_modules/npm-audit-report": {
5328-
"version": "2.1.5",
5329-
"resolved": "https://registry.npmjs.org/npm-audit-report/-/npm-audit-report-2.1.5.tgz",
5330-
"integrity": "sha512-YB8qOoEmBhUH1UJgh1xFAv7Jg1d+xoNhsDYiFQlEFThEBui0W1vIz2ZK6FVg4WZjwEdl7uBQlm1jy3MUfyHeEw==",
5328+
"version": "3.0.0",
5329+
"resolved": "https://registry.npmjs.org/npm-audit-report/-/npm-audit-report-3.0.0.tgz",
5330+
"integrity": "sha512-tWQzfbwz1sc4244Bx2BVELw0EmZlCsCF0X93RDcmmwhonCsPMoEviYsi+32R+mdRvOWXolPce9zo64n2xgPESw==",
53315331
"inBundle": true,
53325332
"dependencies": {
53335333
"chalk": "^4.0.0"
53345334
},
53355335
"engines": {
5336-
"node": ">=10"
5336+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
53375337
}
53385338
},
53395339
"node_modules/npm-bundled": {
@@ -14812,9 +14812,9 @@
1481214812
"dev": true
1481314813
},
1481414814
"npm-audit-report": {
14815-
"version": "2.1.5",
14816-
"resolved": "https://registry.npmjs.org/npm-audit-report/-/npm-audit-report-2.1.5.tgz",
14817-
"integrity": "sha512-YB8qOoEmBhUH1UJgh1xFAv7Jg1d+xoNhsDYiFQlEFThEBui0W1vIz2ZK6FVg4WZjwEdl7uBQlm1jy3MUfyHeEw==",
14815+
"version": "3.0.0",
14816+
"resolved": "https://registry.npmjs.org/npm-audit-report/-/npm-audit-report-3.0.0.tgz",
14817+
"integrity": "sha512-tWQzfbwz1sc4244Bx2BVELw0EmZlCsCF0X93RDcmmwhonCsPMoEviYsi+32R+mdRvOWXolPce9zo64n2xgPESw==",
1481814818
"requires": {
1481914819
"chalk": "^4.0.0"
1482014820
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"ms": "^2.1.2",
100100
"node-gyp": "^9.0.0",
101101
"nopt": "^5.0.0",
102-
"npm-audit-report": "^2.1.5",
102+
"npm-audit-report": "^3.0.0",
103103
"npm-install-checks": "^4.0.0",
104104
"npm-package-arg": "^9.0.1",
105105
"npm-pick-manifest": "^7.0.0",

0 commit comments

Comments
 (0)