fix: use chalkStderr for stderr color detection#57
Merged
Conversation
All logging and error output goes to stderr, but was using chalk's default instance which detects color support based on stdout TTY state. This caused colors to break when only stdout was redirected, and ANSI codes to leak into files when stderr was redirected. Switch to chalkStderr which uses process.stderr.isTTY for detection, and tie util.inspect's color flag to chalkStderr.level. Closes #51
There was a problem hiding this comment.
Pull request overview
This PR fixes stderr colorization behavior by switching all stderr-oriented output paths from stdout-based chalk detection to chalkStderr, ensuring ANSI styling follows process.stderr TTY state (and preventing escape-code leakage when stderr is redirected).
Changes:
- Replace
chalkwithchalkStderrin the logger, platform resolution logging, and Commander’s stderr writer. - Tie
util.inspect(..., colors)tochalkStderr.levelso inspected objects only include color codes when stderr supports color.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/platform/index.ts |
Uses chalkStderr for the “Resolved platform” log message so platform logging respects stderr TTY. |
src/logging/index.ts |
Routes all logger styling through chalkStderr and gates util.inspect colors based on chalkStderr.level. |
index.ts |
Updates Commander stderr output and top-level error formatting to use chalkStderr. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Consumers now import `style` from the logging module instead of chalk directly, keeping the stderr color detection in one place.
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.
Summary
chalk(stdout-based TTY detection) withchalkStderrin all stderr output paths: logger, Commander error handler, and error formattingutil.inspectcolor flag tochalkStderr.levelso inspect output also respects stderr TTY stateCloses #51
Test plan
./git-that-semver --log-level DEBUG > /dev/null— stderr should remain colored in terminal./git-that-semver --log-level DEBUG 2> /tmp/stderr.log && cat -v /tmp/stderr.log— no^[[escape codes in file./git-that-semver --config-file nonexistent.yaml 2> /tmp/err.log && cat -v /tmp/err.log— error output also clean