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.

Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

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.

Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

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
});

if (Boolean(namespaceImport) && namespaceImport.text() === options.old) {
if (namespaceImport && namespaceImport.text() === options.old) {
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.

why this change ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This was automatically applied by the Biome linter during the pre-commit check — Boolean(namespaceImport) and namespaceImport are functionally equivalent in a conditional and Biome flags the explicit coercion as unnecessary. Happy to revert if you'd prefer to keep the original.

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.

no probleme

@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
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

2 participants