-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathchalk.ts
More file actions
27 lines (24 loc) · 819 Bytes
/
chalk.ts
File metadata and controls
27 lines (24 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Chalk 5 is ESM-only. We load it via dynamic import and cache for use in CommonJS.
*/
let chalkInstance: typeof import('chalk').default | null = null;
export type ChalkInstance = typeof import('chalk').default;
/**
* Load chalk (ESM) and cache it. Call this once during CLI init before any chalk usage.
*/
export async function loadChalk(): Promise<ChalkInstance> {
if (!chalkInstance) {
const chalkModule = await import('chalk');
chalkInstance = chalkModule.default;
}
return chalkInstance;
}
/**
* Get the cached chalk instance. Must call loadChalk() first (e.g. in init hook).
*/
export function getChalk(): ChalkInstance {
if (!chalkInstance) {
throw new Error('Chalk not loaded. Ensure loadChalk() is called during init (e.g. in utils-init hook).');
}
return chalkInstance;
}