* Removes the conflicting global HTMLElementEventMap declaration from * @paulirish/trace_engine/models/trace/ModelImpl.d.ts to avoid TS2717 error * when both chrome-devtools-frontend and @paulirish/trace_engine declare * the same property.
()
| 23 | * the same property. |
| 24 | */ |
| 25 | function removeConflictingGlobalDeclaration(): void { |
| 26 | const filePath = resolve( |
| 27 | projectRoot, |
| 28 | 'node_modules/@paulirish/trace_engine/models/trace/ModelImpl.d.ts', |
| 29 | ); |
| 30 | console.log( |
| 31 | 'Removing conflicting global declaration from @paulirish/trace_engine...', |
| 32 | ); |
| 33 | const content = readFileSync(filePath, 'utf-8'); |
| 34 | // Remove the declare global block using regex |
| 35 | // Matches: declare global { ... interface HTMLElementEventMap { ... } ... } |
| 36 | const newContent = content.replace( |
| 37 | /declare global\s*\{\s*interface HTMLElementEventMap\s*\{[^}]*\[ModelUpdateEvent\.eventName\]:\s*ModelUpdateEvent;\s*\}\s*\}/s, |
| 38 | '', |
| 39 | ); |
| 40 | writeFileSync(filePath, newContent, 'utf-8'); |
| 41 | console.log('Successfully removed conflicting global declaration.'); |
| 42 | } |
| 43 | |
| 44 | async function main() { |
| 45 | console.log('Running prepare script to clean up chrome-devtools-frontend...'); |