MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / buildFrontend

Function buildFrontend

scripts/static-build.mjs:14–75  ·  view source on GitHub ↗
(config, args = {})

Source from the content-addressed store, hash-verified

12import { buildNpmScriptCommand } from "./dev-safe.mjs";
13
14export function buildFrontend(config, args = {}) {
15 const buildDir = join(config.canvasPath, "build");
16
17 if (args.skipBuild) {
18 if (!existsSync(buildDir)) {
19 logError(
20 "--skip-build was passed but build/ does not exist. Run without --skip-build first.",
21 );
22 process.exit(1);
23 }
24 logStep("build", "Skipping frontend build (--skip-build)");
25 logService("build", `Reusing existing build/ at ${buildDir}`, c.dim);
26 logService(
27 "build",
28 "Source edits will NOT appear until you run without --skip-build (or `npm run build`).",
29 c.yellow,
30 );
31 return;
32 }
33
34 logStep("build", "Building frontend (npm run build:app)...");
35 logService(
36 "build",
37 "This typically takes 30-60s; cached as build/ for --skip-build reuse",
38 c.dim,
39 );
40
41 const cmd = buildNpmScriptCommand("build:app");
42 const buildEnv = {
43 ...process.env,
44 // Bake the session API key — used by the frontend for both agent-server
45 // and automation auth via the `X-Session-API-Key` header.
46 VITE_SESSION_API_KEY: config.sessionApiKey,
47 // Intentionally do NOT set VITE_BACKEND_BASE_URL: leaving it unset makes
48 // the runtime fall back to window.location.origin, which keeps the build
49 // portable across localhost, LAN hosts, and tunnels such as ngrok.
50 };
51 if (config.viteWorkingDir) {
52 buildEnv.VITE_WORKING_DIR = config.viteWorkingDir;
53 }
54
55 const result = spawnSync(cmd.command, cmd.args, {
56 cwd: config.canvasPath,
57 stdio: "inherit",
58 env: buildEnv,
59 });
60
61 if (result.status !== 0) {
62 logError(`Build failed with exit code ${result.status ?? "null"}`);
63 process.exit(result.status ?? 1);
64 }
65
66 if (!existsSync(join(buildDir, "index.html"))) {
67 logError(
68 `Build completed but ${join(buildDir, "index.html")} is missing. ` +
69 "Did react-router build write somewhere unexpected?",
70 );
71 process.exit(1);

Callers 1

mainFunction · 0.90

Calls 5

logErrorFunction · 0.90
logStepFunction · 0.90
logServiceFunction · 0.90
buildNpmScriptCommandFunction · 0.90
logSuccessFunction · 0.90

Tested by

no test coverage detected