Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions recipes/kleur-to-util-styletext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Kleur to util.styleText

This recipe migrates from the external `kleur` package to Node.js built-in `util.styleText` API. It transforms `kleur` style calls and `kleur/colors` named style functions to the native Node.js styling functionality.

## Examples

```diff
- import kleur from 'kleur';
+ import { styleText } from 'node:util';
- console.log(kleur.red('Error'));
+ console.log(styleText('red', 'Error'));
- console.log(kleur.bold().red('Failure'));
+ console.log(styleText(['bold', 'red'], 'Failure'));
```

```diff
- import { green, dim } from 'kleur/colors';
+ import { styleText } from 'node:util';
- console.log(green('OK') + ' ' + dim(name));
+ console.log(styleText('green', 'OK') + ' ' + styleText('dim', name));
```

```diff
- import { bgRed, white } from 'kleur/colors';
+ import { styleText } from 'node:util';
- console.log(bgRed(white('FAIL')));
+ console.log(styleText(['bgRed', 'white'], 'FAIL'));
```

## Compatibility

- Removes the `kleur` dependency from package.json automatically
- Supports default, namespace, and CommonJS `kleur` imports
- Supports named imports and destructured requires from `kleur/colors`
- Leaves unsupported APIs such as `kleur.enabled` and `$` from `kleur/colors` unchanged

## Limitations

- Manual migration is required for `kleur.enabled`, `$` from `kleur/colors`, and other APIs that are not direct style functions
26 changes: 26 additions & 0 deletions recipes/kleur-to-util-styletext/codemod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
schema_version: "1.0"
name: "@nodejs/kleur-to-util-styletext"
version: 1.0.0
capabilities:
- fs
- child_process
description: Migrate from the kleur package to Node.js's built-in util.styleText API
author: Herrtian
license: MIT
workflow: workflow.yaml
category: migration
repository: https://github.com/nodejs/userland-migrations

targets:
languages:
- javascript
- typescript

keywords:
- transformation
- migration
- nodejs

registry:
access: public
visibility: public
26 changes: 26 additions & 0 deletions recipes/kleur-to-util-styletext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@nodejs/kleur-to-util-styletext",
"version": "1.0.0",
"description": "Migrate from the kleur package to Node.js's built-in util.styleText API",
"type": "module",
"scripts": {
"test": "node --run test:workflow && node --run test:remove-dependencies",
"test:workflow": "npx codemod jssg test -l typescript ./src/workflow.ts ./tests/workflow",
"test:remove-dependencies": "npx codemod jssg test -l json ./src/remove-dependencies.ts ./tests/remove-dependencies --allow-child-process --allow-fs --strictness cst"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nodejs/userland-migrations.git",
"directory": "recipes/kleur-to-util-styletext",
"bugs": "https://github.com/nodejs/userland-migrations/issues"
},
"author": "Herrtian",
"license": "MIT",
"homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/kleur-to-util-styletext/README.md",
"devDependencies": {
"@codemod.com/jssg-types": "^1.6.1"
},
"dependencies": {
"@nodejs/codemod-utils": "*"
}
}
13 changes: 13 additions & 0 deletions recipes/kleur-to-util-styletext/src/remove-dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Transform } from '@codemod.com/jssg-types/main';
import type Json from '@codemod.com/jssg-types/langs/json';
import removeDependencies from '@nodejs/codemod-utils/remove-dependencies';

const transform: Transform<Json> = async (root) => {
return removeDependencies(['kleur'], {
packageJsonPath: root.filename(),
runInstall: false,
persistFileWrite: false,
});
};

export default transform;
Loading
Loading