mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 07:42:17 +00:00
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import path from "node:path";
|
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
import { spawnPnpmRunner } from "../pnpm-runner.mjs";
|
|
import {
|
|
installVitestProcessGroupCleanup,
|
|
shouldUseDetachedVitestProcessGroup,
|
|
} from "../vitest-process-group.mjs";
|
|
|
|
const scriptFile = fileURLToPath(import.meta.url);
|
|
const scriptDir = path.dirname(scriptFile);
|
|
const repoRoot = path.resolve(scriptDir, "../..");
|
|
|
|
export async function runVitestBatch(params) {
|
|
return await new Promise((resolve, reject) => {
|
|
const child = spawnPnpmRunner({
|
|
cwd: repoRoot,
|
|
detached: shouldUseDetachedVitestProcessGroup(),
|
|
env: params.env,
|
|
pnpmArgs: [
|
|
"exec",
|
|
"vitest",
|
|
"run",
|
|
"--config",
|
|
params.config,
|
|
...params.targets,
|
|
...params.args,
|
|
],
|
|
stdio: "inherit",
|
|
});
|
|
const teardownChildCleanup = installVitestProcessGroupCleanup({ child });
|
|
|
|
child.on("error", (error) => {
|
|
teardownChildCleanup();
|
|
reject(error);
|
|
});
|
|
child.on("exit", (code, signal) => {
|
|
teardownChildCleanup();
|
|
if (signal) {
|
|
process.kill(process.pid, signal);
|
|
return;
|
|
}
|
|
resolve(code ?? 1);
|
|
});
|
|
});
|
|
}
|
|
|
|
export function isDirectScriptRun(metaUrl) {
|
|
const entryHref = process.argv[1] ? pathToFileURL(path.resolve(process.argv[1])).href : "";
|
|
return metaUrl === entryHref;
|
|
}
|