mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(studio-server): an inserted scene names its file from the project root, as the renderer reads it (#8150)
* fix(studio-server): an inserted scene names its file from the project root, as the renderer reads it * test(studio-server): keep a test comment under the line limit
This commit is contained in:
@@ -167,6 +167,50 @@ describe("insertCompositionIntoSource", () => {
|
||||
expect(result.html).toContain('data-duration="5.9"');
|
||||
});
|
||||
|
||||
// fails without the fix: inserting into an open scene wrote the path from that scene's folder ("b.html"), which the
|
||||
// renderer and the preview read from the project root, so the export said the scene was missing.
|
||||
it("names the source from the project root when inserting into a scene in a folder", () => {
|
||||
const dir = project();
|
||||
const scene = `<template><div data-composition-id="a" data-width="1920" data-height="1080" data-duration="2"></div></template>`;
|
||||
mkdirSync(join(dir, "compositions"));
|
||||
mkdirSync(join(dir, "scenes"));
|
||||
writeFileSync(join(dir, "compositions/a.html"), scene);
|
||||
writeFileSync(join(dir, "compositions/b.html"), child);
|
||||
writeFileSync(join(dir, "scenes/c.html"), child.replace('"headline"', '"other"'));
|
||||
const insert = (sourcePath: string) =>
|
||||
insertCompositionIntoSource({
|
||||
projectDir: dir,
|
||||
targetPath: "compositions/a.html",
|
||||
sourcePath,
|
||||
parentSource: scene,
|
||||
start: 0,
|
||||
desiredTrack: 0,
|
||||
}).html;
|
||||
|
||||
expect(insert("compositions/b.html")).toContain('data-composition-src="compositions/b.html"');
|
||||
expect(insert("scenes/c.html")).toContain('data-composition-src="scenes/c.html"');
|
||||
});
|
||||
|
||||
// fails without the fix: a source naming its own scene from the root was refused as missing.
|
||||
it("follows a source's own scenes from the project root", () => {
|
||||
const dir = project();
|
||||
writeFixture(dir);
|
||||
mkdirSync(join(dir, "compositions"));
|
||||
const nested = `<template><div data-composition-id="wrap" data-width="1920" data-height="1080" data-duration="3"><div data-composition-src="compositions/inner.html"></div></div></template>`;
|
||||
writeFileSync(join(dir, "compositions/wrap.html"), nested);
|
||||
writeFileSync(join(dir, "compositions/inner.html"), child);
|
||||
|
||||
const result = insertCompositionIntoSource({
|
||||
projectDir: dir,
|
||||
targetPath: "index.html",
|
||||
sourcePath: "compositions/wrap.html",
|
||||
parentSource: parent,
|
||||
start: 0,
|
||||
desiredTrack: 0,
|
||||
});
|
||||
expect(result.html).toContain('data-composition-src="compositions/wrap.html"');
|
||||
});
|
||||
|
||||
it("rejects self-nesting, transitive cycles, missing files, and invalid durations", () => {
|
||||
const dir = project();
|
||||
writeFixture(dir);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import { readProjectFile } from "@hyperframes/parsers/asset-resolution";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { dirname, relative, resolve, sep } from "node:path";
|
||||
import { relative, sep } from "node:path";
|
||||
import { parseHTML } from "linkedom";
|
||||
import { ProjectRootMissingError } from "@hyperframes/core";
|
||||
import { folderGone, isSafePath, realpath, resolveWithinProject } from "./safePath.js";
|
||||
@@ -75,14 +75,6 @@ function canonicalProjectFile(projectDir: string, sourcePath: string): string {
|
||||
return canonicalProjectPath(projectDir, resolveWithinProject(projectDir, sourcePath));
|
||||
}
|
||||
|
||||
function canonicalDependency(projectDir: string, ownerAbs: string, sourcePath: string): string {
|
||||
validateSourcePath(sourcePath);
|
||||
return canonicalProjectPath(
|
||||
projectDir,
|
||||
resolveWithinProject(projectDir, relative(projectDir, resolve(dirname(ownerAbs), sourcePath))),
|
||||
);
|
||||
}
|
||||
|
||||
function validateDependencyGraph(projectDir: string, targetAbs: string, sourceAbs: string): void {
|
||||
const visited = new Set<string>();
|
||||
const visiting = new Set<string>();
|
||||
@@ -100,7 +92,7 @@ function validateDependencyGraph(projectDir: string, targetAbs: string, sourceAb
|
||||
for (const host of descendants(document, "[data-composition-src]")) {
|
||||
const dependency = host.getAttribute("data-composition-src");
|
||||
if (dependency) {
|
||||
visit(canonicalDependency(projectDir, file, dependency));
|
||||
visit(canonicalProjectFile(projectDir, dependency));
|
||||
}
|
||||
}
|
||||
visiting.delete(file);
|
||||
@@ -165,8 +157,8 @@ function uniqueHostId(root: Element, base: string): string {
|
||||
return `${base}_${suffix}`;
|
||||
}
|
||||
|
||||
function relativeSourcePath(targetAbs: string, sourceAbs: string): string {
|
||||
return relative(dirname(targetAbs), sourceAbs).split(sep).join("/");
|
||||
function rootSourcePath(projectDir: string, sourceAbs: string): string {
|
||||
return relative(realpath(projectDir), sourceAbs).split(sep).join("/");
|
||||
}
|
||||
|
||||
export function insertCompositionIntoSource(input: {
|
||||
@@ -219,7 +211,7 @@ export function insertCompositionIntoSource(input: {
|
||||
host.setAttribute("data-hf-id", `hf-${randomUUID()}`);
|
||||
const mountedRootId = sourceCompositionId || hostId;
|
||||
host.setAttribute("data-composition-id", mountedRootId);
|
||||
host.setAttribute("data-composition-src", relativeSourcePath(targetAbs, sourceAbs));
|
||||
host.setAttribute("data-composition-src", rootSourcePath(input.projectDir, sourceAbs));
|
||||
host.setAttribute("data-start", String(Math.round(input.start * 100) / 100));
|
||||
host.setAttribute("data-duration", String(duration));
|
||||
host.setAttribute("data-playback-start", "0");
|
||||
|
||||
Reference in New Issue
Block a user