// Fails if the page or any module reaches the network: no imports, scripts, styles or fetches // from http(s):// or protocol-relative URLs. three.js lives in vendor/three/, not on a CDN. import { readFileSync, readdirSync, statSync } from "node:fs"; import { join } from "node:path"; function files(dir) { return readdirSync(dir).flatMap((name) => { const path = join(dir, name); return statSync(path).isDirectory() ? files(path) : [path]; }); } const checked = ["index.html", "style.css", ...files("src").filter((f) => /\.(m?js|css|html)$/.test(f))]; const remote = /(?:import\s*(?:[^'"]*from\s*)?|import\(|src=|href=|url\(|fetch\()\s*['"]?((?:https?:)?\/\/[^'")\s]+)/g; const problems = []; for (const file of checked) { const text = readFileSync(file, "utf8"); for (const m of text.matchAll(remote)) problems.push(`${file}: ${m[1]}`); } if (problems.length) { console.error("Loads from the network (vendor it instead):\n" + problems.join("\n")); process.exit(1); } console.log(`self-contained: ${checked.length} files, no remote loads`);