verifyTypeScriptSetup.js writes mixed line endings into tsconfig.json
Created by: mikebeaton
fs.writeFileSync(fileName, JSON.stringify(object, null, 2) + os.EOL);
the code uses a combination of JSON.stringify
and os.EOL
- however JSON.stringify is specified to (and does) always use 0x000A
as its linefeed, even on Windows.
The net result is that after building a create-react-app
project on Windows, then tsconfig.json
contains LFs all down the file until the last line, which is CRLF, as shown here:
- This is not a user misconfiguration, it is the out-of-the-box behaviour
- It occurs whenever
verifyTypeScriptSetup.js
rewrites this file on Windows -
tsconfig.json
ends up with linebreaks as shown above regardless of whether it was initially pure LF or initially pure CRLF
It is possible to achieve (what seems to be fairly evidently) the intent of the code by replacing all LF characters in the JSON.stringify
output with os.EOL
as follows:
fs.writeFileSync(fileName, JSON.stringify(object, null, 2).replace(/\n/g, os.EOL) + os.EOL);
NB Even this is NOT necessarily what the user actually wants (for a Windows user, it depends on whether they are working with Windows linefeeds, or perhaps in Unix linefeeds because it is a cross-platform project).
I'd be happy to do a PR, but suspect there may well be other places where this approach is used, and also note that there are two other uses of os.EOL
in the same file (which again may or may not be what the user really wants for the reason just mentioned).