diff --git a/src/cli/program/config-guard.ts b/src/cli/program/config-guard.ts index 48ca6c26e88..e741b6a42ac 100644 --- a/src/cli/program/config-guard.ts +++ b/src/cli/program/config-guard.ts @@ -1,11 +1,6 @@ -import { loadAndMaybeMigrateDoctorConfig } from "../../commands/doctor-config-flow.js"; import { readConfigFileSnapshot } from "../../config/config.js"; -import { formatConfigIssueLines } from "../../config/issue-format.js"; import type { RuntimeEnv } from "../../runtime.js"; -import { colorize, isRich, theme } from "../../terminal/theme.js"; -import { shortenHomePath } from "../../utils.js"; import { shouldMigrateStateFromPath } from "../argv.js"; -import { formatCliCommand } from "../command-format.js"; const ALLOWED_INVALID_COMMANDS = new Set(["doctor", "logs", "health", "help", "status"]); const ALLOWED_INVALID_GATEWAY_SUBCOMMANDS = new Set([ @@ -47,7 +42,7 @@ export async function ensureConfigReady(params: { if (!didRunDoctorConfigFlow && shouldMigrateStateFromPath(commandPath)) { didRunDoctorConfigFlow = true; const runDoctorConfigFlow = async () => - loadAndMaybeMigrateDoctorConfig({ + (await import("../../commands/doctor-config-flow.js")).loadAndMaybeMigrateDoctorConfig({ options: { nonInteractive: true }, confirm: async () => false, }); @@ -80,6 +75,7 @@ export async function ensureConfigReady(params: { subcommandName && ALLOWED_INVALID_GATEWAY_SUBCOMMANDS.has(subcommandName)) : false; + const { formatConfigIssueLines } = await import("../../config/issue-format.js"); const issues = snapshot.exists && !snapshot.valid ? formatConfigIssueLines(snapshot.issues, "-", { normalizeRoot: true }) @@ -92,6 +88,12 @@ export async function ensureConfigReady(params: { return; } + const [{ colorize, isRich, theme }, { shortenHomePath }, { formatCliCommand }] = + await Promise.all([ + import("../../terminal/theme.js"), + import("../../utils.js"), + import("../command-format.js"), + ]); const rich = isRich(); const muted = (value: string) => colorize(rich, theme.muted, value); const error = (value: string) => colorize(rich, theme.error, value); diff --git a/src/cli/route.ts b/src/cli/route.ts index 763000a3d0b..abd347be0a0 100644 --- a/src/cli/route.ts +++ b/src/cli/route.ts @@ -3,8 +3,6 @@ import { defaultRuntime } from "../runtime.js"; import { VERSION } from "../version.js"; import { getCommandPathWithRootOptions, hasFlag, hasHelpOrVersion } from "./argv.js"; import { emitCliBanner } from "./banner.js"; -import { ensurePluginRegistryLoaded } from "./plugin-registry.js"; -import { ensureConfigReady } from "./program/config-guard.js"; import { findRoutedCommand } from "./program/routes.js"; async function prepareRoutedCommand(params: { @@ -14,6 +12,7 @@ async function prepareRoutedCommand(params: { }) { const suppressDoctorStdout = hasFlag(params.argv, "--json"); emitCliBanner(VERSION, { argv: params.argv }); + const { ensureConfigReady } = await import("./program/config-guard.js"); await ensureConfigReady({ runtime: defaultRuntime, commandPath: params.commandPath, @@ -22,6 +21,7 @@ async function prepareRoutedCommand(params: { const shouldLoadPlugins = typeof params.loadPlugins === "function" ? params.loadPlugins(params.argv) : params.loadPlugins; if (shouldLoadPlugins) { + const { ensurePluginRegistryLoaded } = await import("./plugin-registry.js"); ensurePluginRegistryLoaded({ scope: params.commandPath[0] === "status" || params.commandPath[0] === "health"