TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Compiler flag to specify line ending

Open fMads opened this issue 11 years ago • 10 comments

All generated js-files have windows-style line endings. It would be great, if we could specify the line endings - windows, unix etc.

We use PhpStorm as editor, and it keeps marking generated js, d.ts etc files as changed, even though the code is the same. The only difference is \n -> \r\n.

Relates to https://typescript.codeplex.com/workitem/258

fMads avatar Jan 16 '15 07:01 fMads

I don't know if you'd get different results if the line endings were the same - but you could also configure your editor's line ending options to make sure this is the case.

DanielRosenwasser avatar Jan 16 '15 08:01 DanielRosenwasser

I have configured the editor - but I think the difference is, that this is an external change to the files and the editor therefor isn't updating the line endings. Git is also configures to use unix-style, so it will be commited with unix style line endings.

The main problem is, when we're changing branches, and the .ts files are changed in the new branch. The TSC will se the .ts file change and recompile the file and thus overwriting the .js file (which was committed with unix style line endings) with windows style line endings. It marks as a change in PhpStorm.

fMads avatar Jan 16 '15 08:01 fMads

The line endings of the generated .js, .d.ts, and .sourcemap files are currently only dependent on the underlying system. so if you are running on windows you will always get /r/n if you are on macOS you would get /n.

@fMads you want a new compiler flag to toggle line endings, correct?

mhegazy avatar Jan 16 '15 17:01 mhegazy

If this is a matter of checking out something with Unix line endings, have you tried setting your git repo's autocrlf option?

DanielRosenwasser avatar Jan 16 '15 22:01 DanielRosenwasser

@fMads: any particular reason you're committing the generated js files? I feel like they should be left out of the repo, just like binaries. Not being snarky, just curious.

carlpaten avatar Jan 17 '15 17:01 carlpaten

@mhegazy Yes, a compiler flag would be great :)

@DanielRosenwasser Yes - it only converts the file, when the repo is committed. That's a step to late.

@lilred You're proberbly right - that would be the best way to handle it. We just don't have any post-processing of our code at our live systems. We commit and push to remote repo, when we do an update to our clients. We could of course change it, so we compile the code at post-receive - but it's just easier doing it on dev-system (Before pushing)

fMads avatar Jan 19 '15 09:01 fMads

updating the title for the issue.

@fMads, a PR would definitely be welcomed. The system now is wired to get the sys.newline, (see program.ts L72) the change would be to pass options.newLine instead.

mhegazy avatar Jan 19 '15 23:01 mhegazy

+1 for this feature of specifying a line ending. GIT doesn't have quite the right mix of options for dealing with cross-platform line endings and the best I've found on a mixed team that deploys to UNIX-style systems is to just force those common line endings everywhere. Yes, having JS files in version control may not be ideal but it's pragmatic.

kmashint avatar Feb 10 '15 00:02 kmashint

+1 for this feature of specifying a line ending.

hranicka avatar Feb 18 '15 08:02 hranicka

Thanks @kmashint!

mhegazy avatar May 04 '15 20:05 mhegazy