Files
hyperframes/packages/cli/src/browser/installProtocol.ts
T
Miguel Ángel fcec26ed5f fix(cli): a Chrome download that stops sending is abandoned, retried, and releases the lock (#6222)
* 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
2026-10-24 17:53:54 +00:00

33 lines
1.0 KiB
TypeScript

const PROGRESS_PREFIX = "HYPERFRAMES_BROWSER_INSTALL_PROGRESS:";
const LOG_PREFIX = "HYPERFRAMES_BROWSER_INSTALL_LOG:";
export type InstallEvent =
| { kind: "progress"; downloaded: number; total: number }
| { kind: "log"; text: string };
export function installProgressLine(downloaded: number, total: number): string {
return `${PROGRESS_PREFIX}${JSON.stringify([downloaded, total])}\n`;
}
export function installLogLine(text: string): string {
return `${LOG_PREFIX}${JSON.stringify(text)}\n`;
}
export function parseInstallLine(line: string): InstallEvent | null {
try {
if (line.startsWith(PROGRESS_PREFIX)) {
const [downloaded, total] = JSON.parse(line.slice(PROGRESS_PREFIX.length)) as [
number,
number,
];
return { kind: "progress", downloaded, total };
}
if (line.startsWith(LOG_PREFIX)) {
return { kind: "log", text: JSON.parse(line.slice(LOG_PREFIX.length)) as string };
}
} catch {
// a torn line is dropped: the next progress line carries the same information
}
return null;
}