Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: replace ansi-colors with smaller and faster ansis #5274

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

webdiscus
Copy link

@webdiscus webdiscus commented Dec 17, 2024

PR Checklist

Overview

This PR replaces the outdated ansi-colors (last update 3 years ago) package with smaller and faster ansis.

Benefits of ansis

  • Supports both ESM and CommonJS
  • Supports Bun and Deno runtimes
  • Supports TypeScript
  • Ansis is compatible with ansi-colors API, plus supports named import: import { red, yellow } from 'ansis'
  • Installed package size only 10 kB (ansi-colors 26 kB), see Compare the size of most popular packages
  • 7-10x faster than ansi-colors, see Benchmarks
  • Using named import your code will be clean and more readable:
    - console.error(ansi.red(`Error: ${result.error.message}`));
    + console.error(red`Error: ${result.error.message}`); // <= shorter and more readable
  • Supports ANSI 256 colors and TrueColor with Fallback: TrueColor → 256 colors → 16 colors → no colors
  • Supports environment variables NO_COLOR FORCE_COLOR and flags --no-color --color
  • Both Ansis and Picocolors (does't support named import) are recommended by the ES Tooling community as smallest and fastest packages.

Packages that already use ansis

Test

This PR does not require unit/integration tests.

But you can do the manual test.

Install the fork

git clone https://github.com/webdiscus/mocha.git
cd mocha
git checkout switch-to-ansis
npm i
npm run build

Test changed files

Cmd:

node ./bin/mocha.js -h

In console output will be displayed color text:
Other Options

Cmd:

node ./bin/mocha.js -h --no-color

In console output will be displayed b&w text:
Other Options

Cmd:

node ./bin/mocha.js -R

In console output will be displayed red text:
Error Not enough arguments following R

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.

1 participant