Repository navigation
Leave unchanged JSON locale files alone and keep their trailing newline - #124
Merged
Merged
Conversation
- Skip the write when the merged content equals what was read, so a sync no longer reformats the source file - Skip the delete-path write when none of the keys were in the file - Keep the trailing newline when the file had one; new files end with one - Fixes localheroai/localhero-ai#859
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Every JSON write re-serialised the whole file with
JSON.stringify(x, null, 2)and no trailing newline, even when nothing changed. In a sync the source-language cells are part of the payload, so a hand-formatteden.jsonwas rewritten on every sync: inline arrays and one-line objects got exploded, and git showed\ No newline at end of file(newsroom-demo PR #19). The delete path had the same problem on a larger scale:pullcalls it for every translation file when keys were deleted, and each JSON file was rewritten even when it held none of those keys.Change
All in
src/utils/translation-updater/json-handler.ts:updateJsonFileskips the write when the merged content serialises exactly like what was read (compactJSON.stringifyon both, so key order counts too). The skip only happens when a write would have changed nothing but whitespace. A file that is new or unparseable is always written.deleteKeysFromJsonFilereturns without writing when none of the keys were in the file.updatedKeys,created, deleted keys), so counts and summaries stay the same.Not changed: indentation is still 2 spaces, and a file that really does change still has inline arrays expanded. Keeping those would need a splicer like
yaml-splicer.ts.Plan with a caller audit (translate, ci sync in git and signed-commit mode, pull update and delete, source alignment, multi-language files, new files):
dev-docs/specs/859-json-write-noise.mdin the monorepo. Codex reviewed the plan and found no blockers.Verified
tests/utils/translation-updater/json-write-noise.test.tswere written first: 6 of the 7 failed on main's code. The 7th covers a file without a trailing newline, which main already left alone. They cover a byte-identical hand-formatted file with unchanged values, a byte-identical multi-language file, the newline kept after a real change, no newline added to a file without one, a new file ending in a newline, a delete leaving a file without those keys untouched, and a delete keeping the newline.npm test: 83 suites, 1502 tests pass.npx tsc --noEmitandnpx eslint 'src/**/*.ts'are clean.distand ranupdateTranslationFileon a copy of newsroom-demo'sapps/editoren.jsonwith its own values, which is what a sync does. The file stayed byte-identical (34 lines in, 34 out). A real change tosv.jsonupdated the value and kept the newline.Known edge case, not a blocker: a file with a duplicated key is no longer cleaned up by a no-op write, since the write is skipped.
Fixes localheroai/localhero-ai#859