writeFile method
Writes atomically so readers never see a half-written file.
Implementation
void writeFile(String path) {
try {
final file = File(path);
file.parent.createSync(recursive: true);
final tmp = File('$path.tmp');
tmp.writeAsStringSync(jsonEncode(toJson()));
tmp.renameSync(path);
} catch (_) {
// Progress reporting must never break a build.
}
}