mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-14 05:13:47 +00:00
* fix(cli): a Chrome download that stops sending is abandoned, retried, and releases the lock * fix(cli): a stalled Chrome download is aborted at the socket so the process can exit * fix(cli): the Chrome download runs in its own process and is killed when it stalls * test(cli): ignore the expected socket reset in the download stall test on Windows
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { constants, setPriority } from "node:os";
|
|
import { runBrowserInstall } from "./browser/installRun.js";
|
|
import { ensureBrowser, releaseOwnedBrowserInstallLock } from "./browser/manager.js";
|
|
import { lintProject } from "./utils/lintProject.js";
|
|
import { killOrphanedProcesses } from "./utils/orphanCleanup.js";
|
|
import {
|
|
installRenderSetupSignalHandlers,
|
|
renderSetupErrorLine,
|
|
renderSetupResultLine,
|
|
} from "./renderSetupWorkerLifecycle.js";
|
|
|
|
const mode = process.argv[2];
|
|
const input = JSON.parse(process.env.HYPERFRAMES_RENDER_SETUP_INPUT ?? "{}");
|
|
|
|
const disposeSignalHandlers = installRenderSetupSignalHandlers(
|
|
process,
|
|
releaseOwnedBrowserInstallLock,
|
|
(signal) => process.kill(process.pid, signal),
|
|
process.env.HYPERFRAMES_RENDER_DETACHED !== "1",
|
|
);
|
|
|
|
function lowerPriority(): void {
|
|
try {
|
|
setPriority(constants.priority.PRIORITY_LOW);
|
|
} catch (error) {
|
|
process.stderr.write(`Lint runs at normal priority: ${(error as Error).message}\n`);
|
|
}
|
|
}
|
|
|
|
async function runMode(): Promise<unknown> {
|
|
if (mode === "browser") return ensureBrowser(input);
|
|
if (mode === "browser-install") return runBrowserInstall(input);
|
|
if (mode === "lint") {
|
|
// Nobody waits on a background lint the way they wait on a Studio boot, so it takes idle CPU only.
|
|
lowerPriority();
|
|
return lintProject(
|
|
input.projectDir,
|
|
input.entryFile,
|
|
input.host ? { host: input.host } : undefined,
|
|
);
|
|
}
|
|
if (mode === "orphan-cleanup") {
|
|
const killed = killOrphanedProcesses();
|
|
if (killed > 0) await new Promise((resolve) => setTimeout(resolve, 600));
|
|
return killed;
|
|
}
|
|
throw new Error(`Unknown render setup mode: ${mode}`);
|
|
}
|
|
|
|
try {
|
|
const result = await runMode().finally(disposeSignalHandlers);
|
|
process.stdout.write(renderSetupResultLine(result));
|
|
} catch (error) {
|
|
process.stderr.write(renderSetupErrorLine(error), () => {
|
|
throw error;
|
|
});
|
|
}
|