-
-
Notifications
You must be signed in to change notification settings - Fork 56
feat(ansi-colors-to-styletext): introduce #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e603f32
1e0672b
d2cab92
067c631
a4b0399
36eba4c
2f1eb46
15c4bd2
5105999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # ansi-colors to util.styleText | ||
|
|
||
| This recipe migrates from the external `ansi-colors` package to Node.js's built-in `util.styleText` API. It transforms ansi-colors method calls to use the native Node.js styling functionality. | ||
|
|
||
| ## Usage | ||
|
|
||
| Run this codemod with: | ||
|
|
||
| ```sh | ||
| npx codemod @nodejs/ansi-colors-to-styletext | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| ```diff | ||
| - import ac from 'ansi-colors'; | ||
| + import { styleText, stripVTControlCharacters } from 'node:util'; | ||
|
|
||
| - console.log(ac.red('Error message')); | ||
| + console.log(styleText('red', 'Error message')); | ||
|
|
||
| - console.log(ac.green('Success message')); | ||
| + console.log(styleText('green', 'Success message')); | ||
|
|
||
| - console.log(ac.unstyle(ac.bold.blue('Info message'))); | ||
| + console.log(stripVTControlCharacters(styleText(['bold', 'blue'], 'Info message'))); | ||
| ``` | ||
|
|
||
| ```diff | ||
| - const ac = require('ansi-colors'); | ||
| + const { styleText } = require('node:util'); | ||
|
|
||
| - console.log(ac.bold.red('Critical error')); | ||
| + console.log(styleText(['bold', 'red'], 'Critical error')); | ||
| ``` | ||
|
|
||
| ```diff | ||
| - const { red, blue } = require('ansi-colors'); | ||
| + const { styleText } = require('node:util'); | ||
|
|
||
| - console.log(red('Error')); | ||
| + console.log(styleText('red', 'Error')); | ||
|
|
||
| - console.log(blue('Info')); | ||
| + console.log(styleText('blue', 'Info')); | ||
| ``` | ||
|
|
||
| ## Compatibility | ||
|
|
||
| - **Removes ansi-colors dependency** from package.json automatically | ||
| - **Supports all ansi-colors methods**: colors, background colors, text modifiers, and chained styles | ||
| - **Unsupported methods**: `enabled`, `visible`, `unstyle`, `alias`, `theme`, `create` (warnings will be shown) | ||
|
|
||
| ## Limitations | ||
|
|
||
| - **Runtime toggles** like `ac.enabled = false` require manual intervention | ||
| - **Custom themes and aliases** need to be rewritten as plain objects | ||
| - **Dynamic imports with `.then()`** are not transformed and require manual migration | ||
|
|
||
| <!-- sync_to_learn: true --> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| schema_version: "1.0" | ||
| name: "@nodejs/ansi-colors-to-styletext" | ||
| version: 1.0.0 | ||
| capabilities: | ||
| - fs | ||
| - child_process | ||
| description: "Migrate from ansi-colors package to Node.js util.styleText API" | ||
| author: Shamya Haria | ||
| license: MIT | ||
| workflow: workflow.yaml | ||
| category: migration | ||
| repository: https://github.com/nodejs/userland-migrations | ||
|
|
||
| targets: | ||
| languages: | ||
| - javascript | ||
| - typescript | ||
|
|
||
| keywords: | ||
| - transformation | ||
| - migration | ||
| - nodejs | ||
| - ansi-colors | ||
| - styletext | ||
|
|
||
| registry: | ||
| access: public | ||
| visibility: public |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "name": "@nodejs/ansi-colors-to-styletext", | ||
| "version": "1.0.0", | ||
| "description": "Migrate from ansi-colors package to Node.js util.styleText API", | ||
| "type": "module", | ||
| "scripts": { | ||
| "test": "npx codemod jssg test -l typescript ./src/workflow.ts ./tests && npx codemod jssg test -l json ./src/remove-dependencies.ts ./tests/remove-dependencies --allow-child-process --allow-fs --strictness cst", | ||
| "test:workflow": "npx codemod jssg test -l typescript ./src/workflow.ts ./tests", | ||
| "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/ansi-colors-to-styletext", | ||
| "bugs": "https://github.com/nodejs/userland-migrations/issues" | ||
| }, | ||
| "author": "Shamya Haria", | ||
| "license": "MIT", | ||
| "homepage": "https://github.com/nodejs/userland-migrations/blob/main/recipes/ansi-colors-to-styletext/README.md", | ||
| "devDependencies": { | ||
| "@codemod.com/jssg-types": "^1.6.3" | ||
| }, | ||
| "dependencies": { | ||
| "@nodejs/codemod-utils": "*" | ||
| } | ||
| } |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really doing anything—it seems just bloat.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I what we do for all ecosystem codemod |
| 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(['ansi-colors', '@types/ansi-colors'], { | ||
| packageJsonPath: root.filename(), | ||
| runInstall: false, | ||
| persistFileWrite: false, | ||
| }); | ||
| }; | ||
|
|
||
| export default transform; |
Uh oh!
There was an error while loading. Please reload this page.