mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-08 19:06:04 +00:00
Extends the studio-preview fix to the render path and the asset-discovery utilities, which share the same resolver and had the same defect. `rewriteAssetPath` takes an optional `assetExists` probe. A plain relative ref authored in a sub-composition (`_shared.css`, `clip.mp4`) is re-pointed at the composition's own directory when that sibling exists on disk; project-root refs with no sibling (the registry's `assets/logo.png` convention) stay as authored. Callers that can see the filesystem supply the probe, so the module stays free of node:fs. Also fixes a second defect in the inliner: `<head>` <link> hrefs and external script srcs are hoisted into the root document but never went through the rewrite at all, so even the documented `../` form escaped the project and 404'd at render time. Wired into the preview bundler, the producer compiler, the studio preview builder, the HEVC preview lint, the project lint's asset scans, publish proxy baking, and media-treatment source resolution.
53 lines
2.1 KiB
TypeScript
53 lines
2.1 KiB
TypeScript
import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { collectLocalVideoCandidates } from "./hevcPreviewLint.js";
|
|
|
|
function makeProject(files: string[]): string {
|
|
const dir = mkdtempSync(join(tmpdir(), "hf-hevc-lint-"));
|
|
for (const rel of files) {
|
|
const full = join(dir, rel);
|
|
mkdirSync(join(full, ".."), { recursive: true });
|
|
writeFileSync(full, "video-bytes", "utf-8");
|
|
}
|
|
return dir;
|
|
}
|
|
|
|
// A sub-composition referencing a SIBLING video (`clip.mp4` next to it) resolves
|
|
// against its own directory, exactly as the preview and render paths now do.
|
|
// Resolving it against the project root instead either finds nothing (the file
|
|
// is silently skipped, so a real HEVC source is never reported) or finds a
|
|
// same-named file at the root and probes the WRONG one.
|
|
describe("collectLocalVideoCandidates", () => {
|
|
it("resolves a sibling video against the sub-composition dir", () => {
|
|
const dir = makeProject(["design/styleframes/clip.mp4"]);
|
|
|
|
const candidates = collectLocalVideoCandidates(dir, [
|
|
{ html: `<video src="clip.mp4"></video>`, compSrcPath: "design/styleframes/frame-01.html" },
|
|
]);
|
|
|
|
expect([...candidates.keys()]).toEqual([join(dir, "design/styleframes/clip.mp4")]);
|
|
});
|
|
|
|
it("prefers the sibling over a same-named file at the project root", () => {
|
|
const dir = makeProject(["clip.mp4", "design/styleframes/clip.mp4"]);
|
|
|
|
const candidates = collectLocalVideoCandidates(dir, [
|
|
{ html: `<video src="clip.mp4"></video>`, compSrcPath: "design/styleframes/frame-01.html" },
|
|
]);
|
|
|
|
expect([...candidates.keys()]).toEqual([join(dir, "design/styleframes/clip.mp4")]);
|
|
});
|
|
|
|
it("still resolves project-root refs that have no sibling", () => {
|
|
const dir = makeProject(["assets/clip.mp4"]);
|
|
|
|
const candidates = collectLocalVideoCandidates(dir, [
|
|
{ html: `<video src="assets/clip.mp4"></video>`, compSrcPath: "blocks/hero.html" },
|
|
]);
|
|
|
|
expect([...candidates.keys()]).toEqual([join(dir, "assets/clip.mp4")]);
|
|
});
|
|
});
|