Skip to content

verifyTypeScriptSetup.js writes mixed line endings into tsconfig.json #6566

Closed
@mikebeaton

Description

@mikebeaton

In verifyTypeScriptSetup.js:

    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:

screenshot_4

  • 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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions