Commit 3f21898
Make locale generation idempotent with force flag support (#2093)
## Summary
Makes the `react_on_rails:locale` rake task idempotent - it now skips
generation when locale files are already up-to-date. This eliminates
duplicate work when the task is called multiple times (e.g., in
Shakapacker's `precompile_hook`).
## Key Changes
**Idempotent Generation Logic**
- Added timestamp checking to skip generation when output files are
newer than source YAML files
- Returns early with message: "Locale files are up to date, skipping
generation"
- Prevents unnecessary rebuilds during development and CI
**Force Regeneration Option**
- Added `force=true` parameter to override timestamp checking
- Usage: `rake react_on_rails:locale force=true`
- Useful when you need to force regeneration regardless of timestamps
**RBS Type Signatures**
- Added comprehensive type signatures in
`sig/react_on_rails/locales.rbs`
- Covers `Locales::Base`, `Locales::ToJs`, and `Locales::ToJson` classes
- Improves type safety for the locale generation system
**User Feedback**
- Prints confirmation message when files are generated
- Prints skip message when files are up-to-date
- Clear messaging improves debugging experience
## Use Cases
**Safe for Shakapacker's precompile_hook:**
```yaml
# config/shakapacker.yml
default: &default
precompile_hook: 'bundle exec rake react_on_rails:locale'
```
Now safe to call multiple times without performance penalty - subsequent
calls skip instantly.
**Development workflow:**
```bash
bundle exec rake react_on_rails:locale # First call generates files
bundle exec rake react_on_rails:locale # Subsequent calls skip if up-to-date
bundle exec rake react_on_rails:locale force=true # Force regeneration
```
## Implementation Details
**Timestamp Comparison:**
- Compares mtime of YAML source files against output files
- Considers outdated if: no output files exist OR any YAML file is newer
than oldest output file
- Edge case handled: empty locale_files array returns true (outdated)
**Force Parameter Flow:**
- Passed from rake task → `Locales.compile(force:)` → `Base.new(force:)`
- Bypasses timestamp check when `force: true`
- Defaults to `false` for backward compatibility
## Testing
- ✅ Added tests for force parameter passing through compile chain
- ✅ Added test for force regeneration with future timestamps
- ✅ Existing tests verify timestamp-based skipping behavior
## Documentation
Updated `docs/building-features/i18n.md` to explain:
- Idempotent behavior and benefits
- Usage with Shakapacker's precompile_hook
- Force flag usage examples
## Breaking Changes
None - idempotent behavior is backward compatible.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Locale generation task is idempotent and will skip work when files are
up-to-date.
* Added a force=true option to bypass timestamp checks and force
regeneration.
* Task now emits clear notices when skipping or generating locale files.
* **Documentation**
* Updated i18n guidance with examples, auto-run (precompile hook)
configuration, and force usage.
* **Tests**
* Added tests verifying force=true forces regeneration and is propagated
through the compile flow.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude <[email protected]>1 parent f91737d commit 3f21898
File tree
7 files changed
+122
-9
lines changed- docs/building-features
- lib
- react_on_rails/locales
- tasks
- sig/react_on_rails
- spec/react_on_rails
7 files changed
+122
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
24 | 37 | | |
25 | 38 | | |
26 | | - | |
| 39 | + | |
27 | 40 | | |
28 | 41 | | |
29 | 42 | | |
30 | 43 | | |
31 | | - | |
32 | | - | |
33 | 44 | | |
34 | 45 | | |
35 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
42 | 52 | | |
43 | 53 | | |
44 | 54 | | |
| 55 | + | |
45 | 56 | | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| 63 | + | |
52 | 64 | | |
53 | 65 | | |
54 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | | - | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
39 | 55 | | |
40 | 56 | | |
41 | 57 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
53 | 73 | | |
54 | 74 | | |
55 | 75 | | |
| |||
0 commit comments