Preserve detector extension mappings

Keep unmanaged detector fields when ignore-file updates the canonical detector configuration. Add a regression covering existing extension mappings.\n\nAI assistance: Codex implemented and validated this change under maintainer authorization.
This commit is contained in:
Paul Bakaus
2026-08-03 10:42:07 -07:00
parent 57ce11288f
commit 2345868c7b
2 changed files with 12 additions and 2 deletions
+6 -2
View File
@@ -240,10 +240,14 @@ function writeDetectorConfig(cwd, detectorConfig, opts = {}) {
const existingRaw = readRawConfigFile(filePath).raw;
const existing = existingRaw && typeof existingRaw === 'object' && !Array.isArray(existingRaw) ? existingRaw : {};
const nextHook = stripDetectorKeys(hookSection(existing));
const existingDetector = mergeDetectorConfig(detectorSection(existing));
const existingDetectorSection = detectorSection(existing) || {};
const existingDetector = mergeDetectorConfig(existingDetectorSection);
const next = {
...existing,
detector: mergeDetectorConfig(detectorConfig, existingDetector),
detector: {
...existingDetectorSection,
...mergeDetectorConfig(detectorConfig, existingDetector),
},
};
if (Object.keys(nextHook).length > 0) next.hook = nextHook;
else delete next.hook;
+6
View File
@@ -1058,9 +1058,15 @@ describe('hook-admin.mjs', () => {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, '<div style="border-left: 4px solid #7c3aed; border-radius: 16px; padding: 16px;">Card</div>');
fs.mkdirSync(path.dirname(getConfigPath(cwd)), { recursive: true });
fs.writeFileSync(getConfigPath(cwd), JSON.stringify({
detector: { extensions: [{ ext: '.blade.php', engine: 'html' }] },
}));
runAdmin(['ignore-file', 'src/ConfirmedCard.html']);
const shared = JSON.parse(fs.readFileSync(getConfigPath(cwd), 'utf-8')).detector;
assert.deepEqual(shared.extensions, [{ ext: '.blade.php', engine: 'html' }]);
assert.deepEqual(shared.ignoreFiles, ['src/ConfirmedCard.html']);
const r = await runHook({