(filePath: string, updates: Record<string, string>)
| 21 | * Reads the raw text, does targeted regex replacements, and writes it back. |
| 22 | */ |
| 23 | export async function updateJsonFields(filePath: string, updates: Record<string, string>): Promise<void> { |
| 24 | let content = await readFile(filePath, 'utf-8'); |
| 25 | for (const [key, newValue] of Object.entries(updates)) { |
| 26 | const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
| 27 | const pattern = new RegExp(`("${escaped}"\\s*:\\s*)"[^"]*"`); |
| 28 | content = content.replace(pattern, `$1"${newValue}"`); |
| 29 | } |
| 30 | await writeFile(filePath, content, 'utf-8'); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Update a nested string field inside a top-level object in a JSON file without reformatting. |
no outgoing calls
no test coverage detected
searching dependent graphs…