mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
perf(plugins): parallelize boundary artifact prep
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { spawnSync } from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
import { createRequire } from "node:module";
|
import { createRequire } from "node:module";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
|
|
||||||
@@ -7,34 +7,81 @@ const repoRoot = resolve(import.meta.dirname, "..");
|
|||||||
const tscBin = require.resolve("typescript/bin/tsc");
|
const tscBin = require.resolve("typescript/bin/tsc");
|
||||||
|
|
||||||
function runNodeStep(label, args, timeoutMs) {
|
function runNodeStep(label, args, timeoutMs) {
|
||||||
const result = spawnSync(process.execPath, args, {
|
return new Promise((resolvePromise, rejectPromise) => {
|
||||||
cwd: repoRoot,
|
const child = spawn(process.execPath, args, {
|
||||||
encoding: "utf8",
|
cwd: repoRoot,
|
||||||
maxBuffer: 16 * 1024 * 1024,
|
env: process.env,
|
||||||
timeout: timeoutMs,
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
|
});
|
||||||
|
|
||||||
|
let stdout = "";
|
||||||
|
let stderr = "";
|
||||||
|
let settled = false;
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
if (settled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
child.kill("SIGTERM");
|
||||||
|
settled = true;
|
||||||
|
rejectPromise(
|
||||||
|
new Error(`${label}\n${stdout}${stderr}\n${label} timed out after ${timeoutMs}ms`.trim()),
|
||||||
|
);
|
||||||
|
}, timeoutMs);
|
||||||
|
|
||||||
|
child.stdout.setEncoding("utf8");
|
||||||
|
child.stderr.setEncoding("utf8");
|
||||||
|
child.stdout.on("data", (chunk) => {
|
||||||
|
stdout += chunk;
|
||||||
|
});
|
||||||
|
child.stderr.on("data", (chunk) => {
|
||||||
|
stderr += chunk;
|
||||||
|
});
|
||||||
|
child.on("error", (error) => {
|
||||||
|
if (settled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(timer);
|
||||||
|
settled = true;
|
||||||
|
rejectPromise(new Error(`${label}\n${stdout}${stderr}\n${error.message}`.trim()));
|
||||||
|
});
|
||||||
|
child.on("close", (code) => {
|
||||||
|
if (settled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(timer);
|
||||||
|
settled = true;
|
||||||
|
if (code === 0) {
|
||||||
|
resolvePromise();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rejectPromise(new Error(`${label}\n${stdout}${stderr}`.trim()));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.status === 0 && !result.error) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeoutSuffix =
|
|
||||||
result.error?.name === "Error" && result.error.message.includes("ETIMEDOUT")
|
|
||||||
? `\n${label} timed out after ${timeoutMs}ms`
|
|
||||||
: "";
|
|
||||||
const errorSuffix = result.error ? `\n${result.error.message}` : "";
|
|
||||||
process.stderr.write(`${label}\n${result.stdout}${result.stderr}${timeoutSuffix}${errorSuffix}`);
|
|
||||||
process.exit(result.status ?? 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runNodeStep("plugin-sdk boundary dts", [tscBin, "-p", "tsconfig.plugin-sdk.dts.json"], 300_000);
|
async function main() {
|
||||||
runNodeStep(
|
try {
|
||||||
"plugin-sdk package boundary dts",
|
await Promise.all([
|
||||||
[tscBin, "-p", "packages/plugin-sdk/tsconfig.json"],
|
runNodeStep(
|
||||||
300_000,
|
"plugin-sdk boundary dts",
|
||||||
);
|
[tscBin, "-p", "tsconfig.plugin-sdk.dts.json"],
|
||||||
runNodeStep(
|
300_000,
|
||||||
"plugin-sdk boundary root shims",
|
),
|
||||||
["--import", "tsx", resolve(repoRoot, "scripts/write-plugin-sdk-entry-dts.ts")],
|
runNodeStep(
|
||||||
120_000,
|
"plugin-sdk package boundary dts",
|
||||||
);
|
[tscBin, "-p", "packages/plugin-sdk/tsconfig.json"],
|
||||||
|
300_000,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
await runNodeStep(
|
||||||
|
"plugin-sdk boundary root shims",
|
||||||
|
["--import", "tsx", resolve(repoRoot, "scripts/write-plugin-sdk-entry-dts.ts")],
|
||||||
|
120_000,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await main();
|
||||||
|
|||||||
Reference in New Issue
Block a user