From 9cf42b944ce10e8edd1ad76466f3ce4b7360ce36 Mon Sep 17 00:00:00 2001 From: Richie McColl Date: Fri, 19 Dec 2025 15:01:16 +0200 Subject: [PATCH 1/2] feat: add migration guide for chalk to util styletext codemod --- .../en/blog/migrations/chalk-to-styletext.mdx | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx diff --git a/apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx b/apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx new file mode 100644 index 0000000000000..0561c984beac7 --- /dev/null +++ b/apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx @@ -0,0 +1,67 @@ +--- +date: '2025-12-19T00:00:00.000Z' +category: migrations +title: Chalk to Node.js util styleText +layout: blog-post +author: richiemccoll +--- + +# Migrate from Chalk to Node.js util styleText + +## `chalk-to-util-styletext` + +This codemod aims to help you reduce external dependencies by transforming chalk method calls to use the native Node.js styling functionality. It will also handle automatic removal of the `chalk` package from the package.json. + +### Compatible Features: + +- Basic colors (red, green, blue, yellow, etc.) +- Bright colors (redBright, greenBright, etc.) +- Background colors (bgRed, bgGreen, etc.) +- Text modifiers (bold, dim, italic, underline, strikethrough, etc.) +- Style chaining via array syntax +- Environment variable support (NO_COLOR, NODE_DISABLE_COLORS, FORCE_COLOR) + +### Non-Compatible Features: + +- Custom RGB colors (chalk.rgb(), chalk.hex()) +- 256-color palette (chalk.ansi256()) +- Template literal syntax (chalk...``) + -Advanced modifiers with limited terminal support (overline, blink, etc.) + +The source code for this codemod can be found in the [chalk-to-util-styletext directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/chalk-to-util-styletext). + +You can find this codemod in the [Codemod Registry](https://app.codemod.com/registry/@nodejs/chalk-to-util-styletext). + +```bash +npx codemod @nodejs/chalk-to-util-styletext +``` + +### Example: + +```js displayName="Before" +import chalk from 'chalk'; + +console.log(chalk.red('Error message')); + +console.log(chalk.red.bold('Important error')); + +const red = chalk.red; +console.log(red('Error')); + +const boldBlue = chalk.blue.bold; +console.log(boldBlue('Info')); +``` + +```js displayName="After" +import { styleText } from 'node:util'; + +console.log(styleText('red', 'Error message')); + +console.log(styleText(['red', 'bold'], 'Important error')); + +const red = text => styleText('red', text); +console.log(red('Error')); + +const boldBlue = text => styleText(['blue', 'bold'], text); +console.log(boldBlue('Info')); +``` From 3bff17ed85341c9cc59729666ef57c27abe68f3f Mon Sep 17 00:00:00 2001 From: Richie McColl Date: Fri, 19 Dec 2025 15:12:37 +0200 Subject: [PATCH 2/2] chore: fix formatting --- apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx b/apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx index 0561c984beac7..48f3b10092d6d 100644 --- a/apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx +++ b/apps/site/pages/en/blog/migrations/chalk-to-styletext.mdx @@ -26,7 +26,7 @@ This codemod aims to help you reduce external dependencies by transforming chalk - Custom RGB colors (chalk.rgb(), chalk.hex()) - 256-color palette (chalk.ansi256()) - Template literal syntax (chalk...``) - -Advanced modifiers with limited terminal support (overline, blink, etc.) +- Advanced modifiers with limited terminal support (overline, blink, etc.) The source code for this codemod can be found in the [chalk-to-util-styletext directory](https://github.com/nodejs/userland-migrations/tree/main/recipes/chalk-to-util-styletext).