Skip to content

feat: add chalk codemod#77

Merged
thepassle merged 1 commit intomainfrom
chalk
Aug 1, 2024
Merged

feat: add chalk codemod#77
thepassle merged 1 commit intomainfrom
chalk

Conversation

@43081j
Copy link
Contributor

@43081j 43081j commented Aug 1, 2024

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

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:

```ts

// 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:

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

// Similarly not detected
const red = chalk.red;
red(str);
```
@thepassle
Copy link
Collaborator

nice 👍

@thepassle thepassle merged commit 8ddb3f7 into main Aug 1, 2024
@43081j 43081j deleted the chalk branch August 1, 2024 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants