deps: replace chalk with built-in styleText#9793
Open
james-pre wants to merge 3 commits into
Open
Conversation
Also removed now unused `supports-color`
chalk with built-in styleTextchalk with built-in styleText
chalk with built-in styleTextchalk with built-in styleText
Contributor
Author
|
One of the patch tests is failing for 24.15.0 due to a race condition during cleanup. This failure isn't related to the PR. @manzoorwanijk you've done most of the work for |
chalk with built-in styleTextchalk with built-in styleText
Contributor
Thank you for the ping Yes, it's unrelated to this PR. I dug into it and there are two defects in
I have created a fix for it - #9798 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: get rid of two dependencies and color dependency injection
This PR replaces the
chalkdependency with the built-instyleTextfunction provided bynode:util. This is already support in all of the Node.js versions npm supports. There is no longer a reason to include a bundled runtime dependency when the platform can do the same job.The biggest benefit is that we get rid of dependency injection for colors. Before 3 different chalk instances (
npm.chalk,npm.logChalk,npm.noColorChalk) were passed to every single command so that the colorization could happen in one place. Now, call sites can use a tinycolorutility that is configured by display.js. This also meanssupports-coloris no longer needed so that was removed as well.npm-audit-reportcurrently uses this dependency injection, which is being addressed in npm/npm-audit-report#162. That PR's changes have been included in this one pending a merge and release, when we can actually update the dependency.There are a couple of small changes to how rendering is handled:
styleTextemits the codes one. This has no effect on the on the rendered output.styleTextdoesn't so we now account for this when highlighting matches in the package name duringnpm search(the only place styles are nested)In case it matters this PR results in an 8.2 KB smaller tarball and 22.7 KB smaller install size. This is only a ~0.3% change though.