Preserve formatting of package.json
See original GitHub issueSee discussion in #38, which was originally meant to address #37 but ended up in a slippery slope of scope creep.
Basically, we overwrite package.json using JSON.stringify(pkg, null, 2) + '\n'
but this may be too intrusive for folks using Windows line endings (\r\n
instead of \n
) or different indentation (tabs instead of spaces, or more than 2 spaces).
Here are a couple ways we could address this:
- Detect and preserve newline chars and indentation via
detect-newline
anddetect-indent
(similar to #38) - Read package.json as string (instead of
require()
ing it) and just replace the"version"
value, ignoring/preserving all other content/formatting
I think I’d prefer option 2.
I also think our CHANGELOG writing logic should not be affected by this.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:13 (10 by maintainers)
Top Results From Across the Web
Stop re-formatting package.json with Prettier and VSCode ...
You are using VSCode, Prettier and have configured auto formatting on save. Now you, go to package. json or tsconfig. json, you change ......
Read more >Coping strategy for npm --save reformatting package.json
To make sure your package.json is automatically reformatted and not relying on the developer to do it, you can add reformatting as part...
Read more >package.json - npm Docs
json are the name and version fields as they will be required. The name and version together form an identifier that is assumed...
Read more >Can I make npm install follow a certain package.json format?
Is there any way to make npm follow the existing format, or to specifiy a custom format (e.g. 4-space indentation) for the package.json...
Read more >Respect package.json formatting · Issue #5694 - GitHub
Indentation is now detected and preserved for package.json , package-lock.json , and npm-shrinkwrap.json . If the package lock is missing, it ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
please preserve the code format, we are always fixing conflicts on package.json
Looks like
npm version
pretty much does the same thing thatstandard-version
does. Hmm, maybe this is a non-issue then…