import { readFileSync, readdirSync, statSync } from "node:fs"; import { fileURLToPath } from "node:url"; import path from "node:path"; import { describe, expect, it } from "vitest"; const SOURCE_EXTENSIONS = new Set([".ts", ".vue"]); // Workspace sources that ship in the WebView bundle. Named capture groups // (`(?…)`) are fine — Safari 10.1+ supports them; lookbehind // (`(?<=…)` / `(? collectSourceFiles(path.join(workspaceRoot, relativeRoot))); // The runtime feature probe in legacyWebView.ts constructs its lookbehind // from a string inside try/catch (module still parses on old WebKit; the // engine that throws is the one being detected), so it is the sole allowed // exception. const LOOKBEHIND_ALLOWLIST = new Set(["apps/desktop/src/lib/ui/legacyWebView.ts"]); describe("WebView startup sources stay compatible with old WebKit regex syntax", () => { it("ships no lookbehind assertions in bundled sources", () => { expect(bundledSources.length).toBeGreaterThan(1000); const offenders = bundledSources .filter((file) => { const source = readFileSync(file, "utf8"); return source.includes("(?<=") || source.includes("(? path.relative(workspaceRoot, file)) .filter((relative) => !LOOKBEHIND_ALLOWLIST.has(relative)); expect(offenders).toEqual([]); }); });