Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #6566
Closed
Open
Issue created Mar 04, 2019 by Administrator@rootContributor

verifyTypeScriptSetup.js writes mixed line endings into tsconfig.json

Created by: 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).

Assignee
Assign to
Time tracking