Files
hyperframes/packages/cli/src/renderSetupWorker.ts
T
Miguel Ángel 6cf4b56697 fix(engine): a render on Windows opens no console windows (#6613)
* ci(windows): probe that a render opens no visible window

* ci(windows): the probe names what opened each window

* ci(windows): the probe spawns each binary alone, with and without detached

* ci(windows): the probe logs the processes started during the render

* ci(windows): the probe also spawns Chrome one consoleless hop down

* ci(windows): the probe logs each child started without windowsHide

* ci(windows): the probe logs every child process with its windowsHide and detached

* fix(engine): Chrome keeps the CLI's console on Windows, so a render opens no window

* fix(cli): every child the CLI starts on Windows is hidden unless it opts out

* ci(windows): the probe bisects Chrome's flags and keeps each command's output

* ci(windows): the probe names the Chrome process behind each window

* ci(windows): the probe loads a page in Chrome directly and one hidden hop down

* ci(windows): the probe prints the Chrome main command line and renders with the reporter's flags

* ci(windows): the probe narrows the CLI's Chrome arguments to the ones that open a window

* ci(windows): the probe launches the CLI's Chrome arguments one hidden hop down

* ci(windows): the probe launches Chrome through the engine's browser pool

* ci(windows): the probe varies what the engine passes to Puppeteer

* fix(engine): renders on Windows launch Chrome with a Puppeteer that keeps it attached

* refactor(cli): hideChildConsoles copies its arguments and keeps one comment line
2026-10-28 07:48:40 +00:00

59 lines
1.9 KiB
TypeScript

import "./utils/hideChildConsoles.js";
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;
});
}