diff --git a/src/flows/doctor-health.ts b/src/flows/doctor-health.ts index 683bd4713a5..52caa5c508d 100644 --- a/src/flows/doctor-health.ts +++ b/src/flows/doctor-health.ts @@ -6,10 +6,18 @@ import type { RuntimeEnv } from "../runtime.js"; const intro = (message: string) => clackIntro(stylePromptTitle(message) ?? message); const outro = (message: string) => clackOutro(stylePromptTitle(message) ?? message); +type ConfigModule = typeof import("../config/config.js"); + +let configModulePromise: Promise | undefined; + +function loadConfigModule(): Promise { + return (configModulePromise ??= import("../config/config.js")); +} + export async function doctorCommand(runtime?: RuntimeEnv, options: DoctorOptions = {}) { const effectiveRuntime = runtime ?? (await import("../runtime.js")).defaultRuntime; if (options.repair === true || options.yes === true || options.generateGatewayToken === true) { - const { assertConfigWriteAllowedInCurrentMode } = await import("../config/config.js"); + const { assertConfigWriteAllowedInCurrentMode } = await loadConfigModule(); assertConfigWriteAllowedInCurrentMode(); } @@ -55,7 +63,7 @@ export async function doctorCommand(runtime?: RuntimeEnv, options: DoctorOptions runtime: effectiveRuntime, prompter, }); - const { CONFIG_PATH } = await import("../config/config.js"); + const { CONFIG_PATH } = await loadConfigModule(); const ctx = { runtime: effectiveRuntime, options,