perf: lazy-load status route startup helpers

This commit is contained in:
Ayaan Zaidi
2026-03-16 22:07:59 +05:30
parent 97a7dcf48e
commit 7e2658908d
2 changed files with 10 additions and 8 deletions

View File

@@ -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);

View File

@@ -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"