mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(core): the bundle's contract check reads a timeline registered in a local script (#7248)
* fix(core): the bundle's contract check reads a timeline registered in a local script * fix(lint): collectExternalStyles is internal now that linkedSources is the export
This commit is contained in:
@@ -2679,6 +2679,27 @@ describe("bundleToSingleHtml", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("reads a timeline registered by a local script, as hyperframes lint does", async () => {
|
||||
const dir = makeTempProject({
|
||||
"index.html": `<!doctype html><html><head></head><body>
|
||||
<div id="root" data-composition-id="root" data-width="320" data-height="180" data-duration="1"></div>
|
||||
<script src="timeline.js"></script>
|
||||
</body></html>`,
|
||||
"timeline.js": `window.__timelines = window.__timelines || {};
|
||||
window.__timelines.root = { duration: () => 1, seek() {}, pause() {} };`,
|
||||
});
|
||||
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
try {
|
||||
await bundleToSingleHtml(dir);
|
||||
const guard = warnSpy.mock.calls
|
||||
.map((call) => String(call[0] ?? ""))
|
||||
.filter((line) => line.includes("[StaticGuard]"));
|
||||
expect(guard).toEqual([]);
|
||||
} finally {
|
||||
warnSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("runs the StaticGuard lint unless staticGuard is false", async () => {
|
||||
const dir = makeTempProject({
|
||||
"index.html": `<!doctype html><html><head></head><body>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { collectExternalStyles, lintHyperframeHtml } from "@hyperframes/lint";
|
||||
import { linkedSources, lintHyperframeHtml } from "@hyperframes/lint";
|
||||
|
||||
export type HyperframeStaticFailureReason =
|
||||
| "missing_composition_id"
|
||||
@@ -19,9 +19,7 @@ export async function validateHyperframeHtmlContract(
|
||||
): Promise<HyperframeStaticGuardResult> {
|
||||
const result = await lintHyperframeHtml(
|
||||
html,
|
||||
project && {
|
||||
externalStyles: collectExternalStyles(project.dir, html, project.compSrcPath),
|
||||
},
|
||||
project && linkedSources(project.dir, html, project.compSrcPath),
|
||||
);
|
||||
const missingKeys = result.findings
|
||||
.filter((finding) => finding.severity === "error")
|
||||
|
||||
@@ -11,7 +11,7 @@ export {
|
||||
LINT_RULE_COUNT,
|
||||
LINT_RULE_GROUP_COUNTS,
|
||||
} from "./hyperframeLinter.js";
|
||||
export { collectExternalStyles, lintProject, shouldBlockRender } from "./project.js";
|
||||
export { linkedSources, lintProject, shouldBlockRender } from "./project.js";
|
||||
export type { ProjectLintResult } from "./project.js";
|
||||
export { projectIgnore } from "./projectIgnore.js";
|
||||
export { audioAttributeShapeError, type AudioAttribute } from "./rules/audioAttributes.js";
|
||||
|
||||
@@ -140,7 +140,7 @@ function collectLocalStylesheets(
|
||||
return styles;
|
||||
}
|
||||
|
||||
export function collectExternalStyles(
|
||||
function collectExternalStyles(
|
||||
projectDir: string,
|
||||
html: string,
|
||||
compSrcPath?: string,
|
||||
@@ -159,6 +159,17 @@ export function collectExternalStyles(
|
||||
|
||||
const MAX_EXTERNAL_SCRIPT_BYTES = 1_000_000;
|
||||
|
||||
export function linkedSources(
|
||||
projectDir: string,
|
||||
html: string,
|
||||
compSrcPath?: string,
|
||||
): Pick<HyperframeLinterOptions, "externalStyles" | "externalScripts"> {
|
||||
return {
|
||||
externalStyles: collectExternalStyles(projectDir, html, compSrcPath),
|
||||
externalScripts: collectExternalScripts(projectDir, html, compSrcPath),
|
||||
};
|
||||
}
|
||||
|
||||
function collectExternalScripts(
|
||||
projectDir: string,
|
||||
html: string,
|
||||
@@ -304,9 +315,8 @@ export async function lintProject(
|
||||
...hostOptions,
|
||||
filePath: indexPath,
|
||||
compSrcPath: rootFile,
|
||||
externalStyles: collectExternalStyles(projectDir, rootHtml, rootCompSrcPath),
|
||||
...linkedSources(projectDir, rootHtml, rootCompSrcPath),
|
||||
projectFontFamilies,
|
||||
externalScripts: collectExternalScripts(projectDir, rootHtml, rootCompSrcPath),
|
||||
});
|
||||
results.push({ file: rootFile, result: rootResult, contentHash: contentDigest(rootHtml) });
|
||||
totalErrors += rootResult.errorCount;
|
||||
@@ -350,9 +360,8 @@ export async function lintProject(
|
||||
filePath,
|
||||
isSubComposition: true,
|
||||
compSrcPath,
|
||||
externalStyles: collectExternalStyles(projectDir, html, compSrcPath),
|
||||
...linkedSources(projectDir, html, compSrcPath),
|
||||
projectFontFamilies,
|
||||
externalScripts: collectExternalScripts(projectDir, html, compSrcPath),
|
||||
});
|
||||
results.push({
|
||||
file: `compositions/${file}`,
|
||||
|
||||
Reference in New Issue
Block a user