Skip to content

refactor: replace chalk with node:util styleText - #352

Merged
finalerock44 merged 1 commit into
devfrom
refactor/chalk-to-styletext
Nov 23, 2026
Merged

finalerock44 merged 1 commit into
devfrom
refactor/chalk-to-styletext

Conversation

@finalerock44

Copy link
Copy Markdown
Contributor

chalk was imported in one file, src/utils/styling.ts. Node's built-in util.styleText does the same job, so the dependency goes.

styling.ts decides whether a stream takes colour itself, by the rule Node's styleText applies (FORCE_COLOR when set, otherwise a TTY with a colour depth above monochrome), and only then calls styleText. Not every runtime makes that check: bun 1.3, which compiles the standalone binaries, colours unconditionally.

Colour is still decided by stdout, as chalk did. Text written to stderr now goes through forStderr(), which strips the codes when stderr does not take colour, so dcd cloud 2> err.log from a terminal no longer writes escape codes into the file. NO_COLOR is now honoured too.

A colours call with a non-string prints it rather than throwing, as chalk did. The Node floor moves to 22.8.0.

Closes #330

What & why

Type of change

  • fix — bug fix
  • feat — new feature
  • perf — performance improvement
  • refactor — code change that's neither a fix nor a feature
  • docs — documentation only
  • chore / ci / build / test — tooling, no user-facing change
  • Breaking change (title has ! or PR notes a BREAKING CHANGE:)

Checklist

  • PR title follows the Conventional Commits format (see comment above)
  • pnpm lint passes
  • pnpm typecheck passes
  • pnpm build passes
  • I have not bumped the version or edited CHANGELOG.md (the release workflow handles this)
  • I have signed the CLA (the bot will prompt on first contribution)
  • Docs / README.md / STYLE_GUIDE.md updated if behaviour or output changed

How to test

chalk was imported in one file, src/utils/styling.ts. Node's built-in
util.styleText does the same job, so the dependency goes.

styling.ts decides whether a stream takes colour itself, by the rule
Node's styleText applies (FORCE_COLOR when set, otherwise a TTY with a
colour depth above monochrome), and only then calls styleText. Not every
runtime makes that check: bun 1.3, which compiles the standalone
binaries, colours unconditionally.

Colour is still decided by stdout, as chalk did. Text written to stderr
now goes through forStderr(), which strips the codes when stderr does
not take colour, so `dcd cloud 2> err.log` from a terminal no longer
writes escape codes into the file. NO_COLOR is now honoured too.

A colours call with a non-string prints it rather than throwing, as
chalk did. The Node floor moves to 22.8.0.

Closes #330
@finalerock44 finalerock44 self-assigned this Nov 23, 2026
@claude

claude Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@finalerock44
finalerock44 merged commit 2e2377b into dev Nov 23, 2026
9 checks passed
@finalerock44
finalerock44 deleted the refactor/chalk-to-styletext branch November 23, 2026 16:49
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.

Replace chalk with Node's built-in util.styleText

1 participant