johan-v-r / LibSassBuilder

Sass builder for .NET projects
MIT License
99 stars 14 forks source link

Do not override if only white space (or EOL) changes #51

Closed JeanFTP closed 1 year ago

JeanFTP commented 1 year ago

Using Git & Visual Studio, it happens often when changing branches that css files are re-generated even if only white space or end-of-line changes are found. It is kind of anoying when you combine with git use, as it finds modified files when it is actalluy the same. Is there a way to avoid this behavior? And if not, would it be possible to implement an option for this?

johan-v-r commented 1 year ago

Hi Jean - do you have any suggestions how that could work?

We already have a hash check to see if files were modified, and I believe whitespace/EOL would affect that as well. I think even MSBuild would recompile on whitespace changes in .cs files.

JeanFTP commented 1 year ago

Quite easy : Replace result.CompiledContent == await File.ReadAllTextAsync(newFile)) with RemoveEndOfLines(result.CompiledContent) == RemoveEndOfLines(await File.ReadAllTextAsync(newFile)) And add:

        static string RemoveEndOfLines(string s)
            => string.Join("", string.Split(new[] { '\r' }, s, StringSplitOptions.RemoveEmptyEntries));

Needs to be tested, but this should work.

or I just found out that there is a new method "".ReplaceLineEndings() which may be simpler: result.CompiledContent.ReplaceLineEndings() == (await File.ReadAllTextAsync(newFile)).ReplaceLineEndings()

JeanFTP commented 1 year ago

See https://github.com/johan-v-r/LibSassBuilder/pull/52

JeanFTP commented 1 year ago

@johan-v-r Would that be a reasonable change for you ? On our side it is really a pain to have css changes every compilation when switching branches

johan-v-r commented 1 year ago

Looks good thanks for the PR! Will update shortly

JeanFTP commented 1 year ago

Great, however I believe you havean issue with the CI :)

JeanFTP commented 1 year ago

@johan-v-r