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

feat: preserve formatting when writing to package.json #282

Merged
merged 1 commit into from
Feb 14, 2019
Merged

feat: preserve formatting when writing to package.json #282

merged 1 commit into from
Feb 14, 2019

Conversation

alasdairhurst
Copy link
Contributor

@alasdairhurst alasdairhurst commented Nov 29, 2018

This PR implements a feature (or maybe it's a fix?) to get standard-version to preserve the indentation and
line feed of package.json instead of overriding the user's preferred format with 2 space indentation. (See #43)

detect-indent and detect-newline are used to figure out the current indentation of package.json. This is done in an identical way to how npm handles writing changes to package.json.

Notable internal change:

  1. package.json is no longer loaded with require(). While it should be functionally identical, in order to detect the formatting, the file to be read in as plain text. This caused certain tests to fail since the require cache wasn't updated during the bump, resulting in additional places where the cache needed to be deleted between invocations of the CLI in these tests. By using fs.readFileSync() in both places in the code where package.json is read instead of require(), the deletion of the require cache in the tests is no longer necessary for them to work.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 856a5c5 on alasdairhurst:preserve-formatting into 844cde6 on conventional-changelog:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 856a5c5 on alasdairhurst:preserve-formatting into 844cde6 on conventional-changelog:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 856a5c5 on alasdairhurst:preserve-formatting into 844cde6 on conventional-changelog:master.

index.js Show resolved Hide resolved
test.js Show resolved Hide resolved
@bcoe bcoe merged commit 96216da into conventional-changelog:master Feb 14, 2019
@bcoe
Copy link
Member

bcoe commented Feb 14, 2019

@alasdairhurst sorry this took so long to land, thank you for the contribution.

If you don't mind, give this a try:

npm i standard-version@5.0.0

You should find it has your changes.

@alasdairhurst alasdairhurst deleted the preserve-formatting branch May 6, 2019 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants