http-server icon indicating copy to clipboard operation
http-server copied to clipboard

Replace chalk with picocolors

Open roli-lpci opened this issue 9 months ago • 2 comments

Summary

  • Replace chalk (v4, 5 transitive deps) with picocolors (v1, zero deps)
  • Fix ReferenceError: colors is not defined in the --no-panic error handler
  • Fix TypeError: logger.warning is not a function in the WebSocket proxy check

Changes

bin/http-server

  • require('chalk') → require('picocolors')
  • Fix undefined colors variable references (lines 115-118) that caused crashes in the --no-panic error handler — colors was never imported, should have been chalk (now pc)
  • Fix logger.warning() call — the logger object has no .warning() method; changed to logger.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

roli-lpci avatar Feb 27 '26 20:02 roli-lpci

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.

KernelDeimos avatar Mar 12 '26 18:03 KernelDeimos

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.

roli-lpci avatar Mar 14 '26 22:03 roli-lpci