From 3b41f9c45c2bc843f97df5a4ad31cd80732b2ee3 Mon Sep 17 00:00:00 2001 From: soulgalore Date: Sun, 29 Dec 2024 16:06:20 +0100 Subject: [PATCH] Replace cli-color --- lib/plugins/text/color.js | 30 +++++++ lib/plugins/text/textBuilder.js | 28 +++--- npm-shrinkwrap.json | 153 -------------------------------- package.json | 1 - 4 files changed, 45 insertions(+), 167 deletions(-) create mode 100644 lib/plugins/text/color.js diff --git a/lib/plugins/text/color.js b/lib/plugins/text/color.js new file mode 100644 index 0000000000..192c38a74e --- /dev/null +++ b/lib/plugins/text/color.js @@ -0,0 +1,30 @@ +const ansi = { + reset: '\u001B[0m', + bold: '\u001B[1m', + green: '\u001B[32m', + yellow: '\u001B[33m', + red: '\u001B[31m', + blackBright: '\u001B[90m' +}; + +function stripAnsi(str) { + // eslint-disable-next-line no-control-regex + return str.replaceAll(/\u001B\[[0-9;]*[A-Za-z]/g, ''); +} + +export function colorise(str, clr) { + if (!clr || !ansi[clr]) return str; + return ansi[clr] + str + ansi.reset; +} + +export function makeBold(str) { + return ansi.bold + str + ansi.reset; +} + +export function getStrippedLength(str) { + return stripAnsi(str).length; +} + +export function blackBright(str) { + return colorise(str, 'blackBright'); +} diff --git a/lib/plugins/text/textBuilder.js b/lib/plugins/text/textBuilder.js index 75872184e0..1748c13a4c 100644 --- a/lib/plugins/text/textBuilder.js +++ b/lib/plugins/text/textBuilder.js @@ -1,13 +1,10 @@ -import clic from 'cli-color'; - import { plural, short, cap } from '../../support/helpers/index.js'; import summaryBoxesSetup from '../html/setup/summaryBoxes.js'; +import { colorise, makeBold, getStrippedLength, blackBright } from './color.js'; -const { getStrippedLength, blackBright, bold } = clic; const tableOptions = { stringLength: getStrippedLength }; -const drab = blackBright; function table(rows, options = {}) { const { stringLength = str => str.length } = options; @@ -54,7 +51,7 @@ function getColor(label) { function getHeader(context, options) { const noPages = options.urls.length; - return drab( + return blackBright( [ `${plural(noPages, 'page')} analysed for ${short(context.name, 30)} `, `(${plural(options.browsertime.iterations, 'run')}, `, @@ -82,9 +79,9 @@ export function renderSummary(metrics, context, options) { let out = getHeader(context, options); let rows = getBoxes(metrics, options.html).map(b => { const marker = getMarker(b.label), - c = getColor(b.label); + clr = getColor(b.label); - return [clic[c](marker), clic[c](b.name), bold(b.median)]; + return [colorise(marker, clr), colorise(b.name, clr), makeBold(b.median)]; }); rows.unshift( ['', 'Score / Metric', 'Median'], @@ -100,13 +97,13 @@ export function renderBriefSummary(metrics, context, options) { reqs = '', rum = ''; getBoxes(metrics, options.html).map(b => { - let c = getColor(b.label), - value = b.median, - name; - c = clic[c] || noop; + const clr = getColor(b.label); + let value = b.median; + let name; + const colorFn = clr ? str => colorise(str, clr) : noop; if (/score$/i.test(b.url)) { name = abbr(b.name.replace('score', '')); - scores.push(c(`${name}:${value}`)); + scores.push(colorFn(`${name}:${value}`)); } else if ('pageSize' === b.url) { value = value.replace(' ', ''); // 10 KB -> 10KB size = `${value}`; @@ -114,6 +111,11 @@ export function renderBriefSummary(metrics, context, options) { reqs = `${value} reqs`; } }); - lines.push(drab('Score: ') + scores.reverse().join(', '), size, reqs, rum); + lines.push( + blackBright('Score: ') + scores.reverse().join(', '), + size, + reqs, + rum + ); options.summary = { out: `${out}\n` + lines.join(' / ') }; } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 34fbdde690..e8a974d033 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -18,7 +18,6 @@ "@tgwf/co2": "0.16.4", "axe-core": "4.10.2", "browsertime": "23.5.0", - "cli-color": "2.0.4", "coach-core": "8.1.1", "concurrent-queue": "7.0.2", "dayjs": "1.11.11", @@ -4133,21 +4132,6 @@ "node": ">=4" } }, - "node_modules/cli-color": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.4.tgz", - "integrity": "sha512-zlnpg0jNcibNrO7GG9IeHH7maWFeCz+Ja1wx/7tZNU5ASSSSZ+/qZciM0/LHCYxSdqv5h2sdbQ/PXYdOuetXvA==", - "dependencies": { - "d": "^1.0.1", - "es5-ext": "^0.10.64", - "es6-iterator": "^2.0.3", - "memoizee": "^0.4.15", - "timers-ext": "^0.1.7" - }, - "engines": { - "node": ">=0.10" - } - }, "node_modules/cli-cursor": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", @@ -4522,15 +4506,6 @@ "node": ">=0.10.0" } }, - "node_modules/d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", - "dependencies": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" - } - }, "node_modules/data-view-buffer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/data-view-buffer/-/data-view-buffer-1.0.1.tgz", @@ -4981,51 +4956,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/es5-ext": { - "version": "0.10.64", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", - "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", - "hasInstallScript": true, - "dependencies": { - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.3", - "esniff": "^2.0.1", - "next-tick": "^1.1.0" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", - "dependencies": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, - "node_modules/es6-symbol": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", - "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", - "dependencies": { - "d": "^1.0.1", - "ext": "^1.1.2" - } - }, - "node_modules/es6-weak-map": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz", - "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", - "dependencies": { - "d": "1", - "es5-ext": "^0.10.46", - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.1" - } - }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -5399,25 +5329,6 @@ "node": ">=8" } }, - "node_modules/esniff": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", - "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", - "dependencies": { - "d": "^1.0.1", - "es5-ext": "^0.10.62", - "event-emitter": "^0.3.5", - "type": "^2.7.2" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/esniff/node_modules/type": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", - "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" - }, "node_modules/espree": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/espree/-/espree-10.1.0.tgz", @@ -5520,15 +5431,6 @@ "node": ">=0.10.0" } }, - "node_modules/event-emitter": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", - "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", - "dependencies": { - "d": "1", - "es5-ext": "~0.10.14" - } - }, "node_modules/event-target-shim": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", @@ -5682,19 +5584,6 @@ "integrity": "sha512-c2bQfLNbMzLPmzQuOr8fy0csy84WmwnER81W88DzTp9CYNPJ6yzOj2EZAh9pywYpqHnshVLHQJ8WzldAyfY+Iw==", "optional": true }, - "node_modules/ext": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/ext/-/ext-1.6.0.tgz", - "integrity": "sha512-sdBImtzkq2HpkdRLtlLWDa6w4DX22ijZLKx8BMPUuKe1c5lbN6xwQDQCxSfxBQnHZ13ls/FH0MQZx/q/gr6FQg==", - "dependencies": { - "type": "^2.5.0" - } - }, - "node_modules/ext/node_modules/type": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/type/-/type-2.6.0.tgz", - "integrity": "sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ==" - }, "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", @@ -7912,14 +7801,6 @@ "node": ">=10" } }, - "node_modules/lru-queue": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz", - "integrity": "sha1-Jzi9nw089PhEkMVzbEhpmsYyzaM=", - "dependencies": { - "es5-ext": "~0.10.2" - } - }, "node_modules/macos-release": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/macos-release/-/macos-release-3.2.0.tgz", @@ -8079,21 +7960,6 @@ "url": "https://github.com/sindresorhus/memoize?sponsor=1" } }, - "node_modules/memoizee": { - "version": "0.4.15", - "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.15.tgz", - "integrity": "sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==", - "dependencies": { - "d": "^1.0.1", - "es5-ext": "^0.10.53", - "es6-weak-map": "^2.0.3", - "event-emitter": "^0.3.5", - "is-promise": "^2.2.2", - "lru-queue": "^0.1.0", - "next-tick": "^1.1.0", - "timers-ext": "^0.1.7" - } - }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -8287,11 +8153,6 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, - "node_modules/next-tick": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" - }, "node_modules/node-addon-api": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.1.tgz", @@ -10879,15 +10740,6 @@ "node": ">=4" } }, - "node_modules/timers-ext": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.7.tgz", - "integrity": "sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==", - "dependencies": { - "es5-ext": "~0.10.46", - "next-tick": "1" - } - }, "node_modules/timm": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/timm/-/timm-1.7.1.tgz", @@ -11011,11 +10863,6 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, - "node_modules/type": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index 22a56192c7..87e54549a3 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,6 @@ "axe-core": "4.10.2", "browsertime": "23.5.0", "coach-core": "8.1.1", - "cli-color": "2.0.4", "concurrent-queue": "7.0.2", "dayjs": "1.11.11", "fast-crc32c": "2.0.0",