| 70 | })), |
| 71 | |
| 72 | async flush(): Promise<void> { |
| 73 | const written = new Set<string>(); |
| 74 | try { |
| 75 | await [...pending.entries()].reduce<Promise<null>>( |
| 76 | async (acc, [filePath, { content }]) => { |
| 77 | await acc; |
| 78 | const absolutePath = resolve(filePath); |
| 79 | await fs.mkdir(path.dirname(absolutePath), { recursive: true }); |
| 80 | await fs.writeFile(absolutePath, content); |
| 81 | written.add(filePath); |
| 82 | return null; |
| 83 | }, |
| 84 | Promise.resolve(null), |
| 85 | ); |
| 86 | pending.clear(); |
| 87 | } catch (error) { |
| 88 | await rollback([...written], pending, fs, resolve); |
| 89 | throw error; |
| 90 | } |
| 91 | }, |
| 92 | }; |
| 93 | } |
| 94 | |