Skip to content

Commit ea04361

Browse files
committed
fix(cli): lazy-load logger for analytics debug
1 parent 5230cc9 commit ea04361

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

cli/src/utils/analytics.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,32 @@ function resolveDeps(): ResolvedAnalyticsDeps {
7373
}
7474
}
7575

76+
let loggerModulePromise:
77+
| Promise<{ logger: { debug: (data: any, msg?: string, ...args: any[]) => void } }>
78+
| null = null
79+
80+
const loadLogger = () => {
81+
if (!loggerModulePromise) {
82+
loggerModulePromise = import('./logger')
83+
}
84+
return loggerModulePromise
85+
}
86+
7687
function logAnalyticsDebug(message: string, data: Record<string, unknown>) {
7788
if (!DEBUG_ANALYTICS) {
7889
return
7990
}
80-
try {
81-
console.debug(message, data)
82-
} catch {
83-
// Ignore console errors in restricted environments
84-
}
91+
void loadLogger()
92+
.then(({ logger }) => {
93+
logger.debug(data, message)
94+
})
95+
.catch(() => {
96+
try {
97+
console.debug(message, data)
98+
} catch {
99+
// Ignore console errors in restricted environments
100+
}
101+
})
85102
}
86103

87104
/** Get current distinct ID (real user ID if identified, otherwise anonymous ID) */

0 commit comments

Comments
 (0)