Skip to content

Replace chalk with picocolors#958

Open
roli-lpci wants to merge 1 commit intohttp-party:masterfrom
roli-lpci:chore/replace-chalk-with-picocolors
Open

Replace chalk with picocolors#958
roli-lpci wants to merge 1 commit intohttp-party:masterfrom
roli-lpci:chore/replace-chalk-with-picocolors

Conversation

@roli-lpci
Copy link

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

- Swap chalk v4 for picocolors (14x smaller, zero dependencies)
- Fix ReferenceError: colors is not defined (lines 115-118)
  The nopanic error handler referenced `colors` instead of the
  imported `chalk` variable, causing a crash on fatal errors
- Fix TypeError: logger.warning is not a function (line 233)
  The websocket proxy warning used `logger.warning()` which does
  not exist on the logger object; changed to `logger.info()`

Addresses http-party#949

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@KernelDeimos
Copy link
Contributor

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.

@roli-lpci
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants