From 0b355982460e0ca66b6f762da7732d4990c6ddc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Thu, 5 Nov 2026 15:48:10 +0000 Subject: [PATCH] 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 --- .../core/src/compiler/htmlBundler.test.ts | 21 +++++++++++++++++++ packages/core/src/compiler/staticGuard.ts | 6 ++---- packages/lint/src/index.ts | 2 +- packages/lint/src/project.ts | 19 ++++++++++++----- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/core/src/compiler/htmlBundler.test.ts b/packages/core/src/compiler/htmlBundler.test.ts index 2d0005ad58..7011c39482 100644 --- a/packages/core/src/compiler/htmlBundler.test.ts +++ b/packages/core/src/compiler/htmlBundler.test.ts @@ -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": ` +
+ +`, + "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": ` diff --git a/packages/core/src/compiler/staticGuard.ts b/packages/core/src/compiler/staticGuard.ts index d13be15214..42c0e0c5d1 100644 --- a/packages/core/src/compiler/staticGuard.ts +++ b/packages/core/src/compiler/staticGuard.ts @@ -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 { 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") diff --git a/packages/lint/src/index.ts b/packages/lint/src/index.ts index a862a6e8ee..7752ca4334 100644 --- a/packages/lint/src/index.ts +++ b/packages/lint/src/index.ts @@ -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"; diff --git a/packages/lint/src/project.ts b/packages/lint/src/project.ts index efa00370b2..d1c57a339b 100644 --- a/packages/lint/src/project.ts +++ b/packages/lint/src/project.ts @@ -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 { + 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}`,