-
Notifications
You must be signed in to change notification settings - Fork 399
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 chalk with smaller and faster ansis #2845
base: next
Are you sure you want to change the base?
Conversation
@@ -63,7 +63,7 @@ export class TypeCheckerHost { | |||
const reportWatchStatusCallback = (diagnostic: ts.Diagnostic) => { | |||
if (diagnostic.messageText !== TSC_NO_ERRORS_MESSAGE) { | |||
if ((diagnostic.messageText as string)?.includes('Found')) { | |||
console.log(TSC_LOG_ERROR_PREFIX, chalk.red(diagnostic.messageText)); | |||
console.log(TSC_LOG_ERROR_PREFIX, red(diagnostic.messageText.toString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ansis method accepts the string
or number
argument, but diagnostic.messageText
is string | ts.DiagnosticMessageChain
, therefore we need it to convert into string
console.info( | ||
'OS Version :', | ||
chalk.blue(osName(platform(), release()), release()), | ||
blue(osName(platform(), release()) + release()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ansis method accepts only one argument as a string, therefore we need to concatenate two stings into one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! I just changed the base branch to next and a few minor conflicts popped up. Would you like to resolve them? |
yes of cause, I will resolve conflicts |
@kamilmysliwiec in the
Error:
Using |
You can safely ignore that error and run |
a4c99de
to
101081a
Compare
@kamilmysliwiec I have applied my changes directly to the next branch and force pushed here. So my branch has no conflicts with the But the checker (build-and-test) can't install it because of npm error. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
This PR replaces the outdated chalk@4 (
64 kB
install size, 2 dependencies) package with smaller and faster ansis.Benefits of
ansis
import { red, bold, bgRgb } from 'ansis'
10KB
(no dependencies), see Compare the size of most popular packageschalk
, see BenchmarksPackages that already use
ansis
Alternatives
Today are actual two fastest and smallest libraries::
picocolors
andansis
.Both are recommended by the ES Tooling community .
picocolors
vsansis
, see the Compare featurespicocolors
-6.3 kB
ansis
-10.3 kB
picocolors
is fastestansis
is fastestpicocolors
doesn't supports the truecoloransis
has rgb() and hex() functions, e.g.bgRgb(60, 190, 100).bold.rgb(0, 0, 0)(' Info ');
ansis supports fallback to supported color space:
TrueColor —> 256 colors —> 16 colors —> no colors (black & white)
picocolors
doesn't supports chained syntax:picocolors.bgCyan(picocolors.bold(' SWC '))
ansis
supports chained syntax:bgCyan.bold(' SWC ')
<= more readable and shorterTest
This PR does not require unit/integration tests.
But you can do the
manual test
.Install the fork
Test changed files
Cmd:
In console output will be displayed color text:
Test changed files
Cmd:
In console output will be displayed color text:
Test changed files
Cmd:
In console output will be displayed color text:
Test changed files
Cmd:
In console output will be displayed color text: