Files
pbakaus_impeccable/scripts/build-browser-detector.js
T
Paul BakausandClaude d7d10277d1 Merge main into oneshot-v4, keeping the service layer split out
main still carries the site, so every `site/` path resolves to deleted.
`tests/docs-integrity.test.js` goes with it (it imports the site's demo
renderer), and `package.json` keeps main's `@anthropic-ai/sdk` bump while
dropping `@google/genai` and `@paper-design/shaders`, which nothing in the
product layer imports.

Real code merges:

- hook-lib: main's #391 cache fix (sync the remembered set to the live
  scan so fixed findings stop being named and a reintroduced one fires
  again) now runs on the immediate tier rather than the whole filtered
  set. Remembering a deferred finding the per-edit pass never reported
  would let the Stop deep pass dedupe it away. main's `maxFileBytes`
  ceiling, `cleanAcked` once-per-file ack, and template-extensions
  re-export all land alongside the tiering work.
- live-browser: main's `hasParams` gate on the Tune badge, keeping this
  branch's `C.ink` badge text so it stays legible on kinpaku gold.
- detect-text: both the block-level codex-grid-background scan and main's
  inset-stripe CSS check.
- test-suites: union of both trigger sets and file lists, minus the
  site-only entries (`shiki-theme`, `docs-integrity`).
- Two hook tests moved off deferred-tier rules (`overused-font`,
  `side-tab`) onto immediate-tier ones. They assert cache bookkeeping,
  which the per-edit pass only reaches for the immediate tier.

Also drops the site waivers from `.impeccable/config.json` and stops
`build:browser` recreating a stray `site/` tree just to write a bundle
the other repo builds itself.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-21 01:45:42 -07:00

70 lines
2.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Generates cli/engine/detect-antipatterns-browser.js
* by concatenating the browser-safe detector modules and wrapping them in an IIFE.
*
* Run: node scripts/build-browser-detector.js
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, '..');
const MODULES = [
'cli/engine/shared/constants.mjs',
'cli/engine/registry/antipatterns.mjs',
'cli/engine/shared/color.mjs',
'cli/engine/shared/fonts.mjs',
'cli/engine/rules/checks.mjs',
'cli/engine/browser/injected/index.mjs',
];
const OUTPUT = path.join(ROOT, 'cli/engine/detect-antipatterns-browser.js');
const SITE_OUTPUT = path.join(ROOT, 'site/public/js/detect-antipatterns-browser.js');
function browserSafeModule(relPath) {
let code = fs.readFileSync(path.join(ROOT, relPath), 'utf-8');
if (relPath === 'cli/engine/registry/antipatterns.mjs') {
const match = code.match(/const ANTIPATTERNS = \[[\s\S]*?\n\];/);
if (!match) throw new Error('Could not extract browser antipattern registry');
code = match[0];
}
code = code.replace(/^import[\s\S]*?;\n/gm, '');
code = code.replace(/^export\s+\{[^}]*\};\n?/gm, '');
code = code.replace(/^export\s+\{[\s\S]*?^};\n?/gm, '');
return `// --- ${relPath} ---\n${code.trim()}\n`;
}
const code = MODULES.map(browserSafeModule).join('\n');
const output = `/**
* Anti-Pattern Browser Detector for Impeccable
* Copyright (c) 2026 Paul Bakaus
* SPDX-License-Identifier: Apache-2.0
*
* GENERATED -- do not edit. Source: cli/engine/browser/injected/index.mjs
* Rebuild: node scripts/build-browser-detector.js
*
* Usage: <script src="detect-antipatterns-browser.js"></script>
* Re-scan: window.impeccableScan()
*/
(function () {
if (typeof window === 'undefined') return;
${code}
})();
`;
fs.writeFileSync(OUTPUT, output);
console.log(`Generated ${path.relative(ROOT, OUTPUT)} (${(output.length / 1024).toFixed(1)} KB)`);
// The site consumes this bundle from its own repo. Only mirror it when that
// checkout is present, so a build here never recreates a stray `site/` tree.
if (fs.existsSync(path.dirname(path.dirname(SITE_OUTPUT)))) {
fs.mkdirSync(path.dirname(SITE_OUTPUT), { recursive: true });
fs.writeFileSync(SITE_OUTPUT, output);
console.log(`Generated ${path.relative(ROOT, SITE_OUTPUT)} (${(output.length / 1024).toFixed(1)} KB)`);
}