fix: sort discovered locales for deterministic generator output#792
Open
KuceraMartin wants to merge 1 commit into
Open
fix: sort discovered locales for deterministic generator output#792KuceraMartin wants to merge 1 commit into
KuceraMartin wants to merge 1 commit into
Conversation
`getAllLocales` returned locale folders in the order `fs.readdir` yielded them, which is filesystem-dependent and not stable across platforms or runs. This caused the generated `Locales` type and `locales` array to be reordered on regeneration even when nothing changed, producing noisy diffs. Sort the discovered locales so the output is deterministic.
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.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.Tests
pnpm testand lint the project withpnpm lintProblem
getAllLocales(inpackages/shared/src/file.utils.mts) returns the localefolders in the order
fs.readdirhappens to yield them. That order isfilesystem-dependent and is not guaranteed to be stable across platforms
or even across runs on the same machine (e.g. APFS on macOS).
Because this order flows directly into the generated output, the
Localesunion type and the
localesarray get reordered whenever types areregenerated — even when no translations changed. For projects that commit
their generated
i18n-types.ts/i18n-util.ts, this produces recurring,noisy diffs like:
Fix
Sort the discovered locale folder names so the generated output is
deterministic regardless of the order returned by
fs.readdir. This is asingle
.sort()on the resultingstring[].Tests
Added
packages/generator/test/get-all-locales.test.ts, which feedsgetAllLocalesa mocked filesystem returning locale folders in an unsortedorder and asserts the result is sorted and independent of the input order.
The test fails on
mainand passes with this change.pnpm test(generator suite, 103 tests) andpnpm lintpass locally.