Skip to content

TNS Commands Removing Newline Added by NPM from Package.json #4049

@Logikgate

Description

@Logikgate

Environment

  • CLI: 4.2.4
  • Cross-platform modules: 4.3.0-2018-08-10-02
  • Android Runtime: 5.0.0-2018-10-18-162704-01
  • iOS Runtime: 4.3.0-2018-09-28-125108-01
  • Plugin(s): None

Describe the bug
By default NPM adds a \n newline to the end of the package.json file when npm saves the package.json file.
The line in npm-cli that calls the module that adds the newline
The module, maintained by npm, that adds the newline (stringify-package)

Since the nativescript-cli doesn't use the same stringify command within FileSystem.writeJson it removes the newline added by npm-cli commands. This causes package.json to appear modified even when nothing has changed which makes for unneeded commits. For reference, below is the writeJson method within nativescript-cli:

return this.writeFile(filename, JSON.stringify(data, null, space), encoding);

To Reproduce
tns create MyApp
cd ./MyApp
The package.json file will have an extra newline
tns platform update android
The package.json file will NOT have an extra newline

Expected behavior
tns operations should not remove newlines from the end of package.json

Additional context
I am happy to open a pull request to modify the writeJson method so that it uses the stringify-package module (the same one that NPM uses and maintains). I would make it add the newline if the file that is being saved is called package.json only. This way it won't affect any other usage of writeJson. I'd like to discuss this here and will open the pull request if everyone agrees.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions