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

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

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Changes from 2 commits
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
8 changes: 7 additions & 1 deletion hatch_nodejs_version/version_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,15 @@ 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:
data = json.load(f)
raw_data = f.read()

data = json.loads(raw_data)

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')