mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-11 21:57:14 +03:00
unreferencedPlates: an explicit artifact joins the source corpus instead of replacing it
Greptile's follow-up P1 on #599: with --artifact set, only that HTML file was read, so a plate referenced exclusively from a linked stylesheet still read as unused. The bounded source walk now runs either way. AI-assisted (Claude Code).
This commit is contained in:
@@ -341,7 +341,10 @@ function sourceFiles(root = '.', limit = 400) {
|
||||
export function unreferencedPlates(spec, artifact = null) {
|
||||
const plates = (spec?.regions || []).filter((r) => r.medium === 'raster' && r.plate);
|
||||
if (!plates.length) return [];
|
||||
const files = artifact && fs.existsSync(artifact) ? [artifact] : sourceFiles();
|
||||
// The artifact narrows nothing: a plate may be referenced only from a
|
||||
// stylesheet the artifact links (assets/hero.css), so the source walk runs
|
||||
// either way and the artifact is simply guaranteed a seat in the corpus.
|
||||
const files = [...new Set([...(artifact && fs.existsSync(artifact) ? [artifact] : []), ...sourceFiles()])];
|
||||
let corpus = '';
|
||||
for (const f of files) { try { corpus += fs.readFileSync(f, 'utf8') + '\n'; } catch { /* skip */ } }
|
||||
const missing = [];
|
||||
|
||||
@@ -475,8 +475,12 @@ describe('unreferencedPlates', () => {
|
||||
fs.writeFileSync(path.join(d, 'assets', 'hero.css'), ".hero { background-image: url('./plates/hero-plate.png'); }");
|
||||
const spec = { regions: [{ id: 'hero-art', medium: 'raster', plate: 'assets/plates/hero-plate.png' }] };
|
||||
assert.deepEqual(unreferencedPlates(spec, null), [], 'the stylesheet under assets counts as a reference');
|
||||
// an explicit artifact does not bypass the stylesheet walk
|
||||
fs.writeFileSync(path.join(d, 'index.html'), '<link rel="stylesheet" href="assets/hero.css"><main class="hero"></main>');
|
||||
assert.deepEqual(unreferencedPlates(spec, path.join(d, 'index.html')), [], 'the linked stylesheet still counts with --artifact set');
|
||||
fs.writeFileSync(path.join(d, 'assets', 'hero.css'), '.hero { background: red; }');
|
||||
assert.equal(unreferencedPlates(spec, null).length, 1, 'an unreferenced plate is still named');
|
||||
assert.equal(unreferencedPlates(spec, path.join(d, 'index.html')).length, 1, 'and with the artifact set too');
|
||||
} finally { process.chdir(prev); fs.rmSync(d, { recursive: true, force: true }); }
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user