mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
perf(cli): start Studio before the startup lint finishes
hyperframes preview linted the whole project before it listened, 4 to 6 s on a large film, and did so in --json mode where the result is discarded. The lint now runs in the CLI worker while Studio starts and prints its summary when done; --json skips it.
This commit is contained in:
@@ -22,6 +22,16 @@ import {
|
||||
waitForStudioChildClose,
|
||||
} from "./preview.js";
|
||||
|
||||
const lint = vi.hoisted(() => ({ inProcess: vi.fn(), worker: vi.fn() }));
|
||||
vi.mock("../utils/lintProject.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../utils/lintProject.js")>()),
|
||||
lintProject: lint.inProcess,
|
||||
}));
|
||||
vi.mock("../utils/cancellableProcess.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../utils/cancellableProcess.js")>()),
|
||||
runRenderSetupWorker: lint.worker,
|
||||
}));
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
@@ -398,6 +408,40 @@ describe("prebuildPreview", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("startup lint", () => {
|
||||
const neverSettles = () => new Promise<never>(() => {});
|
||||
|
||||
it("never lints for a --json start", async () => {
|
||||
lint.inProcess.mockImplementation(neverSettles);
|
||||
lint.worker.mockImplementation(neverSettles);
|
||||
const dir = tempProject();
|
||||
writeFileSync(join(dir, "index.html"), "<html></html>");
|
||||
vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
|
||||
await runCommand(previewCommand, {
|
||||
rawArgs: [dir, "--background", "--json", "--user-data-dir", join(dir, "profile")],
|
||||
});
|
||||
|
||||
expect(lint.inProcess).not.toHaveBeenCalled();
|
||||
expect(lint.worker).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not hold a start behind a lint that has not finished", async () => {
|
||||
lint.inProcess.mockImplementation(neverSettles);
|
||||
lint.worker.mockImplementation(neverSettles);
|
||||
const dir = tempProject();
|
||||
writeFileSync(join(dir, "index.html"), "<html></html>");
|
||||
const error = vi.spyOn(clack.log, "error").mockImplementation(() => {});
|
||||
|
||||
await runCommand(previewCommand, {
|
||||
rawArgs: [dir, "--background", "--user-data-dir", join(dir, "profile")],
|
||||
});
|
||||
|
||||
expect(error).toHaveBeenCalledWith(expect.stringContaining("--user-data-dir"));
|
||||
expect(lint.inProcess).not.toHaveBeenCalled();
|
||||
}, 5_000);
|
||||
});
|
||||
|
||||
describe("foreground preview JSON", () => {
|
||||
it("emits the same ready session contract before remaining attached", () => {
|
||||
const dir = tempProject();
|
||||
|
||||
@@ -48,7 +48,8 @@ import {
|
||||
parseRemoteDebuggingPort,
|
||||
validateRemoteDebuggingPortDeps,
|
||||
} from "../utils/openBrowser.js";
|
||||
import { lintProject } from "../utils/lintProject.js";
|
||||
import type { ProjectLintResult } from "../utils/lintProject.js";
|
||||
import { runRenderSetupWorker } from "../utils/cancellableProcess.js";
|
||||
import { formatLintStartupMessage } from "../utils/lintFormat.js";
|
||||
import {
|
||||
activeServerOnPort,
|
||||
@@ -416,19 +417,6 @@ export default defineCommand({
|
||||
const dir = project.dir;
|
||||
const projectName = isImplicitCwd ? basename(process.env.PWD ?? dir) : project.name;
|
||||
|
||||
// Lint before starting — surface issues for the agent to fix.
|
||||
const lintResult = await lintProject(dir);
|
||||
if (!args.json && (lintResult.totalErrors > 0 || lintResult.totalWarnings > 0)) {
|
||||
console.log();
|
||||
const verbose = Boolean(args["lint-verbose"]);
|
||||
for (const line of formatLintStartupMessage(
|
||||
lintResult,
|
||||
verbose ? { kind: "verbose" } : { kind: "summary", pointer: "studio" },
|
||||
))
|
||||
console.log(line);
|
||||
console.log();
|
||||
}
|
||||
|
||||
// Validation: --user-data-dir requires --browser-path
|
||||
if (args["user-data-dir"] && !args["browser-path"]) {
|
||||
reportPreviewFailure(
|
||||
@@ -492,6 +480,10 @@ export default defineCommand({
|
||||
);
|
||||
}
|
||||
|
||||
// Lint surfaces issues for the agent reading this terminal. It runs in the CLI worker while
|
||||
// Studio starts, so it never delays the Studio opening; --json never reads it.
|
||||
const startupLint = args.json ? null : printStartupLint(dir, Boolean(args["lint-verbose"]));
|
||||
|
||||
const launchMode = previewLaunchMode({
|
||||
background: Boolean(args.background),
|
||||
foreground: Boolean(args.foreground),
|
||||
@@ -555,6 +547,7 @@ export default defineCommand({
|
||||
remoteDebuggingPort,
|
||||
browserNoGpu,
|
||||
});
|
||||
await startupLint;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -605,6 +598,26 @@ export default defineCommand({
|
||||
},
|
||||
});
|
||||
|
||||
async function printStartupLint(dir: string, verbose: boolean): Promise<void> {
|
||||
try {
|
||||
const lintResult = await runRenderSetupWorker<ProjectLintResult>(
|
||||
"lint",
|
||||
{ projectDir: dir },
|
||||
{ maxBufferBytes: 8 * 1024 * 1024 },
|
||||
);
|
||||
if (lintResult.totalErrors === 0 && lintResult.totalWarnings === 0) return;
|
||||
console.log();
|
||||
for (const line of formatLintStartupMessage(
|
||||
lintResult,
|
||||
verbose ? { kind: "verbose" } : { kind: "summary", pointer: "studio" },
|
||||
))
|
||||
console.log(line);
|
||||
console.log();
|
||||
} catch (error) {
|
||||
clack.log.warn(`Lint did not finish: ${errorMessage(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
export type PreviewLaunchMode = "background" | "dev" | "local" | "embedded";
|
||||
|
||||
export function previewLaunchMode(options: {
|
||||
|
||||
Reference in New Issue
Block a user