celo-composer
celo-composer copied to clipboard
feat: add dynamic chalk loader for ESM compatibility
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 usesimport()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