-
Notifications
You must be signed in to change notification settings - Fork 922
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
[Proposal] Swap Chalk for Kleur #520
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/2ri1bbybp |
Yess! I love PRs like this that reduce dependencies (especially w/ ESM). I’m +1 on this but would love @FredKSchott’s thoughts as well. |
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.
Big fan of this! But again, happy to hear thoughts from @FredKSchott.
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.
Looks good, thanks :)
I'd say that the amount of color-nesting Snowpack has is just below the threshold where I'd start using kleur
(main) instead. It makes writing chains easier, but the drawback is that it doesn't support tree shaking
@@ -47,22 +47,22 @@ export async function getPort(defaultPort: number): Promise<number> { | |||
return bestAvailablePort; | |||
} | |||
|
|||
function getStateString(workerState: any, isWatch: boolean): [chalk.ChalkFunction, string] { | |||
function getStateString(workerState: any, isWatch: boolean): [colors.Colorize, string] { |
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.
Nice :) I'm glad that type came in handy for someone else haha
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.
So since I couldn't get the typings provided to work, this actually just results in any
currently 😢
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.
Interesting. Is there something special about the TS config here? It works for me in multiple places
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.
Do you have an example I can take a look at?
Also, @FredKSchott do you have any idea why it might not be picking up the typing?
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.
Ah, funny enough, I was getting the type information from within JS files – not TS! 😆 microsoft/TypeScript#33079 (comment)
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.
Interesting... 🤔 Thanks for looking into it!
🤔 This is really interesting why the tests aren’t passing. You can see in Inside we have functions like this that replace things like function stripStats(stdout) {
// Need to strip leading whitespace to get around strange Node v13 behavior
return stdout.replace(/\s+[\d\.]*? KB/g, ' XXXX KB');
} And the tests are failing with: - Expected
+ Received
- - snowpack installing...
- ✔ snowpack install complete.
- ⦿ web_modules/ size gzip brotli
- └─ preact/compat.js XXXX KB XXXX KB XXXX KB
+ - snowpack installing...
+ ✔ snowpack install complete.
+ ⦿ web_modules/ size gzip brotli
+ └─ preact/compat.js 19.48 KB 7.44 KB 6.86 KB There’s something about |
I was afraid something like that would happen. If I get the go ahead on this PR, I can dig into it or maybe @lukeed can shed some insight on why this might be happening? |
Yeah please investigate! Unfortunately I don’t have time today to investigate myself. If possible I’d like to figure out what the difference is in output before merging this PR. Maybe you can run the tests locally yourself, and/or test some local builds with this PR? Happy to help with that setup part if you need anything. |
@stramel @drwpow It's to do with ANSI code ordering for closing. The result is still the same, but since the Here's an example:
Notice that in |
It also looks like the ANSI characters are being output in the string and our expected is not checking for those? Output:
Expected:
UPDATE: Yep, if I have it strip the ANSI escapes from the original output it matches as expected. I'm not sure if we want to validate the formatting or not? @FredKSchott @drwpow
|
I've been using Chalk for so long, it's cool to see some new options in the space. I don't feel too strongly either way, so if this is getting people excited then I'm +1 for that alone! Definitely conceptually aligned with the ESM-first approach, and love the idea of supporting other libraries in this as much as possible. Note that we still have chalk in our dependency tree via |
@FredKSchott @drwpow Do you want ansi escapes in the expected output? |
Lets keep escaping for now. If we ever convert these to true snapshot tests, then we won't have to worry about maintaining the ansi ourselves in |
Just a head up that Node 13.0 thru 13.6 will resolve |
You might already know this though, as it's true for all packages with conditional, native ESM support. Luckily there have been multiple versions of 13 that support this correctly -- and all of 13 is "end of life" come July |
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.
LGTM but package-lock conflicts. Mind rebasing, deleting the package-lock & node_modules dir, and then reinstalling?
This PR replaces
chalk
withkleur
.@lukeed just recently released v4 which is generally faster than
chalk
and native ESM. https://twitter.com/lukeed05/status/1273320599008342016Figured I would throw this out there as a PR to start the discussion. Only thing that I ran into was the project wasn't recognizing the typings provided by
kleur
I slid some extra typings in here that we hadn't installed. I can pull this out if we decide to not go this direction.