{"record":{"id":"3a4ed03d694dfb99","repo":"pbakaus/impeccable","slug":"could-not-extract-browser-antipattern-registry","errorCode":null,"errorMessage":"Could not extract browser antipattern registry","messagePattern":"Could not extract browser antipattern registry","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/browser-detector-bundle.js","lineNumber":17,"sourceCode":"import fs from 'node:fs';\nimport path from 'node:path';\n\nconst BROWSER_DETECTOR_MODULES = [\n  'cli/engine/shared/constants.mjs',\n  'cli/engine/registry/antipatterns.mjs',\n  'cli/engine/shared/color.mjs',\n  'cli/engine/shared/fonts.mjs',\n  'cli/engine/rules/checks.mjs',\n  'cli/engine/browser/injected/index.mjs',\n];\n\nfunction browserSafeModule(root, relPath) {\n  let code = fs.readFileSync(path.join(root, relPath), 'utf-8');\n  if (relPath === 'cli/engine/registry/antipatterns.mjs') {\n    const match = code.match(/const ANTIPATTERNS = \\[[\\s\\S]*?\\n\\];/);\n    if (!match) throw new Error('Could not extract browser antipattern registry');\n    code = match[0];\n  }\n  code = code.replace(/^import[\\s\\S]*?;\\n/gm, '');\n  code = code.replace(/^export\\s+\\{[^}]*\\};\\n?/gm, '');\n  code = code.replace(/^export\\s+\\{[\\s\\S]*?^};\\n?/gm, '');\n  return `// --- ${relPath} ---\\n${code.trim()}\\n`;\n}\n\nexport function bundleBrowserDetectorModules(root) {\n  return BROWSER_DETECTOR_MODULES\n    .map((relPath) => browserSafeModule(root, relPath))\n    .join('\\n');\n}\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/pbakaus/impeccable/blob/d14711ae3d1a1dd62dee61a358d27f107c51ccd0/scripts/lib/browser-detector-bundle.js#L1-L31","documentation":"Thrown by the browser-detector bundler when the regex `/const ANTIPATTERNS = \\[[\\s\\S]*?\\n\\];/` does not match the contents of cli/engine/registry/antipatterns.mjs. The bundler extracts that array literal to ship a browser-safe inlined copy; if the array's declaration syntax changes (e.g. renamed, reformatted, or split across files) the extraction breaks.","triggerScenarios":"Renaming the ANTIPATTERNS constant, changing its declaration form (e.g. `export const ANTIPATTERNS=` vs `const ANTIPATTERNS =`), adding a `]` on a non-newline-terminated line, or splitting the array across multiple modules. Fires during `bun run build:browser` / `bun run build`.","commonSituations":"A refactor moves antipattern definitions into a registry loader that builds the array at runtime; a formatter rewraps the closing `];` onto the same line as content; the file was deleted or moved without updating BROWSER_DETECTOR_MODULES.","solutions":["Keep the literal declaration `const ANTIPATTERNS = [ ... \\n];` intact in cli/engine/registry/antipatterns.mjs so the regex matches.","If you must change the declaration shape, update the regex in scripts/lib/browser-detector-bundle.js to match the new form.","Run `bun run build:browser` after registry edits to fail fast on extraction breakage."],"exampleFix":"// before — renamed constant breaks the extractor\nconst RULES = [ ... ];\n\n// after — keep the literal name and newline-terminated close\nconst ANTIPATTERNS = [\n  { id: 'side-tab', /* ... */ },\n];","handlingStrategy":"validation","validationCode":"const code = fs.readFileSync(antipatternsPath, 'utf-8');\nif (!/const ANTIPATTERNS = \\[[\\s\\S]*?\\n\\];/.test(code)) {\n  throw new Error('Registry literal shape changed; update the bundler regex.');\n}","typeGuard":"function registryLiteralMatches(code) {\n  return /const ANTIPATTERNS = \\[[\\s\\S]*?\\n\\];/.test(code);\n}","tryCatchPattern":"try {\n  bundleBrowserDetectorModules(root);\n} catch (err) {\n  if (/extract browser antipattern registry/.test(err.message)) {\n    console.error('Registry literal not found; keep `const ANTIPATTERNS = [ ... ];` intact.');\n  } else throw err;\n}","preventionTips":["Run `bun run build:browser` in CI to catch extraction breakage early.","If refactoring the registry, update the bundler regex in the same commit.","Add a unit test asserting the regex still matches the registry file."],"tags":["build","regex","registry","browser-engine","extraction"],"backgroundTag":null,"analyzedSha":"d14711ae3d1a1dd62dee61a358d27f107c51ccd0","analyzedAt":"2026-08-13T00:52:25.771Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}