From 7f62041f133bc077b1bc6d8b9f228cf6eec1da1b Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 28 Aug 2026 21:59:27 -0700 Subject: [PATCH] refactor: replace chalk with util.styleText --- lib/ci/build-types/test_build.js | 6 +++--- lib/ci/failure_aggregator.js | 4 ++-- lib/cli.js | 12 ++++++------ lib/figures.js | 10 +++++----- lib/verbosity.js | 6 ++---- package-lock.json | 15 --------------- package.json | 1 - 7 files changed, 18 insertions(+), 36 deletions(-) diff --git a/lib/ci/build-types/test_build.js b/lib/ci/build-types/test_build.js index 87456853..36240fda 100644 --- a/lib/ci/build-types/test_build.js +++ b/lib/ci/build-types/test_build.js @@ -1,4 +1,4 @@ -import chalk from 'chalk'; +import { styleText } from 'node:util'; import { shortSha } from '../../utils.js'; import { @@ -119,11 +119,11 @@ export class TestBuild extends Job { cli.table('Built On', failure.builtOn); } if (!reason.includes('\n') && reason.length < 40) { - cli.table('Reason', chalk.red(reason)); + cli.table('Reason', styleText('red', reason)); } else { cli.table('Reason', ''); const lines = reason.split('\n'); - cli.log(` ${chalk.red(lines[0])}`); + cli.log(` ${styleText('red', lines[0])}`); for (let i = 1; i < lines.length; ++i) { cli.log(` ${lines[i]}`); } diff --git a/lib/ci/failure_aggregator.js b/lib/ci/failure_aggregator.js index 8c421915..ca530f52 100644 --- a/lib/ci/failure_aggregator.js +++ b/lib/ci/failure_aggregator.js @@ -1,4 +1,4 @@ -import chalk from 'chalk'; +import { styleText } from 'node:util'; import { getMachineUrl, parsePRFromURL } from '../links.js'; import CIFailureParser from './ci_failure_parser.js'; @@ -140,7 +140,7 @@ export class FailureAggregator { cli.table('First CI', `${prs[0].upstream}`); } cli.table('Last CI', `${prs[prs.length - 1].upstream}`); - cli.log('\n' + chalk.bold('Example: ') + `${failures[0].url}\n`); + cli.log('\n' + styleText('bold', 'Example: ') + `${failures[0].url}\n`); const example = failures[0].reason; cli.log(example.length > 512 ? example.slice(0, 512) + '...' : example); cli.separator(); diff --git a/lib/cli.js b/lib/cli.js index bfb10474..e0e71276 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,5 +1,5 @@ import ora from 'ora'; -import chalk from 'chalk'; +import { styleText } from 'node:util'; import * as inquirer from '@inquirer/prompts'; import { warning, error, info, success } from './figures.js'; @@ -22,7 +22,7 @@ const QUESTION_TYPE = { const formatter = new Intl.ListFormat('en', { type: 'disjunction' }); function head(text, length = 11) { - return chalk.bold(text.padEnd(length)); + return styleText('bold', text.padEnd(length)); } export default class CLI { @@ -180,9 +180,9 @@ export default class CLI { const rest = (length - text.length - 2); const half = sep.repeat(Math.abs(Math.floor(rest / 2))); if (rest % 2 === 0) { - this.log(`${half} ${chalk.bold(text)} ${half}`); + this.log(`${half} ${styleText('bold', text)} ${half}`); } else { - this.log(`${half} ${chalk.bold(text)} ${sep}${half}`); + this.log(`${half} ${styleText('bold', text)} ${sep}${half}`); } } @@ -193,7 +193,7 @@ export default class CLI { warn(text, options = {}) { const prefix = options.newline ? this.eolIndent : this.figureIndent; - this.log(prefix + chalk.bold(`${warning} ${text}`)); + this.log(prefix + styleText('bold', `${warning} ${text}`)); } info(text, options = {}) { @@ -210,7 +210,7 @@ export default class CLI { this.log(JSON.stringify(obj.data, null, 2)); } } else { - this.log(prefix + chalk.bold(`${error} ${obj}`)); + this.log(prefix + styleText('bold', `${error} ${obj}`)); } } diff --git a/lib/figures.js b/lib/figures.js index f55ee0d8..3d22fcb9 100644 --- a/lib/figures.js +++ b/lib/figures.js @@ -1,7 +1,7 @@ -import chalk from 'chalk'; import { figures } from 'listr2'; +import { styleText } from 'node:util'; -export const warning = chalk.yellow(figures.warning); -export const error = chalk.red(figures.cross); -export const info = chalk.blue(figures.info); -export const success = chalk.green(figures.tick); +export const warning = styleText('yellow', figures.warning); +export const error = styleText('red', figures.cross); +export const info = styleText('blue', figures.info); +export const success = styleText('green', figures.tick); diff --git a/lib/verbosity.js b/lib/verbosity.js index dc071c33..88016817 100644 --- a/lib/verbosity.js +++ b/lib/verbosity.js @@ -1,6 +1,4 @@ -import util from 'node:util'; - -import chalk from 'chalk'; +import { format, styleText } from 'node:util'; const VERBOSITY = { NONE: 0, @@ -25,5 +23,5 @@ export function setVerbosityFromEnv() { export function debuglog(...args) { // Prepend a line break in case it's logged while the spinner is running - console.error(chalk.green(util.format('\n[DEBUG]', ...args))); + console.error(styleText('green', format('\n[DEBUG]', ...args))); } diff --git a/package-lock.json b/package-lock.json index b885eb2f..66fa5b75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ "@node-core/caritat", "@pkgjs/nv", "branch-diff", - "chalk", "changelog-maker", "cheerio", "core-validate-commit", @@ -34,7 +33,6 @@ "@node-core/caritat": "^1.6.0", "@pkgjs/nv": "^0.3.0", "branch-diff": "^3.1.1", - "chalk": "^6.0.0", "changelog-maker": "^4.4.1", "cheerio": "^1.0.0", "core-validate-commit": "^6.0.0", @@ -2159,19 +2157,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/chalk": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-6.0.0.tgz", - "integrity": "sha512-2uNTXIuTTxk7ciZgAU1BQcgnchcG0xXnrs6jzkQfj9SsRa9M2s5zE8WT96hS6KmG4MzWHSrvH43DF1m4XRkrFg==", - "inBundle": true, - "license": "MIT", - "engines": { - "node": ">=22" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, "node_modules/changelog-maker": { "version": "4.4.32", "resolved": "https://registry.npmjs.org/changelog-maker/-/changelog-maker-4.4.32.tgz", diff --git a/package.json b/package.json index 10657015..e3130e09 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "@node-core/caritat": "^1.6.0", "@pkgjs/nv": "^0.3.0", "branch-diff": "^3.1.1", - "chalk": "^6.0.0", "changelog-maker": "^4.4.1", "cheerio": "^1.0.0", "core-validate-commit": "^6.0.0",