microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

Home Page:https://www.typescriptlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler flag to specify line ending

fMads opened this issue · 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

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.

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.

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?

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

@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.

@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)

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.

+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.

+1 for this feature of specifying a line ending.