jwvdiermen / grunt-include-source

Include lists of files into your source files automatically.
MIT License
68 stars 31 forks source link

Line break issue in Windows with wiredep #25

Closed ghwilson4456 closed 9 years ago

ghwilson4456 commented 10 years ago

Running wiredep after doing an includeSource breaks my index.html, but only on Windows machines. Works fine in OS X. Changing line 204 of includeSource.js to .join('\r\n'); fixes the issue.

jwvdiermen commented 10 years ago

Those newlines are giving me headaches, but for this the solutions seems to be simple enough. I'll scan the first file to detect the type of end-line and apply that to the join. I'll have a try at it this in the weekend.

jwvdiermen commented 10 years ago

I've improved the line endings for your use case, but it's untested. Could you confirm it works for you? Unit tests are required, I hope to add them eventually.

ryeballar commented 10 years ago

My issue was somehow similar to @ghwilson4456 problem, the lines that were joined were all \n instead of \r\n in windows. The problem is evident in these lines, https://github.com/jwvdiermen/grunt-include-source/blob/master/tasks/includeSource.js#L261-L264. After a line feed \n is detected, it decrements the index, the problem is at https://github.com/jwvdiermen/grunt-include-source/blob/master/tasks/includeSource.js#L262, wherein you check for the decremented index minus 1.

Change:

                if (contents[i] === '\n'){
                    i--;
                    if (contents[i-1] === '\r'){
                        i--;
                    }
                    break;
                }

to:

                if (contents[i] === '\n'){
                    if (contents[--i] === '\r'){
                        i--;
                    }
                    break;
                }
jwvdiermen commented 9 years ago

This should be fixed in the latest release.