Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a trailing newline to package.json when appropriate #17

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions hatch_nodejs_version/version_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,16 @@ def set_version(self, version: str, version_data):
if not os.path.isfile(path):
raise OSError(f"file does not exist: {self.path}")

# Read the original file so we can see if it has a trailing
# newline character.
with open(path, "r") as f:
raw_data = f.read()

with open(path, "r") as f:
data = json.load(f)

data["version"] = self.python_version_to_node(version)
with open(path, "w") as f:
json.dump(data, f, indent=4)
if raw_data.endswith('\n'):
f.write('\n')