diff --git a/lib/utils.js b/lib/utils.js index cfa8525..579460e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,29 +1,26 @@ 'use strict' +exports.severityLabel = severityLabel +exports.color = color -const colors = require('ansicolors') +const ccs = require('console-control-strings') -const severityColors = { - critical: colors.magenta, - high: colors.red, - moderate: colors.yellow, - low: function (str) { return str } +function color (name) { + const start = ccs.color(name) + const stop = ccs.color(reset) + return str => start + str + stop } -const severityLabel = function (sev, withColor) { - if (withColor) { - return severityColors[sev](sev) - } - return sev +const severityColors = { + critical: 'magenta', + high: 'red', + moderate: 'yellow', + low: null } -const color = function (value, color, withColor) { - if (withColor) { - return colors[color](value) - } - return value +function color (value, colorName, withColor) { + return (colorName && withColor) ? ccs.color(colorName) + value + ccs.color('reset') : value } -module.exports = { - severityLabel: severityLabel, - color: color +function severityLabel (sev, withColor) { + return color(sev, severityColors[sev], withColor) } diff --git a/package-lock.json b/package-lock.json index 9870223..8fa8343 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,11 +62,6 @@ "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", "dev": true }, - "ansicolors": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", - "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk=" - }, "ansistyles": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/ansistyles/-/ansistyles-0.1.3.tgz", @@ -392,6 +387,11 @@ "typedarray": "0.0.6" } }, + "console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" + }, "contains-path": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/contains-path/-/contains-path-0.1.0.tgz", diff --git a/package.json b/package.json index 267e03a..f0ce527 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ "author": "Adam Baldwin", "license": "ISC", "dependencies": { - "ansicolors": "^0.3.2", "ansistyles": "^0.1.3", - "cli-table2": "^0.2.0" + "cli-table2": "^0.2.0", + "console-control-strings": "^1.1.0" }, "devDependencies": { "keyfob": "^1.0.0", diff --git a/reporters/detail.js b/reporters/detail.js index 235253c..d1def30 100644 --- a/reporters/detail.js +++ b/reporters/detail.js @@ -92,7 +92,7 @@ const report = function (data, options) { if (action.action === 'update' || action.action === 'install') { const recommendation = getRecommendation(action, config) const label = action.resolves.length === 1 ? 'vulnerability' : 'vulnerabilities' - log(`\n\n# Run \`${Utils.color(recommendation.cmd, 'red', config.withColor)}\` to resolve ${action.resolves.length} ${label}`) + log(`\n\n# Run ${Utils.color(recommendation.cmd, ['red', 'inverse'], config.withColor)} to resolve ${action.resolves.length} ${label}`) if (recommendation.isBreaking) { log(`SEMVER WARNING: Recommended action is a potentially breaking change`) } diff --git a/test/detail-report-test.js b/test/detail-report-test.js index d333aa4..a6123ba 100644 --- a/test/detail-report-test.js +++ b/test/detail-report-test.js @@ -46,7 +46,7 @@ tap.test('it generates a detail report with one vuln (review dev dep)', function tap.test('it generates a detail report with one vuln, no color', function (t) { return Report(fixtures['one-vuln'], {reporter: 'detail', withColor: false}).then((report) => { t.match(report.exitCode, 1) - t.match(report.report, /# Run `npm update tough-cookie --depth 6` to resolve 1 vulnerability/) + t.match(report.report, /# Run npm update tough-cookie --depth 6 to resolve 1 vulnerability/) }) })