-
-
Notifications
You must be signed in to change notification settings - Fork 53
feat(colors-to-util-styletext): add migration recipe #475
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
Open
Herrtian
wants to merge
5
commits into
nodejs:main
Choose a base branch
from
Herrtian:colors-to-util-styletext-474
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bdb92bf
feat(colors-to-util.styleText): add migration recipe
Herrtian 7839445
Address colors migration review
Herrtian 329b59c
Address colors migration review comments
Herrtian cc82be9
Clarify colors destructuring review
Herrtian 9d49ffc
fix(colors): address safe import follow-ups
Herrtian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Colors to util.styleText | ||
|
|
||
| This recipe migrates compatible `colors` package usage to Node.js built-in `util.styleText`. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```diff | ||
| - const colors = require('colors'); | ||
| + const { styleText } = require('node:util'); | ||
| - console.log('Error message'.red); | ||
| + console.log(styleText('red', 'Error message')); | ||
| ``` | ||
|
|
||
| ```diff | ||
| - import colors from 'colors'; | ||
| + import { styleText } from 'node:util'; | ||
| - console.log('Success'.green.bold); | ||
| + console.log(styleText(['green', 'bold'], 'Success')); | ||
| ``` | ||
|
|
||
| ```diff | ||
| - const colors = require('colors/safe'); | ||
| + const { styleText } = require('node:util'); | ||
| - console.log(colors.green('Success message')); | ||
| + console.log(styleText('green', 'Success message')); | ||
| ``` | ||
|
|
||
| ## Compatibility | ||
|
|
||
| - Removes the `colors` dependency from package.json automatically. | ||
| - Supports string prototype colors and modifiers, including chained styles. | ||
| - Supports `colors/safe` namespace calls. | ||
| - Unsupported extras such as `rainbow`, `zebra`, `america`, `trap`, and `random` are left unchanged and reported for manual review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| schema_version: "1.0" | ||
| name: "@nodejs/colors-to-util-styletext" | ||
| version: 1.0.0 | ||
| capabilities: | ||
| - fs | ||
| - child_process | ||
| description: Migrate from the colors 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: | ||
| - nodejs | ||
| - colors | ||
| - styleText | ||
|
|
||
| registry: | ||
| access: public | ||
| visibility: public | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "name": "@nodejs/colors-to-util-styletext", | ||
| "version": "1.0.0", | ||
| "description": "Migrate from the colors 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", | ||
| "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/colors-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/colors-to-util-styletext/README.md", | ||
| "devDependencies": { | ||
| "@codemod.com/jssg-types": "^1.6.0" | ||
| }, | ||
| "dependencies": { | ||
| "@nodejs/codemod-utils": "*" | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
recipes/colors-to-util-styletext/src/remove-dependencies.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(['colors', '@types/colors'], { | ||
| packageJsonPath: root.filename(), | ||
| runInstall: false, | ||
| persistFileWrite: false, | ||
| }); | ||
| }; | ||
|
|
||
| export default transform; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.