(filePath: string, fn: (json: any) => any | void)
| 10 | import { join } from 'node:path'; |
| 11 | |
| 12 | export function updateJsonFile(filePath: string, fn: (json: any) => any | void) { |
| 13 | return readFile(filePath).then((tsConfigJson) => { |
| 14 | // Remove single and multiline comments |
| 15 | const tsConfig = JSON.parse(tsConfigJson.replace(/\/\*\s(.|\n|\r)*\s\*\/|\/\/.*/g, '')) as any; |
| 16 | const result = fn(tsConfig) || tsConfig; |
| 17 | |
| 18 | return writeFile(filePath, JSON.stringify(result, null, 2)); |
| 19 | }); |
| 20 | } |
| 21 | |
| 22 | export function updateTsConfig(fn: (json: any) => any | void) { |
| 23 | return updateJsonFile('tsconfig.json', fn); |
no test coverage detected