Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Logikgate opened this issue Oct 22, 2018 · 1 comment
Closed

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

Logikgate opened this issue Oct 22, 2018 · 1 comment
Assignees
Labels
Milestone

Comments

@Logikgate
Copy link
Contributor

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.

@Logikgate
Copy link
Contributor Author

It looks like npm broke out the code that stringifies package.json into the stringify-package module for this exact case. It was done so that other projects could use it to ensure they are stringifying package.json in the same way npm does.

https://npm.community/t/splitting-clis-stringify-package-into-its-own-module/654

I've got a branch that is passing all of the tests that implements this. I will submit the PR later on in the week if there is no conversation here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants