Skip to content

Commit 0f53f5a

Browse files
committed
fix(compiler): ensure CRLF line endings and skip identical file writes
1 parent b3c904d commit 0f53f5a

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/Compiler/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ public static async void Output(
316316
string content,
317317
bool forceOverwrite
318318
) {
319+
// All files should use CRLF so we should convert before writing
320+
content = content.Replace("\n", "\r\n");
321+
319322
if (string.IsNullOrWhiteSpace(outputDirectory)) {
320323
// Output to console to allow for piping
321324
Console.Out.Write(content);
@@ -324,6 +327,16 @@ bool forceOverwrite
324327

325328
var outputPath = GetOutputLocation(sourceDirectory, outputDirectory, fileName);
326329
if (File.Exists(outputPath)) {
330+
var hashEngine = System.Security.Cryptography.SHA256.Create();
331+
var existingFileStream = File.OpenRead(outputPath);
332+
var hash = hashEngine.ComputeHash(existingFileStream);
333+
existingFileStream.Close();
334+
var newHash = hashEngine.ComputeHash(Encoding.UTF8.GetBytes(content));
335+
if (hash.SequenceEqual(newHash)) {
336+
Logger.Trace($"File {outputPath} already exists and is identical. Skipping.");
337+
return;
338+
}
339+
327340
var removeFile = forceOverwrite;
328341
if (!removeFile) {
329342
Logger.Info($"File {outputPath} already exists. Overwrite? (Y/n)");

0 commit comments

Comments
 (0)