From ce4bcc47c0ab3ac6487ae530ea5f1f775ebeafe6 Mon Sep 17 00:00:00 2001 From: ukimsanov Date: Tue, 28 Apr 2026 14:36:34 -0400 Subject: [PATCH] fix(cli): use multi-strategy runtime resolver for snapshot Use loadRuntimeSource() from runtimeSource.ts instead of a single hardcoded path. Tries: build from source (dev), inlined constant (production), pre-built artifact (fallback). Fixes snapshot in dev mode where __dirname is src/commands/ not dist/. Co-Authored-By: Claude Opus 4.7 (1M context) --- packages/cli/src/commands/snapshot.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/commands/snapshot.ts b/packages/cli/src/commands/snapshot.ts index a018835ee..fb323eb85 100644 --- a/packages/cli/src/commands/snapshot.ts +++ b/packages/cli/src/commands/snapshot.ts @@ -2,15 +2,11 @@ import { spawn } from "node:child_process"; import { defineCommand } from "citty"; import { existsSync, mkdtempSync, readFileSync, mkdirSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; -import { resolve, join, dirname, relative, isAbsolute } from "node:path"; -import { fileURLToPath } from "node:url"; +import { resolve, join, relative, isAbsolute } from "node:path"; import { resolveProject } from "../utils/project.js"; import { c } from "../ui/colors.js"; import type { Example } from "./_examples.js"; -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); - /** Maximum time a single-frame FFmpeg extract is allowed to run. Mirrors the * default applied by `@hyperframes/engine`'s `runFfmpeg` so a pathological * clip (corrupt media, stalled network mount, codec edge case) cannot wedge @@ -103,12 +99,11 @@ async function captureSnapshots( let html = await bundleToSingleHtml(projectDir); // Inject local runtime if available. - // The runtime IIFE is copied into the CLI dist during build (build:runtime), - // so it lives alongside cli.js. The old ../../../core/dist/ path only worked - // in the monorepo dev layout and broke for published/npx installs. - const runtimePath = resolve(__dirname, "hyperframe.runtime.iife.js"); - if (existsSync(runtimePath)) { - const runtimeSource = readFileSync(runtimePath, "utf-8"); + // Uses the same multi-strategy resolver as the studio preview server + // (runtimeSource.ts) so snapshot works in dev (tsx), built CLI, and npx. + const { loadRuntimeSource } = await import("../server/runtimeSource.js"); + const runtimeSource = await loadRuntimeSource(); + if (runtimeSource) { html = html.replace( /]*data-hyperframes-preview-runtime[^>]*src="[^"]*"[^>]*><\/script>/, () => ``,