@@ -14,7 +14,7 @@ const getNoDeclarationFileError = ({ filename }) =>
1414 ) ;
1515
1616const getTypeMismatchError = ( { filename, expected, actual } ) => {
17- const diff = new LineDiff ( actual , expected ) . toString ( ) ;
17+ const diff = new LineDiff ( enforceLFLineSeparators ( actual ) , expected ) . toString ( ) ;
1818
1919 return new Error (
2020 `Generated type declaration file is outdated. Run webpack and commit the updated type declaration for '${ filename } '\n\n${ diff } `
@@ -36,6 +36,19 @@ const filenameToTypingsFilename = filename => {
3636 return path . join ( dirName , `${ baseName } .d.ts` ) ;
3737} ;
3838
39+ const enforceLFLineSeparators = text => {
40+ if ( text ) {
41+ // replace all CRLFs (Windows) by LFs (Unix)
42+ return text . replace ( / \r \n / g, "\n" ) ;
43+ } else {
44+ return text ;
45+ }
46+ } ;
47+
48+ const compareText = ( contentA , contentB ) => {
49+ return enforceLFLineSeparators ( contentA ) === enforceLFLineSeparators ( contentB ) ;
50+ } ;
51+
3952const validModes = [ 'emit' , 'verify' ] ;
4053
4154const isFileNotFound = err => err && err . code === 'ENOENT' ;
@@ -91,7 +104,7 @@ module.exports = function(content, ...rest) {
91104 return failed ( err ) ;
92105 }
93106
94- if ( cssModuleDefinition !== fileContents ) {
107+ if ( ! compareText ( cssModuleDefinition , fileContents ) ) {
95108 return failed (
96109 getTypeMismatchError ( {
97110 filename : cssModuleInterfaceFilename ,
@@ -105,7 +118,7 @@ module.exports = function(content, ...rest) {
105118 } ) ;
106119 } else {
107120 read ( ( _ , fileContents ) => {
108- if ( cssModuleDefinition !== fileContents ) {
121+ if ( ! compareText ( cssModuleDefinition , fileContents ) ) {
109122 write ( cssModuleDefinition , err => {
110123 if ( err ) {
111124 failed ( err ) ;
0 commit comments