Skip to content

feat: add dynamic chalk loader for ESM compatibility#371

Open
wearedood wants to merge 1 commit into
celo-org:mainfrom
wearedood:feat/fix-esm-chalk-358
Open

feat: add dynamic chalk loader for ESM compatibility#371
wearedood wants to merge 1 commit into
celo-org:mainfrom
wearedood:feat/fix-esm-chalk-358

Conversation

@wearedood
Copy link
Copy Markdown

Summary

Fixes ESM import error caused by chalk being ESM-only in version 5.x. This PR adds a dynamic chalk loader with fallback shim to maintain compatibility while supporting the latest chalk version.

Changes Made

  • Added src/utils/getChalk.ts: Dynamic loader that uses import() to load ESM-only chalk with graceful fallback
  • Updated src/index.ts: Modified CLI entrypoint to use async IIFE pattern with the getChalk helper
  • Maintained backward compatibility: All existing chalk styling functions work as expected

Technical Details

  • Uses dynamic import() to handle ESM-only chalk package
  • Provides fallback shim with common chalk methods (red, green, yellow, blue, etc.)
  • Proxy-based chaining support for complex styling like chalk.green.bold()
  • Minimal risk approach: only modified CLI entrypoint, no changes to library modules

Testing

  • npm run build - TypeScript compilation successful
  • npm run lint - ESLint passes
  • npm test - All tests pass
  • node dist/index.js --help - CLI works correctly
  • npm pack - Package creation successful
  • ✅ No ESM import errors

Closes

#358

Add getChalk.ts helper that dynamically imports ESM-only chalk
with fallback shim for compatibility. Addresses issue celo-org#358.
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.

1 participant