mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
perf(cli): remove ineffective dynamic imports (#127046)
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
committed by
GitHub
parent
2ecd342fbb
commit
c60a26695d
@@ -0,0 +1,14 @@
|
||||
// Run-main owns these modules eagerly, so lazy imports only add ineffective bundle edges.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const source = readFileSync(new URL("./run-main.ts", import.meta.url), "utf8");
|
||||
|
||||
describe("run-main import boundary", () => {
|
||||
it("does not lazy-import its eager startup owners", () => {
|
||||
for (const specifier of ["../config/paths.js", "./command-startup-policy.js"]) {
|
||||
expect(source).toContain(`from "${specifier}"`);
|
||||
expect(source).not.toContain(`import("${specifier}")`);
|
||||
}
|
||||
});
|
||||
});
|
||||
+5
-9
@@ -6,7 +6,7 @@ import { normalizeOptionalString } from "@openclaw/normalization-core/string-coe
|
||||
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
|
||||
import type { Command as CommanderCommand, Option as CommanderOption } from "commander";
|
||||
import { sanitizeTerminalText } from "../../packages/terminal-core/src/safe-text.js";
|
||||
import { resolveStateDir } from "../config/paths.js";
|
||||
import { resolveGatewayPort, resolveStateDir } from "../config/paths.js";
|
||||
import type { ConfigFileSnapshot, OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { isLoopbackAddress, isSecureWebSocketUrl } from "../gateway/net.js";
|
||||
import { normalizeWebSocketProtocol } from "../gateway/websocket-protocol.js";
|
||||
@@ -172,7 +172,6 @@ async function tryRunGatewayRunFastPath(
|
||||
{ addGatewayRunCommand },
|
||||
{ VERSION },
|
||||
{ emitCliBanner },
|
||||
{ resolveCliStartupPolicy },
|
||||
{ ensureCliExecutionBootstrap },
|
||||
{ defaultRuntime },
|
||||
] = await startupTrace.measure("gateway-run-imports", () =>
|
||||
@@ -181,13 +180,12 @@ async function tryRunGatewayRunFastPath(
|
||||
import("./gateway-cli/run-command.js"),
|
||||
import("../version.js"),
|
||||
import("./banner.js"),
|
||||
import("./command-startup-policy.js"),
|
||||
import("./command-execution-startup.js"),
|
||||
import("../runtime.js"),
|
||||
]),
|
||||
);
|
||||
const commandPath = resolveGatewayCatalogCommandPath(argv) ?? ["gateway"];
|
||||
const startupPolicy = resolveCliStartupPolicy({
|
||||
const startupPolicy = resolveCliStartupPolicyForArgv({
|
||||
argv,
|
||||
commandPath,
|
||||
jsonOutputMode: hasJsonOutputFlag(argv),
|
||||
@@ -633,12 +631,10 @@ async function resolveLocalGatewayProbeTargets(
|
||||
config: OpenClawConfig,
|
||||
): Promise<{ targets: GatewayProbeTarget[]; auth: GatewayProbeAuth }> {
|
||||
const [
|
||||
{ resolveGatewayPort },
|
||||
{ resolveControlUiLinks },
|
||||
{ resolveGatewayClientBootstrap },
|
||||
{ readActiveGatewayLockPort },
|
||||
] = await Promise.all([
|
||||
import("../config/paths.js"),
|
||||
import("../gateway/control-ui-links.js"),
|
||||
import("../gateway/client-bootstrap.js"),
|
||||
import("../infra/gateway-lock.js"),
|
||||
@@ -1617,9 +1613,9 @@ async function runCliWithPreparedOutputMode(
|
||||
});
|
||||
if (!shouldSkipPluginRegistration) {
|
||||
const config = await startupTrace.measure("register-plugin-commands", async () => {
|
||||
const [{ registerPluginCliCommandsFromValidatedConfig }, { resolveCliStartupPolicy }] =
|
||||
await Promise.all([import("../plugins/cli.js"), import("./command-startup-policy.js")]);
|
||||
const startupPolicy = resolveCliStartupPolicy({
|
||||
const { registerPluginCliCommandsFromValidatedConfig } =
|
||||
await import("../plugins/cli.js");
|
||||
const startupPolicy = resolveCliStartupPolicyForArgv({
|
||||
argv: parseArgv,
|
||||
commandPath: invocation.commandPath,
|
||||
jsonOutputMode: suppressStartupProgress,
|
||||
|
||||
Reference in New Issue
Block a user