feat(kleur-to-util-styletext): add codemod#509
Open
GiHoon1123 wants to merge 1 commit into
Open
Conversation
Adapted from recipes/chalk-to-util-styletext, since kleur's API (chainable style methods, direct calls) closely mirrors chalk's. kleur's real API is a subset of chalk's - no hex/rgb/ansi256, no Bright color variants, no chalkStderr - so those branches are dropped rather than adapted. Fixes nodejs#479
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #479.
Summary
Adds a codemod that migrates
kleurtonode:util'sstyleText(), following the same shape as the existingchalk-to-util-styletextrecipe.kleur's API is basically a subset ofchalk's (chainable style methods, direct calls), so this is adapted from that recipe rather than written from scratch.kleur's real API is smaller than chalk's - no
hex()/rgb()/ansi256(), no "Bright" color variants, nochalkStderr. Every method kleur actually ships has a directstyleTextequivalent, so there's nothing left unsupported by design (the unsupported-method guard is kept anyway, in case a future kleur version adds something new).Examples
Changes
recipes/kleur-to-util-styletext/src/workflow.ts: main transform. Handles default import/require, named/destructured imports, dynamic import, chained calls (up to 4 styles), method assignment to a variable, and ternary-based style selection.recipes/kleur-to-util-styletext/src/remove-dependencies.ts: removeskleurfrompackage.json(no@types/kleurexists, kleur ships its own types).README.mddocuments one real limitation: direct calls chaining more than 4 styles (kleur.a.b.c.d.e(...)) aren't transformed and are left as-is (no crash, just a no-op). Chaining through a variable assignment first isn't affected by this - only direct calls are.Test plan
node --run test:workflow- 18/18 passingnode --run test:remove-dependencies- 1/1 passingnode --run pre-commit(lint + type-check + full workspace test suite) passes