mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 22:26:38 +03:00
* Add detector benchmark lab and visual contrast fallback * Expand visual contrast fixture coverage * Add browser visual contrast fallback * Show visual contrast overlays in detector lab * Fix detector lab short viewport layout * Fix detector lab visual overlays * Add visual contrast to browser scan overlays * Avoid browser scroll jumps during visual contrast scans * Resolve visual contrast lazily on scroll * Refresh detector lab visual counts lazily * Update pnpm lockfile for static parser deps * Address Bugbot detector API comments * Report extension visual contrast errors * Refactor detector into engine modules * Address Bugbot detector comments * Fix latest Bugbot detector notes * Fix visual contrast fixture labels * Refine detector lab fixtures * Fix stale detector overlay references * Fix detector lab fixture URLs * Fix typography lab fixture highlights * Fix typography lab page-level signal * Fix visual overlay lifecycle cleanup * Remove dead spotlight timer cleanup * Make browser async APIs reject consistently
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const ROOT = process.cwd();
|
|
const FIXTURES_DIR = path.join(ROOT, 'tests', 'fixtures');
|
|
|
|
function walk(dir: string): string[] {
|
|
const out: string[] = [];
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const fullPath = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) out.push(...walk(fullPath));
|
|
else if (entry.name.endsWith('.html')) out.push(fullPath);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function getStaticPaths() {
|
|
return walk(FIXTURES_DIR).map((filePath) => ({
|
|
params: {
|
|
path: path.relative(FIXTURES_DIR, filePath).replace(/\.html$/, '').split(path.sep).join('/'),
|
|
},
|
|
props: {
|
|
filePath,
|
|
},
|
|
}));
|
|
}
|
|
|
|
function withDetectorScript(html: string) {
|
|
if (html.includes('detect-antipatterns-browser.js')) return html;
|
|
const script = [
|
|
'<script>',
|
|
'window.__IMPECCABLE_CONFIG__ = { ...(window.__IMPECCABLE_CONFIG__ || {}), autoScan: true };',
|
|
'</script>',
|
|
'<script src="/js/detect-antipatterns-browser.js"></script>',
|
|
].join('');
|
|
if (/<\/body>/i.test(html)) return html.replace(/<\/body>/i, `${script}</body>`);
|
|
return `${html}${script}`;
|
|
}
|
|
|
|
export function GET({ props }: { props: { filePath: string } }) {
|
|
return new Response(withDetectorScript(fs.readFileSync(props.filePath, 'utf-8')), {
|
|
headers: {
|
|
'Content-Type': 'text/html; charset=utf-8',
|
|
'Cache-Control': 'no-store',
|
|
},
|
|
});
|
|
}
|