Skip to content

fix(formatjs_cli): sort key before serializing#5833

Closed
longlho wants to merge 1 commit intomainfrom
01-05-feat_formatjs_cli_sort_key_before_serializing
Closed

fix(formatjs_cli): sort key before serializing#5833
longlho wants to merge 1 commit intomainfrom
01-05-feat_formatjs_cli_sort_key_before_serializing

Conversation

@longlho
Copy link
Member

@longlho longlho commented Jan 6, 2026

TL;DR

Switched to sorted message keys in formatjs_cli and refactored ID generation into a dedicated module.

What changed?

  • Changed from HashMap to BTreeMap in compile and extract modules to ensure consistent, alphabetically sorted message keys in output files
  • Extracted ID generation logic into a new dedicated module id_generator.rs
  • Added comprehensive tests to verify sorting behavior and ID generation
  • Updated Bazel build files to include the new module

How to test?

  1. Run the formatjs CLI to extract or compile messages:

    formatjs extract "src/**/*.tsx" --out-file messages.json
    formatjs compile messages.json --out-file compiled.json
    
  2. Verify that the output JSON files have keys sorted alphabetically

  3. Test ID generation with different patterns:

    formatjs extract "src/**/*.tsx" --out-file messages.json --id-interpolation-pattern "[sha512:contenthash:hex:8]"
    

Why make this change?

  • Sorted keys provide consistent, deterministic output files, making diffs more meaningful and easier to review
  • Sorted keys improve version control by reducing unnecessary changes when only message order differs
  • The dedicated ID generator module improves code organization and maintainability
  • Comprehensive tests ensure the sorting behavior works correctly across different formatters and output types

@longlho longlho marked this pull request as ready for review January 6, 2026 02:00
@graphite-app
Copy link

graphite-app bot commented Jan 6, 2026

Merge activity

  • Jan 6, 2:04 AM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 6, 2:04 AM UTC: CI is running for this pull request on a draft pull request (#5834) due to your merge queue CI optimization settings.
  • Jan 6, 2:07 AM UTC: Merged by the Graphite merge queue via draft PR: #5834.

graphite-app bot pushed a commit that referenced this pull request Jan 6, 2026
### TL;DR

Switched to sorted message keys in formatjs_cli and refactored ID generation into a dedicated module.

### What changed?

- Changed from `HashMap` to `BTreeMap` in compile and extract modules to ensure consistent, alphabetically sorted message keys in output files
- Extracted ID generation logic into a new dedicated module `id_generator.rs`
- Added comprehensive tests to verify sorting behavior and ID generation
- Updated Bazel build files to include the new module

### How to test?

1. Run the formatjs CLI to extract or compile messages:
   ```
   formatjs extract "src/**/*.tsx" --out-file messages.json
   formatjs compile messages.json --out-file compiled.json
   ```

2. Verify that the output JSON files have keys sorted alphabetically

3. Test ID generation with different patterns:
   ```
   formatjs extract "src/**/*.tsx" --out-file messages.json --id-interpolation-pattern "[sha512:contenthash:hex:8]"
   ```

### Why make this change?

- Sorted keys provide consistent, deterministic output files, making diffs more meaningful and easier to review
- Sorted keys improve version control by reducing unnecessary changes when only message order differs
- The dedicated ID generator module improves code organization and maintainability
- Comprehensive tests ensure the sorting behavior works correctly across different formatters and output types
@longlho longlho force-pushed the 01-05-feat_formatjs_cli_sort_key_before_serializing branch from 5a71a12 to 6013fc1 Compare January 6, 2026 02:05
Copy link
Member Author

longlho commented Jan 6, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • main - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@graphite-app graphite-app bot closed this Jan 6, 2026
@graphite-app graphite-app bot deleted the 01-05-feat_formatjs_cli_sort_key_before_serializing branch January 6, 2026 02:07
@longlho longlho changed the title feat(formatjs_cli): sort key before serializing fix(formatjs_cli): sort key before serializing Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant