Skip to content

Feat chalk adapter#629

Merged
Karanjot786 merged 6 commits into
Karanjot786:mainfrom
Komal2008:feat-chalk-adapter
Jun 4, 2026
Merged

Feat chalk adapter#629
Karanjot786 merged 6 commits into
Karanjot786:mainfrom
Komal2008:feat-chalk-adapter

Conversation

@Komal2008
Copy link
Copy Markdown
Contributor

@Komal2008 Komal2008 commented Jun 3, 2026

Description

Adds a Chalk adapter to @termuijs/adapters for handling Chalk-styled strings inside TermUI widgets.

Changes

  • Added chalkToTermUI adapter in packages/adapters/src/chalk/index.ts
  • Added ANSI passthrough behavior
  • Added ANSI stripping when NO_COLOR is set
  • Added optional peer dependency support for chalk
  • Exported the adapter from packages/adapters/src/index.ts
  • Added tests covering ANSI passthrough and ANSI stripping modes

Related Issue

Closes #72

Which package(s)?

@termuijs/adapters

Type of Change

  • ✨ Feature (type:feature)
  • 🧪 Tests (type:testing)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read [CONTRIBUTING.md](https://chatgpt.com/c/CONTRIBUTING.md).
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (not applicable)
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

  • You are a GSSoC 2026 contributor.
  • Your GSSoC profile: https://gssoc.girlscript.org/profile/2af89ea2-51ba-40f3-a887-93e5300bea0e

Screenshots

image image

Notes for the Reviewer

Implemented a Chalk compatibility adapter following existing adapter patterns. The adapter preserves ANSI-styled strings by default and strips ANSI escape sequences when NO_COLOR is set. Added tests covering both behaviors and exported the adapter through the package entrypoint.

Summary by CodeRabbit

  • New Features

    • Optional color output integration via Chalk; works when installed and remains optional otherwise
    • Color handling respects NO_COLOR to strip ANSI styling; otherwise preserves colors
    • Color adapter exposed from the adapters entry point with clearer messaging when color support isn’t available
  • Tests

    • Added tests for pass-through vs. stripping behavior based on NO_COLOR
    • Verified the new color adapter’s public API and messaging behavior

@Komal2008 Komal2008 requested a review from Karanjot786 as a code owner June 3, 2026 16:08
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 38e78f8e-92f5-4d1d-a0e4-71be4c3e5e76

📥 Commits

Reviewing files that changed from the base of the PR and between 3ba8fbc and d9c2b15.

📒 Files selected for processing (1)
  • packages/adapters/src/chalk/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/adapters/src/chalk/index.ts

📝 Walkthrough

Walkthrough

The PR adds a Chalk adapter to the adapters package: declares chalk as an optional peer dependency, provides ensureChalkInstalled() and chalkToTermUI() to handle runtime availability and conditional ANSI stripping, adds tests for both modes, and re-exports chalkToTermUI from the package entrypoint.

Changes

Chalk adapter for TermUI

Layer / File(s) Summary
Dependency metadata
packages/adapters/package.json
Chalk added to peerDependencies (^5.0.0) and to peerDependenciesMeta with "optional": true.
Chalk adapter functions
packages/adapters/src/chalk/index.ts
Adds ANSI_REGEX, ensureChalkInstalled() (runtime require guard using createRequire), and chalkToTermUI(input) (returns input or strips ANSI when NO_COLOR set).
Testing and package export
packages/adapters/src/chalk/index.test.ts, packages/adapters/src/index.ts
Vitest verifies ANSI passthrough and stripping and that ensureChalkInstalled is exported; barrel export exposes chalkToTermUI from @termuijs/adapters.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant ensureChalkInstalled
  participant chalkToTermUI
  Caller->>ensureChalkInstalled: verify chalk available
  ensureChalkInstalled-->>Caller: throw error or return
  Caller->>chalkToTermUI: pass styled string
  chalkToTermUI-->>Caller: return stripped or original string based on NO_COLOR
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

gssoc:approved, level:advanced, type:feature

Suggested reviewers

  • Karanjot786

Poem

🐰 I hopped in with colors bold and bright,
I hush them when NO_COLOR dims the light,
I guard for chalk when it's not around,
I strip the codes or keep the sound,
Hooray — widgets render just right! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'Feat chalk adapter' is related to the changeset but does not follow the required format 'type: short description' as specified in the repository template. Change title to 'feat: add chalk adapter' to match the 'type: short description' format required by the repository.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is comprehensive and covers all major sections of the template including description, related issue, affected packages, type of change, checklist items, and GSSoC participation.
Linked Issues check ✅ Passed The PR successfully implements all acceptance criteria from issue #72: chalk is added as optional peer dependency, ANSI passthrough and stripping behaviors are implemented and tested, helpful error handling is provided, and the adapter is properly exported.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the chalk adapter implementation as specified in issue #72, with no unrelated refactors or out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the type:testing +10 pts. Tests. label Jun 3, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/adapters/src/chalk/index.test.ts`:
- Around line 5-21: Tests directly mutate process.env.NO_COLOR inside individual
it blocks which risks leaking state on failures; update the test suite for
chalkToTermUI by capturing the original process.env.NO_COLOR in a beforeEach and
restoring it in an afterEach, then change the tests to set/delete
process.env.NO_COLOR without worrying about teardown — reference the existing
tests that set NO_COLOR and the chalkToTermUI assertions so you restore the
original value regardless of test outcome.

In `@packages/adapters/src/chalk/index.ts`:
- Around line 21-22: The current check uses process.env.NO_COLOR as a truthy
check which fails when NO_COLOR is set to an empty string; change the condition
to test key presence (use `'NO_COLOR' in process.env`) so the block that calls
input.replace(ANSI_REGEX, '') runs whenever NO_COLOR is set. Update the if that
references process.env.NO_COLOR to use the `'NO_COLOR' in process.env` presence
check, leaving ANSI_REGEX and the input.replace call unchanged.
- Around line 8-16: ensureChalkInstalled currently uses
createRequire(import.meta.url)('chalk') which can throw ERR_REQUIRE_ESM for
Chalk v5 even when installed; change the presence check to use a resolution-only
approach (e.g., require.resolve('chalk') inside a try/catch) or perform a
dynamic import('chalk') to verify installation instead of calling the CommonJS
require returned by createRequire. Update the function ensureChalkInstalled to
catch and rethrow only when resolution/import fails, preserving the original
error as the cause in the thrown Error so the message and cause reflect real
absence vs ESM-only packaging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bf452097-1dcd-4a40-b293-0ccd07080fff

📥 Commits

Reviewing files that changed from the base of the PR and between 889b802 and 17c45f3.

📒 Files selected for processing (4)
  • packages/adapters/package.json
  • packages/adapters/src/chalk/index.test.ts
  • packages/adapters/src/chalk/index.ts
  • packages/adapters/src/index.ts

Comment thread packages/adapters/src/chalk/index.test.ts Outdated
Comment thread packages/adapters/src/chalk/index.ts
Comment thread packages/adapters/src/chalk/index.ts Outdated
@Komal2008
Copy link
Copy Markdown
Contributor Author

Hi @Karanjot786 👋

I've addressed the review comments and pushed the latest changes. Build and typecheck are passing locally.

Could you please review the PR when you get a chance? Thanks!

@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. quality:exceptional x 1.5 multiplier. Exceptional work. level:intermediate +35 pts. Moderate task. labels Jun 4, 2026
@Karanjot786 Karanjot786 merged commit 3993342 into Karanjot786:main Jun 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved PR. Earns +50 base points. level:intermediate +35 pts. Moderate task. quality:exceptional x 1.5 multiplier. Exceptional work. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Add Chalk adapter to @termuijs/adapters

2 participants