Only write to files if the change (#511)

Fixes #506.
master
Simon Lydell 2017-01-29 16:09:22 +01:00 committed by Christopher Chedeau
parent 3f776bed3d
commit 17add13860
1 changed files with 11 additions and 7 deletions

View File

@ -191,13 +191,17 @@ if (stdin) {
}
if (write) {
fs.writeFile(filename, output, "utf8", err => {
if (err) {
console.error("Unable to write file: " + filename + "\n" + err);
// Don't exit the process if one file failed
process.exitCode = 2;
}
});
// Don't write the file if it won't change in order not to invalidate
// mtime based caches.
if (output !== input) {
fs.writeFile(filename, output, "utf8", err => {
if (err) {
console.error("Unable to write file: " + filename + "\n" + err);
// Don't exit the process if one file failed
process.exitCode = 2;
}
});
}
} else {
// Don't use `console.log` here since it adds an extra newline at the end.
process.stdout.write(output);