Replace chalk with picocolors
Summary
- Replace
chalk(v4, 5 transitive deps) withpicocolors(v1, zero deps) - Fix
ReferenceError: colors is not definedin the--no-panicerror handler - Fix
TypeError: logger.warning is not a functionin the WebSocket proxy check
Changes
bin/http-server
require('chalk')→require('picocolors')- Fix undefined
colorsvariable references (lines 115-118) that caused crashes in the--no-panicerror handler —colorswas never imported, should have beenchalk(nowpc) - Fix
logger.warning()call — the logger object has no.warning()method; changed tologger.info()which is the available output method
package.json
- Remove
chalk^4.1.2 - Add
picocolors^1.1.1
All color methods used (red, cyan, yellow, green, magenta, bold)
have exact equivalents in picocolors. Both libraries respect NO_COLOR and
FORCE_COLOR environment variables.
Testing
Asserts: 528 pass 0 fail 528 of 528 complete
Suites: 41 pass 0 fail 41 of 41 complete
Addresses #949
picocolors seems cool - 2x faster than chalk is great, 14x smaller is even better - but what issues are we going to introduce with the smaller alternative? Is chalk 14x the size for a reason? I noticed there's an included library that reports color support for known terminals - I reckon we might need that.
Btw we might repeat the same mistake that caused #949; please use the name chalk instead of pc even though the picocolors package is being used.
Good question. picocolors does handle color support detection -- it checks NO_COLOR, FORCE_COLOR, and whether stdout is a TTY. The difference is chalk bundles a larger lookup table that maps specific terminal app names (iTerm, ConEmu, etc.) to 256-color and truecolor support levels.
But http-server only uses basic colors -- red, green, cyan, bold -- never 256-color or truecolor. So the simpler detection in picocolors covers everything we actually need here. No functionality lost for this use case.