blob: 4db8da490277541fc2dd71b85d032a530c1f2f96 [file] [edit]
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {existsSync, readFileSync, writeFileSync} from 'node:fs';
import {resolve} from 'node:path';
const projectRoot = process.cwd();
/**
* Removes the conflicting global HTMLElementEventMap declaration from
* @paulirish/trace_engine/models/trace/ModelImpl.d.ts to avoid TS2717 error
* when both devtools-frontend and @paulirish/trace_engine declare
* the same property.
*/
function removeConflictingGlobalDeclaration(): void {
const filePath = resolve(
projectRoot,
'node_modules/@paulirish/trace_engine/models/trace/ModelImpl.d.ts',
);
if (!existsSync(filePath)) {
return;
}
console.log(
'Removing conflicting global declaration from @paulirish/trace_engine...',
);
const content = readFileSync(filePath, 'utf-8');
// Remove the declare global block using regex
// Matches: declare global { ... interface HTMLElementEventMap { ... } ... }
const newContent = content.replace(
/declare global\s*\{\s*interface HTMLElementEventMap\s*\{[^}]*\[ModelUpdateEvent\.eventName\]:\s*ModelUpdateEvent;\s*\}\s*\}/s,
'',
);
writeFileSync(filePath, newContent, 'utf-8');
console.log('Successfully removed conflicting global declaration.');
}
function main(): void {
removeConflictingGlobalDeclaration();
}
main();