diff --git a/internal/check-browser-gates-guarded.mjs b/internal/check-browser-gates-guarded.mjs index 02c478bd5..4949d32dc 100644 --- a/internal/check-browser-gates-guarded.mjs +++ b/internal/check-browser-gates-guarded.mjs @@ -22,12 +22,13 @@ if (process.argv.includes('--list')) { console.error(`${names.length} script(s) launch a browser: run each as internal/browser-slot.sh bun run `) process.exit(0) } -// Files that NAME the import pattern in a regex without importing playwright (the guard itself, and the -// detectors that look for it). Listed by path, not skipped by content, so a real import added to one fails. -const DETECTORS = new Set(['internal/lib/playwright-guarded.mjs', 'internal/check-browser-gates-guarded.mjs', 'internal/lib/browser-gates.mjs']) -const DIRECT = /from\s+['"]playwright['"]|import\(\s*['"]playwright['"]\s*\)|require\(\s*['"]playwright['"]\s*\)/ +// A REAL import, not text that names one: a static import statement at the start of a line, or a literal +// import('playwright') / require('playwright') call. The detectors (browser-gates.mjs, this file) spell the +// pattern inside regex literals, escaped, which none of these match, so they need no exclusion and a real +// import added to one still fails. Only the guard itself imports playwright, by design. +const DIRECT = /^\s*import\b[^;\n]*\bfrom\s+['"]playwright['"]|\bimport\(\s*['"]playwright['"]\s*\)|\brequire\(\s*['"]playwright['"]\s*\)/m const files = execFileSync('git', ['ls-files', '--', 'internal', 'plugin-designs'], { cwd: ROOT, encoding: 'utf8' }) - .split('\n').filter((f) => /\.(mjs|js|cjs)$/.test(f) && !DETECTORS.has(f)) + .split('\n').filter((f) => /\.(mjs|js|cjs)$/.test(f) && f !== 'internal/lib/playwright-guarded.mjs') const bad = [] for (const f of files) { const code = readFileSync(resolve(ROOT, f), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '')