diff --git a/src/cli/devices-cli.ts b/src/cli/devices-cli.ts index 7a0da95a486..d0b8aecd865 100644 --- a/src/cli/devices-cli.ts +++ b/src/cli/devices-cli.ts @@ -17,6 +17,14 @@ type DevicesRpcOpts = { const DEFAULT_DEVICES_TIMEOUT_MS = 10_000; +type DevicesRuntimeModule = typeof import("./devices-cli.runtime.js"); + +let devicesRuntimePromise: Promise | undefined; + +function loadDevicesRuntime(): Promise { + return (devicesRuntimePromise ??= import("./devices-cli.runtime.js")); +} + const devicesCallOpts = (cmd: Command, defaults?: { timeoutMs?: number }) => cmd .option("--url ", "Gateway WebSocket URL (defaults to gateway.remote.url when configured)") @@ -37,7 +45,7 @@ export function registerDevicesCli(program: Command) { .command("list") .description("List pending and paired devices") .action(async (opts: DevicesRpcOpts) => { - const { runDevicesListCommand } = await import("./devices-cli.runtime.js"); + const { runDevicesListCommand } = await loadDevicesRuntime(); await runDevicesListCommand(opts); }), ); @@ -48,7 +56,7 @@ export function registerDevicesCli(program: Command) { .description("Remove a paired device entry") .argument("", "Paired device id") .action(async (deviceId: string, opts: DevicesRpcOpts) => { - const { runDevicesRemoveCommand } = await import("./devices-cli.runtime.js"); + const { runDevicesRemoveCommand } = await loadDevicesRuntime(); await runDevicesRemoveCommand(deviceId, opts); }), ); @@ -60,7 +68,7 @@ export function registerDevicesCli(program: Command) { .option("--pending", "Also reject all pending pairing requests", false) .option("--yes", "Confirm destructive clear", false) .action(async (opts: DevicesRpcOpts) => { - const { runDevicesClearCommand } = await import("./devices-cli.runtime.js"); + const { runDevicesClearCommand } = await loadDevicesRuntime(); await runDevicesClearCommand(opts); }), ); @@ -72,7 +80,7 @@ export function registerDevicesCli(program: Command) { .argument("[requestId]", "Pending request id") .option("--latest", "Show the most recent pending request to approve explicitly", false) .action(async (requestId: string | undefined, opts: DevicesRpcOpts) => { - const { runDevicesApproveCommand } = await import("./devices-cli.runtime.js"); + const { runDevicesApproveCommand } = await loadDevicesRuntime(); await runDevicesApproveCommand(requestId, opts); }), ); @@ -83,7 +91,7 @@ export function registerDevicesCli(program: Command) { .description("Reject a pending device pairing request") .argument("", "Pending request id") .action(async (requestId: string, opts: DevicesRpcOpts) => { - const { runDevicesRejectCommand } = await import("./devices-cli.runtime.js"); + const { runDevicesRejectCommand } = await loadDevicesRuntime(); await runDevicesRejectCommand(requestId, opts); }), ); @@ -96,7 +104,7 @@ export function registerDevicesCli(program: Command) { .requiredOption("--role ", "Role name") .option("--scope ", "Scopes to attach to the token (repeatable)") .action(async (opts: DevicesRpcOpts) => { - const { runDevicesRotateCommand } = await import("./devices-cli.runtime.js"); + const { runDevicesRotateCommand } = await loadDevicesRuntime(); await runDevicesRotateCommand(opts); }), ); @@ -108,7 +116,7 @@ export function registerDevicesCli(program: Command) { .requiredOption("--device ", "Device id") .requiredOption("--role ", "Role name") .action(async (opts: DevicesRpcOpts) => { - const { runDevicesRevokeCommand } = await import("./devices-cli.runtime.js"); + const { runDevicesRevokeCommand } = await loadDevicesRuntime(); await runDevicesRevokeCommand(opts); }), );