fix(transloco): strip a leading BOM in keys-manager and optimize - #1002
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthrough
ChangesBOM-aware JSON parsing
Merge Risk: ⚪ Minimal · up to The change allows two CLI tools to parse translation files with a leading BOM while preserving source-file formatting behavior; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is detailed and directly explains the bug, affected code paths, scope decisions, tests, mutation testing, lint results, and suite results. It does not reproduce every template heading or checklist item, but it provides the required change context and verification information.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@jsverse/transloco
@jsverse/transloco-keys-manager
@jsverse/transloco-locale
@jsverse/transloco-messageformat
@jsverse/transloco-optimize
@jsverse/transloco-persist-lang
@jsverse/transloco-persist-translations
@jsverse/transloco-preload-langs
@jsverse/transloco-schematics
@jsverse/transloco-scoped-libs
@jsverse/transloco-utils
@jsverse/transloco-validator
commit: |
Follow-up to #1000, which taught
transloco-validatorto strip a leading UTF-8 BOM before parsing a translation file. The sibling Node tools that read the same files were left with the original bug, so the toolchain was inconsistent: a translation file saved with a BOM would now pass validation and then still blow up further down the pipeline.Concretely, before this PR:
What changed
Two sites parse translation JSON out of a raw
readFileSyncresult and so hit the sameSyntaxError:libs/transloco-keys-manager/src/lib/utils/file.utils.ts— theparse: truebranch ofreadFile, reached fromkeys-detective/compare-keys-to-files.tsandwebpack-plugin/generate-keys.ts.libs/transloco-optimize/src/lib/transloco-optimize.ts—optimizeFiles.Both now apply the same anchored
.replace(/^\uFEFF/, '')that #1000 introduced, so the three CLI entry points agree on how they treat a BOM.Scope notes
parsebranch ofreadFile. Raw (unparsed) reads feedrun-prettier, which writes its result back over the user's own file — stripping there would silently delete BOMs from source files people asked us to format. There is a spec pinning that behavior.keys-builder/utils/get-current-translation.tsis untouched: itsparseJsongoes throughfs-extra'sreadJsonSync, andjsonfilealready strips the BOM. Verified rather than assumed.HttpXhrBackendparses the response. This is a CLI-only gap.JSON.parsecall sites are left alone; those read workspace/package config, not translation files.Verification
libs/transloco-keys-manager/src/lib/tests/file.utils.spec.ts(4 tests) andlibs/transloco-optimize/src/lib/transloco-optimize.spec.ts(3 tests).transloco-optimizehad no specs at all before this, and the suite runs withpassWithNoTests: true, so the test count was confirmed to actually rise from 0 to 3 rather than the suite merely staying green.keys-managerstrip fails exactly its BOM spec (1 failed, 3 passed); reverting theoptimizestrip fails exactly its BOM spec (1 failed, 2 passed). Each spec guards its own site.transloco-keys-manager222 passed / 1 skipped across 21 files,transloco-optimize3 passed.nx lintclean for both projects (0 errors; the remaining warnings are pre-existingno-explicit-any).tsconfig.lib.jsonfiles already exclude**/*.spec.ts, so neither new spec is emitted intodistor the published packages.Related to #609. Does not close it — #1000 is the PR that addresses the reported case; this only brings the sibling tools in line.
Summary by CodeRabbit
Bug Fixes
Tests