Standard-version: Preserve formatting of package.json

Created on 23 May 2016  路  13Comments  路  Source: conventional-changelog/standard-version

See 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:

  1. Detect and preserve newline chars and indentation via detect-newline and detect-indent (similar to #38)
  2. 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.

stale

Most helpful comment

please preserve the code format, we are always fixing conflicts on package.json

All 13 comments

Probably should be similar to how npm-version does it.

@nexdrew might be worth looking at how greenkeeper does it.

Looks like npm version pretty much does the same thing that standard-version does. Hmm, maybe this is a non-issue then...

Is this still an issue?

@stevemao I think we can close this. If anyone complains we can revisit.

@nexdrew I'm having problems with this, I use 4 spaces in the package.json, but it's changing to 2 spaces.
Could preserve the file, how you said.

tested in v4.3.0

I think we should reopen this since npm preserves the format now.

please preserve the code format, we are always fixing conflicts on package.json

Can I submit a pull request for this ? Which option do you prefer ?

Read package.json as string (instead of require()ing it) and just replace the "version" value, ignoring/preserving all other content/formatting

I am agree with this

I've been looking for this for a while, so just got around to creating a PR for this: #282
It's basically a mix of both suggestions and is the same solution npm uses to preserve the format.

@alasdairhurst @nexdrew is this still something anyone would like to take on?

@bcoe see the linked PR I provided - it's already merged by you and released in 5.0.0!

@bcoe this can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kimnh-0823 picture kimnh-0823  路  4Comments

gultyaev picture gultyaev  路  4Comments

eemeli picture eemeli  路  4Comments

noreiller picture noreiller  路  5Comments

sarbbottam picture sarbbottam  路  3Comments