(relativePath, content, callback)
| 53 | } |
| 54 | |
| 55 | function withTemporaryTextFile(relativePath, content, callback) { |
| 56 | const absolutePath = path.join(root, relativePath); |
| 57 | const existed = fs.existsSync(absolutePath); |
| 58 | const previous = existed ? fs.readFileSync(absolutePath, 'utf8') : null; |
| 59 | |
| 60 | writeText(relativePath, content); |
| 61 | try { |
| 62 | return callback(); |
| 63 | } finally { |
| 64 | if (existed) { |
| 65 | fs.writeFileSync(absolutePath, previous, 'utf8'); |
| 66 | } else { |
| 67 | fs.rmSync(absolutePath, { force: true }); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | function flattenKeys(value, prefix = '') { |
| 73 | if (value == null || typeof value !== 'object' || Array.isArray(value)) { |
no test coverage detected