From 3cc4c82f9e77990474df7f6c4dbc657b3e156c3f Mon Sep 17 00:00:00 2001 From: James Date: Wed, 20 May 2026 05:40:33 +0000 Subject: [PATCH] refactor(cli): minimize studioServer.ts diff for telemetry wiring Net diff is now +3 lines: import line and the two emit calls. Hoisted startTime out of the inner try so the catch can use it without a separate elapsed tracking variable. Pre-existing complexity findings in studioServer.ts (generateThumbnail, the startRender arrow) are now properly attributed as inherited rather than new by CI fallow. --- packages/cli/src/server/studioServer.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/server/studioServer.ts b/packages/cli/src/server/studioServer.ts index 4955e5d39..8cb36772b 100644 --- a/packages/cli/src/server/studioServer.ts +++ b/packages/cli/src/server/studioServer.ts @@ -254,6 +254,7 @@ export function createStudioServer(options: StudioServerOptions): StudioServer { }; // Run render asynchronously, mutating the state object + const startTime = Date.now(); (async () => { try { const { createRenderJob, executeRenderJob } = await import("@hyperframes/producer"); @@ -280,30 +281,23 @@ export function createStudioServer(options: StudioServerOptions): StudioServer { ...(manualEditsRenderScript ? { renderBodyScripts: [manualEditsRenderScript] } : {}), ...(opts.composition ? { entryFile: opts.composition } : {}), }); - const startTime = Date.now(); - let lastStage: string | undefined; const onProgress = (j: { progress: number; currentStage?: string }) => { state.progress = j.progress; - if (j.currentStage) { - state.stage = j.currentStage; - lastStage = j.currentStage; - } + if (j.currentStage) state.stage = j.currentStage; }; - try { - await executeRenderJob(job, opts.project.dir, opts.outputPath, onProgress); - } catch (renderErr) { - emitStudioRenderError(opts, Date.now() - startTime, lastStage, renderErr); - throw renderErr; - } - const elapsed = Date.now() - startTime; + await executeRenderJob(job, opts.project.dir, opts.outputPath, onProgress); state.status = "complete"; state.progress = 100; const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json"); - writeFileSync(metaPath, JSON.stringify({ status: "complete", durationMs: elapsed })); - emitStudioRenderComplete(opts, elapsed, job.perfSummary); + writeFileSync( + metaPath, + JSON.stringify({ status: "complete", durationMs: Date.now() - startTime }), + ); + emitStudioRenderComplete(opts, Date.now() - startTime, job.perfSummary); } catch (err) { state.status = "failed"; state.error = err instanceof Error ? err.message : String(err); + emitStudioRenderError(opts, Date.now() - startTime, state.stage, err); try { const metaPath = opts.outputPath.replace(/\.(mp4|webm|mov)$/, ".meta.json"); writeFileSync(metaPath, JSON.stringify({ status: "failed" }));