Skip to content

Write HTML. Render video. Built for agents.

fix(lint): recognize Three.js loaded via ESM URL/path imports (#1805)

Miguel Ángel27a7f37494f9
diff --git a/packages/lint/src/rules/adapters.test.ts b/packages/lint/src/rules/adapters.test.ts
index d28e49abc9..8e4f3ab51d 100644
--- a/packages/lint/src/rules/adapters.test.ts
+++ b/packages/lint/src/rules/adapters.test.ts
@@ -124,6 +124,88 @@ describe("adapter rules", () => {
expect(finding).toBeUndefined();
});
+ it("does not report missing_three_script for an ESM +esm CDN import (jsdelivr)", async () => {
+ const html = `
+<html><body>
+ <div data-composition-id="main" data-width="1920" data-height="1080"></div>
+ <script type="module">
+ import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
+ window.__timelines = window.__timelines || {};
+ window.__timelines["main"] = gsap.timeline({ paused: true });
+ const scene = new THREE.Scene();
+ </script>
+</body></html>`;
+ const result = await lintHyperframeHtml(html);
+ const finding = result.findings.find((f) => f.code === "missing_three_script");
+ expect(finding).toBeUndefined();
+ });
+
+ it("does not report missing_three_script for an esm.sh/three import", async () => {
+ const html = `
+<html><body>
+ <div data-composition-id="main" data-width="1920" data-height="1080"></div>
+ <script type="module">
+ import * as THREE from 'https://esm.sh/three';
+ window.__timelines = window.__timelines || {};
+ window.__timelines["main"] = gsap.timeline({ paused: true });
+ const scene = new THREE.Scene();
+ </script>
+</body></html>`;
+ const result = await lintHyperframeHtml(html);
+ const finding = result.findings.find((f) => f.code === "missing_three_script");
+ expect(finding).toBeUndefined();
+ });
+
+ it("does not report missing_three_script for a local three.module.js import", async () => {
+ const html = `
+<html><body>
+ <div data-composition-id="main" data-width="1920" data-height="1080"></div>
+ <script type="module">
+ import { Scene } from './vendor/three.module.js';
+ window.__timelines = window.__timelines || {};
+ window.__timelines["main"] = gsap.timeline({ paused: true });
+ const scene = new Scene();
+ THREE.foo();
+ </script>
+</body></html>`;
+ const result = await lintHyperframeHtml(html);
+ const finding = result.findings.find((f) => f.code === "missing_three_script");
+ expect(finding).toBeUndefined();
+ });
+
+ it("does not report missing_three_script for a bare 'three' import (regression)", async () => {
+ const html = `
+<html><body>
+ <div data-composition-id="main" data-width="1920" data-height="1080"></div>
+ <script type="module">
+ import * as THREE from 'three';
+ window.__timelines = window.__timelines || {};
+ window.__timelines["main"] = gsap.timeline({ paused: true });
+ const scene = new THREE.Scene();
+ </script>
+</body></html>`;
+ const result = await lintHyperframeHtml(html);
+ const finding = result.findings.find((f) => f.code === "missing_three_script");
+ expect(finding).toBeUndefined();
+ });
+
+ it("still reports missing_three_script when THREE is used with no three loaded", async () => {
+ const html = `
+<html><body>
+ <div data-composition-id="main" data-width="1920" data-height="1080"></div>
+ <script type="module">
+ import { gsap } from 'https://cdn.jsdelivr.net/npm/gsap@3/+esm';
+ window.__timelines = window.__timelines || {};
+ window.__timelines["main"] = gsap.timeline({ paused: true });
+ const scene = new THREE.Scene();
+ </script>
+</body></html>`;
+ const result = await lintHyperframeHtml(html);
+ const finding = result.findings.find((f) => f.code === "missing_three_script");
+ expect(finding).toBeDefined();
+ expect(finding?.severity).toBe("error");
+ });
+
it("does not report any adapter errors for composition with no adapter usage", async () => {
const html = `
<html><body>
diff --git a/packages/lint/src/rules/adapters.ts b/packages/lint/src/rules/adapters.ts
index 2a9b05bc28..4de4b330b4 100644
--- a/packages/lint/src/rules/adapters.ts
+++ b/packages/lint/src/rules/adapters.ts
@@ -36,8 +36,11 @@ export const adapterRules: Array<(ctx: LintContext) => HyperframeLintFinding[]>
/["']three["']/.test(t) &&
/importmap/.test(scripts.find((s) => s.content === t)?.attrs || ""),
);
- const hasThreeModuleImport = texts.some(
- (t) => /\bimport\b.*['"]three['"]/.test(t) || /\bfrom\s+['"]three['"]/.test(t),
+ // Matches any import/from whose specifier contains "three" (bare 'three', or a
+ // URL/path like .../+esm, esm.sh/three, three.module.js), mirroring the loose
+ // /three/i treatment of <script src>.
+ const hasThreeModuleImport = texts.some((t) =>
+ /\b(?:import|from)\s*[^;\n]*['"][^'"]*three[^'"]*['"]/i.test(t),
);
if (!usesThree || hasThreeScript || hasThreeImportMap || hasThreeModuleImport) return [];