es-tooling / module-replacements-codemods

MIT License
184 stars 24 forks source link

feat: add chalk codemod #77

Closed 43081j closed 1 month ago

43081j commented 1 month ago

Adds a codemod for moving from chalk to picocolors.

This will throw if exports are encountered which picocolors doesn't provide. For example, as of writing this, picocolors doesn't support bright colours (but soon will). That means chalk.redBright will throw since picocolors has no redBright export.

These patterns are supported:


// Before
chalk.red.bold(str);
// After
pc.red(pc.bold(str));

// Before
chalk.red`i am red`;
// After
pc.red(`i am red`);

// Before
chalk.red`i am red and ${chalk.bold('bold')}!`;
// After
pc.red(`i am red and ${pc.bold('bold')}!`);

Some patterns will not be detected. For example:

// Not detected since it isn't a call expression
chalk.red;

// Similarly not detected
const red = chalk.red;
red(str);
thepassle commented 1 month ago

nice 👍