Feat chalk adapter#629
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds a Chalk adapter to the adapters package: declares ChangesChalk adapter for TermUI
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
packages/adapters/package.jsonpackages/adapters/src/chalk/index.test.tspackages/adapters/src/chalk/index.tspackages/adapters/src/index.ts
|
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! |
Description
Adds a Chalk adapter to
@termuijs/adaptersfor handling Chalk-styled strings inside TermUI widgets.Changes
chalkToTermUIadapter inpackages/adapters/src/chalk/index.tsNO_COLORis setchalkpackages/adapters/src/index.tsRelated Issue
Closes #72
Which package(s)?
@termuijs/adapters
Type of Change
type:feature)type:testing)Checklist
needs-starcheck blocks your merge otherwise.bun vitest runbun run buildbun run typecheck[CONTRIBUTING.md](https://chatgpt.com/c/CONTRIBUTING.md).type: short description.markDirty()(not applicable)anytypes without an inline comment explaining why.GSSoC 2026 Participation
https://gssoc.girlscript.org/profile/2af89ea2-51ba-40f3-a887-93e5300bea0eScreenshots
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_COLORis set. Added tests covering both behaviors and exported the adapter through the package entrypoint.Summary by CodeRabbit
New Features
Tests