Skip to content

feat(ansi-colors-to-styletext): introduce#481

Open
ShamyaHaria wants to merge 7 commits into
nodejs:mainfrom
ShamyaHaria:feat/ansi-colors-to-styletext
Open

feat(ansi-colors-to-styletext): introduce#481
ShamyaHaria wants to merge 7 commits into
nodejs:mainfrom
ShamyaHaria:feat/ansi-colors-to-styletext

Conversation

@ShamyaHaria

Copy link
Copy Markdown

Closes #480
Implements the ansi-colors to util.styleText codemod as specified in the issue. The transform handles the following cases:

CommonJS require('ansi-colors') and ES module import ac from 'ansi-colors' — both replaced with the appropriate styleText destructured import from node:util
Simple single style calls — ac.red('text') becomes styleText('red', 'text')
Chained style calls — ac.bold.red('text') becomes styleText(['bold', 'red'], 'text')
Unsupported APIs — detects enabled, visible, unstyle, alias, theme, and create, skips transformation for the enclosing scope, and emits a warning pointing to the line for manual remediation

190 tests passing, 0 failures. Coverage on the new file is 96.94% line and 100% function.

@AugustinMauroy

Copy link
Copy Markdown
Member

hello thanks for the effort here but you aren't shipping any codemod here just codes stored on utils package. So please read the CONTRIBUTING.MD

@AugustinMauroy AugustinMauroy added the awaiting author Reviewer has requested something from the author label Jun 3, 2026
@ShamyaHaria

Copy link
Copy Markdown
Author

Hi @AugustinMauroy, I've reworked the full implementation. The codemod is now properly structured under recipes/ansi-colors-to-styletext/ with all required files.

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test case:

  • dynamic import with await
  • dynamic import with then methode
  • mixed syntax like chained and imported
  • imported with commonJS const { red, blue } = require('ansi-colors');

Comment thread utils/src/ast-grep/ansi-colors-to-styletext.test.ts Outdated
Comment thread utils/src/ast-grep/ansi-colors-to-styletext.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/README.md
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
@AugustinMauroy AugustinMauroy changed the title feat: add ansi-colors to styleText codemod feat(ansi-colors-to-styletext): introduce Jun 4, 2026
@AugustinMauroy

Copy link
Copy Markdown
Member

also you have to npm i to sync lock file with new workspace

@ShamyaHaria

Copy link
Copy Markdown
Author

Hi @AugustinMauroy, all feedback addressed.

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT !

Comment thread recipes/ansi-colors-to-styletext/README.md Outdated
Comment thread utils/src/ast-grep/update-binding.ts
@AugustinMauroy AugustinMauroy changed the title feat(ansi-colors-to-styletext): introduce feat(ansi-colors-to-styletext): introduce Jun 5, 2026
@AugustinMauroy AugustinMauroy added awaiting reviewer Author has responded and needs action from the reviewer and removed awaiting author Reviewer has requested something from the author labels Jun 6, 2026
@AugustinMauroy AugustinMauroy requested a review from a team June 6, 2026 08:15

@brunocroh brunocroh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JakobJingleheimer JakobJingleheimer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Mostly nits and code health improvements; but I do have a concern about the handling of unsupported APIs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really doing anything—it seems just bloat.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I what we do for all ecosystem codemod

Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated
Comment thread recipes/ansi-colors-to-styletext/src/workflow.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a problem, no? The rest is migrated, but it leaves dead code that I think now broken.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's specify on the readme as not migratable api we can leave that as it but add test to be sure it's not modified

@JakobJingleheimer

Copy link
Copy Markdown
Member

Um, what the heck happened with these commits—did you cherry-pick them from main instead of just merging main into this branch?

@ShamyaHaria ShamyaHaria force-pushed the feat/ansi-colors-to-styletext branch from 4af94d1 to 2f1eb46 Compare July 7, 2026 18:33
@ShamyaHaria

Copy link
Copy Markdown
Author

These came in accidentally during a git pull origin feat/ansi-colors-to-styletext --rebase which pulled in commits from my remote fork that had already gotten upstream changes mixed in. I've cleaned it up with a force push — the branch now only contains my commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewer Author has responded and needs action from the reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spec: ansi-colors-to-styletext

4 participants