Search code examples
nestjs

Can NestJS CLI generate files with CRLF line ending?


I already searched for this some time ago but could not find a proper answer, also I don't really understand the inner workings of a CLI.

I'm working on Windows, and every time I use the Nest CLI it generates LF files. I gave a look at that CRLF vs LF discussion saga and seen that the ideal approach is to use CRLF in Windows and LF in Linux/Mac, the native line endings. But until now I couldn't find a way to set the Nest CLI to generate CRLF files. Is it possible at all?

There are two solutions I see, none of which I like very much

  • Use LF on the project and set git config core.autocrlf input, so that all code is pushed to repository as LF and then it is pulled as it is from there (what I'm doing right now)
  • Use CRLF and every single time the CLI is used run yarn format to transform the LF back to CRLF

But, would it be possible to just make the Nest CLI generate CRLF? Once again, I'm not very used to how CLIs work internally so I don't know what the best approach would be. Thanks to all.


Solution

  • Nest's generate command uses @angular-devkit/schematics under the hood which means that the generated file comes from a schematics file that is mostly already built that has values added to it based on the parameters of the CLI call. Because that's the case, you most likely will not be able to get the Nest CLI to generate files with CRLF by default. You might be able to create your own collection and schematic that has this, or you can remember to run format after generation. There is an issue to run prettier and linting after generation, but there's been no work done on it to my knowledge