check:browser-gates-guarded matches a real playwright import, so no detector needs a whole-file exclusion

Excluding the two detector files by path also skipped any real import added to
them. The check now matches only a static import statement at the start of a
line or a literal import('playwright') / require('playwright') call, which the
detectors' escaped regex literals never are; only the guard itself is excluded.
Planted a real import in browser-gates.mjs and one in this check: both fail.
This commit is contained in:
Doxa Maps 2026-09-28 07:12:55 +00:00
parent 462f553442
commit 22a1561d2f

View file

@ -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 <name>`)
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, '')