Files
openidea/perf/lib/bundle.ts
T
l0ng-ai b2d506a929 test(evals): measure Java code intelligence as the user sees it (#2758)
pnpm eval drives the production workbench in Chromium against a release openidea-server and real jdtls, judging each scenario (navigation, usages, implementations, gutter markers, lenses, diagnostics, completion, docs, rename) on time to feedback, first and complete result, and checking results against evals/java/golden/. Supporting changes: data-* hooks in the usages popup, hints and rows; a shared in-page Tauri shim for smoke tests and evals; a shared perf bundle builder; language-server versions in .github/tool-versions.env shared with Language smoke; the eval agent skill.
2026-11-12 12:17:07 +08:00

48 lines
1.8 KiB
TypeScript

/** The workbench's `--mode perf` production bundle: building it and serving it to Chromium. */
import { spawnSync } from "node:child_process";
import { createReadStream, existsSync, statSync } from "node:fs";
import { createServer, type Server } from "node:http";
import { extname, join } from "node:path";
export function buildBundle(root: string, outDir: string, flags: string[] = []) {
console.log("Building the workbench (vite build --mode perf)…");
const r = spawnSync(
"pnpm",
["exec", "vite", "build", "--mode", "perf", ...flags, "--outDir", outDir, "--emptyOutDir"],
{
cwd: root,
stdio: ["ignore", "ignore", "inherit"],
shell: process.platform === "win32",
},
);
if (r.status !== 0) throw new Error("vite build failed");
}
const MIME: Record<string, string> = {
".html": "text/html",
".js": "text/javascript",
".css": "text/css",
".json": "application/json",
".svg": "image/svg+xml",
".png": "image/png",
".woff2": "font/woff2",
".wasm": "application/wasm",
};
/** Serves `dir` on a free local port (unknown paths: `index.html`). */
export function serveBundle(dir: string): Promise<{ server: Server; url: string }> {
const server = createServer((req, res) => {
const path = decodeURIComponent(new URL(req.url ?? "/", "http://x").pathname);
let file = join(dir, path);
if (!file.startsWith(dir) || !existsSync(file) || statSync(file).isDirectory()) file = join(dir, "index.html");
res.writeHead(200, { "content-type": MIME[extname(file)] ?? "application/octet-stream" });
createReadStream(file).pipe(res);
});
return new Promise((ok) =>
server.listen(0, "127.0.0.1", () => {
const addr = server.address();
ok({ server, url: `http://127.0.0.1:${typeof addr === "object" && addr ? addr.port : 0}` });
}),
);
}