feat: add i18next-type-generator#30
Conversation
Port archid-components#273 to @wolfstar scope: new CLI for i18next type augmentations, remove LanguageKeys/T/FT helpers, and adopt namespace-aware TFunction typing across http-framework-i18n and shared-http-pieces. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Warning Review limit reached
More reviews will be available in 32 minutes and 23 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughIntroduces a new Changesi18next type generation and http-framework-i18n API overhaul
Sequence Diagram(s)sequenceDiagram
rect rgba(99, 179, 237, 0.5)
Note over Developer,Output: Type generation (build-time)
Developer->>CLI: i18next-type-generator src/locales/en-US src/@types/i18next.d.ts
CLI->>generate: generate([source, dest], {verbose, prettier, oxfmt})
generate->>FS: recurse(source) — read all .json namespace files
FS-->>generate: namespace/key entries
generate->>Prettier: attempt oxfmt, fall back to Prettier
Prettier-->>generate: formatted TypeScript
generate->>Output: annotate + write CustomTypeOptions module
end
rect rgba(154, 205, 50, 0.5)
Note over SharedCommand,i18next: Runtime translation (Discord interaction)
SharedCommand->>getSupportedUserLanguageName: interaction → lng
getSupportedUserLanguageName-->>SharedCommand: locale string
SharedCommand->>getT: getT(lng, 'commands/shared')
getT->>i18next: getFixedT(locale, namespace)
i18next-->>getT: TFunction~'commands/shared'~
SharedCommand->>t: t('infoEmbedDescription', {...})
t-->>SharedCommand: localized translated string
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #30 +/- ##
==========================================
+ Coverage 51.00% 54.98% +3.98%
==========================================
Files 51 53 +2
Lines 896 982 +86
Branches 202 231 +29
==========================================
+ Hits 457 540 +83
Misses 435 435
- Partials 4 7 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a59e63d. Configure here.
The CLI parsed --indentation but generate ignored it and always used hardcoded tab indentation for the output structure and embedded JSON.
There was a problem hiding this comment.
Actionable comments posted: 9
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/http-framework-i18n/package.json (1)
19-23:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd the missing
homepagefield to satisfy package metadata requirements.This manifest currently omits
homepage, which is required by the package.json guideline.Suggested change
"repository": { "type": "git", "url": "git+https://github.com/wolfstar-project/stars-components.git", "directory": "packages/http-framework-i18n" }, + "homepage": "https://github.com/wolfstar-project/stars-components/tree/main/packages/http-framework-i18n",As per coding guidelines, "Each package must declare: name, author (scope handle), repository.url, bugs.url, homepage, and keywords in package.json."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/http-framework-i18n/package.json` around lines 19 - 23, The package.json file for http-framework-i18n is missing the required `homepage` field at the root level of the manifest. Add the `homepage` field to the package.json to include a URL pointing to the package's directory in the GitHub repository. This field should be placed alongside other metadata fields like repository, bugs, and keywords to satisfy the package metadata requirements guideline.Source: Coding guidelines
packages/shared-http-pieces/package.json (1)
2-23:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd missing
homepagemetadata in this package manifest.
packages/shared-http-pieces/package.jsonis missing the requiredhomepagefield.Proposed fix
"bugs": { "url": "https://github.com/wolfstar-project/stars-components/issues" }, + "homepage": "https://github.com/wolfstar-project/stars-components/tree/main/packages/shared-http-pieces", "license": "Apache-2.0",As per coding guidelines,
packages/*/package.json: "Each package must declare: name, author (scope handle), repository.url, bugs.url, homepage, and keywords in package.json".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/shared-http-pieces/package.json` around lines 2 - 23, The packages/shared-http-pieces/package.json file is missing the required `homepage` field as mandated by the coding guidelines for package manifests. Add a `homepage` field to the package.json file with an appropriate value that references the GitHub repository URL for this package directory, following the pattern of the existing repository.url and directory fields. This field should be placed among the other metadata fields like author, bugs, and repository to maintain consistency with the package manifest structure.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/i18next-type-generator/CHANGELOG.md`:
- Around line 3-5: The CHANGELOG.md file in packages/i18next-type-generator
contains version entries (the "3.0.1" header and "Initial release under the
`@wolfstar` scope." text) that should be removed according to coding guidelines.
Delete all version and body entries from this CHANGELOG file, leaving only the
package header as specified in the guidelines. The file should contain only the
header section with no version history entries.
In `@packages/i18next-type-generator/package.json`:
- Around line 15-24: The package.json for packages/i18next-type-generator is
missing the required homepage field. Add a homepage field to the package
manifest that points to the repository's homepage URL (typically derived from
the repository URL already present in the file). This field is mandatory
according to the repository's coding guidelines for all package.json files in
the packages directory.
In `@packages/i18next-type-generator/README.md`:
- Around line 14-18: The README is missing documentation for the `-i,
--indentation` option that the CLI now supports. Add this option to the options
list in the README (in the same format as the other options like --no-prettier)
to include both the short form -i and long form --indentation with a
description. Additionally, locate the paragraph around line 43 that states
formatting options are not provided and update it to acknowledge that the
indentation option is now available as a formatting option.
In `@packages/i18next-type-generator/src/cli.ts`:
- Around line 12-17: In the indentationParser function, after parsing the value
to a number and checking for NaN, add additional validation to ensure the parsed
number is both non-negative and an integer before calling the repeat method. If
the number is negative or not an integer (such as 2.5 or Infinity), throw an
InvalidArgumentError with a descriptive message explaining that indentation must
be a non-negative integer or the string "tabs". This prevents RangeError
exceptions from repeat() and rejects silently truncated decimal values.
- Around line 27-29: The cli.parse() method is being used with an async action
handler that calls the generate function, which returns a Promise. Replace
cli.parse(process.argv) with cli.parseAsync(process.argv) to properly handle the
asynchronous command action and ensure that any errors from the generate
function are consistently propagated by Commander.
In `@packages/i18next-type-generator/src/generate.ts`:
- Around line 21-34: The current code iterates through directory entries in the
order returned by opendir, which is filesystem-dependent and causes
non-deterministic output. To fix this, collect all directory entries from the
opendir call into an array, sort that array by the dirent.name property, and
then iterate through the sorted array in the for loop. This ensures that files
and directories are always processed in the same consistent order regardless of
the filesystem, making the generated .d.ts output deterministic across different
machines and CI environments.
- Around line 27-30: The key assignment in the file processing logic emits
unquoted keys for root-level files (when namespace is falsy), which generates
invalid TypeScript for filenames containing special characters like hyphens. In
the line where the key constant is assigned, wrap the name value in quotes for
both the namespace and non-namespace cases by changing the conditional to always
produce a quoted string literal, ensuring filenames like my-file.json generate
'my-file' instead of an unquoted my-file.
- Around line 68-76: The prettier import and formatting logic in the if
(options.prettier) block will crash if prettier is not installed, even though it
is declared as an optional dependency. Wrap the entire block containing the
await import('prettier') statement and the subsequent format call in a try-catch
block to gracefully handle the case where prettier is unavailable. In the catch
block, log a warning or error message (using the verbose flag if appropriate)
and allow the generation to continue with the unformatted source instead of
crashing.
In `@packages/shared-http-pieces/src/`@types/i18next-custom.d.ts:
- Around line 5-9: The CustomTypeOptions.resources interface for
'commands/shared' is currently split across the auto-generated i18next.d.ts file
and this manual i18next-custom.d.ts file, creating maintenance friction. Remove
the infoEmbedDescription property definition from the
resources['commands/shared'] object in this custom augmentation and instead add
it to the source locale JSON file that generates i18next.d.ts. Then regenerate
i18next.d.ts to include the infoEmbedDescription property definition in a single
consolidated location. This ensures all type definitions for commands/shared
resources are maintained in one place rather than split across auto-generated
and manual files.
---
Outside diff comments:
In `@packages/http-framework-i18n/package.json`:
- Around line 19-23: The package.json file for http-framework-i18n is missing
the required `homepage` field at the root level of the manifest. Add the
`homepage` field to the package.json to include a URL pointing to the package's
directory in the GitHub repository. This field should be placed alongside other
metadata fields like repository, bugs, and keywords to satisfy the package
metadata requirements guideline.
In `@packages/shared-http-pieces/package.json`:
- Around line 2-23: The packages/shared-http-pieces/package.json file is missing
the required `homepage` field as mandated by the coding guidelines for package
manifests. Add a `homepage` field to the package.json file with an appropriate
value that references the GitHub repository URL for this package directory,
following the pattern of the existing repository.url and directory fields. This
field should be placed among the other metadata fields like author, bugs, and
repository to maintain consistency with the package manifest structure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d8ae9fe4-b9c4-46e8-915d-2fde62e8a3b1
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (25)
.npm-deprecaterc.ymlREADME.mdpackages/http-framework-i18n/README.mdpackages/http-framework-i18n/package.jsonpackages/http-framework-i18n/src/index.tspackages/http-framework-i18n/src/lib/functions.tspackages/http-framework-i18n/src/lib/registry.tspackages/http-framework-i18n/src/lib/types.tspackages/http-framework-i18n/src/lib/utils.tspackages/i18next-type-generator/CHANGELOG.mdpackages/i18next-type-generator/README.mdpackages/i18next-type-generator/package.jsonpackages/i18next-type-generator/src/cli.tspackages/i18next-type-generator/src/generate.tspackages/i18next-type-generator/tsdown.config.tspackages/shared-http-pieces/package.jsonpackages/shared-http-pieces/src/@types/i18next-custom.d.tspackages/shared-http-pieces/src/@types/i18next.d.tspackages/shared-http-pieces/src/commands/info.tspackages/shared-http-pieces/src/index.tspackages/shared-http-pieces/src/lib/i18n/LanguageKeys.tspackages/shared-http-pieces/src/lib/i18n/LanguageKeys/All.tspackages/shared-http-pieces/src/lib/i18n/LanguageKeys/Commands/All.tspackages/shared-http-pieces/src/lib/i18n/LanguageKeys/Commands/Shared.tsscripts/clean.mjs
💤 Files with no reviewable changes (8)
- packages/shared-http-pieces/src/lib/i18n/LanguageKeys/All.ts
- packages/http-framework-i18n/src/lib/functions.ts
- packages/shared-http-pieces/src/index.ts
- packages/shared-http-pieces/src/lib/i18n/LanguageKeys.ts
- packages/shared-http-pieces/src/lib/i18n/LanguageKeys/Commands/Shared.ts
- packages/http-framework-i18n/src/lib/types.ts
- packages/http-framework-i18n/src/index.ts
- packages/shared-http-pieces/src/lib/i18n/LanguageKeys/Commands/All.ts
- Replace `commander` with `citty` for command-line interface handling. - Add support for `oxfmt` and `prettier` formatting options in the generation process. - Introduce file annotations to suppress linting and formatting issues in generated files. - Update package dependencies and scripts, including the addition of a test script using `vitest`. - Improve README documentation to reflect new features and usage instructions.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/i18next-type-generator/src/cli.ts`:
- Around line 35-40: The default value for the indentation option is set to a
literal tab character `'\t'`, but the parseIndentation function expects the
sentinel string `'tabs'` to recognize and properly handle tab indentation.
Change the default value from `'\t'` to `'tabs'` in the indentation option
definition to ensure it matches what parseIndentation expects. This same
inconsistency also appears at another location in the file (lines 62-63) so
apply the same fix there as well.
In `@packages/shared-http-pieces/src/`@types/i18next.d.ts:
- Around line 10-26: The translation key infoEmbedDescription is referenced in
the info.ts file but is missing from both the type definitions and locale files.
Add the infoEmbedDescription key to the CustomTypeOptions interface under the
"commands/shared" resources object in the i18next.d.ts file (similar to the
other keys shown in the diff like infoName, infoDescription, etc.) with an
appropriate string value. Additionally, add the infoEmbedDescription translation
key to all locale JSON files located in src/locales/*/commands/shared.json with
appropriate translations for each language to ensure the type definitions and
runtime translations are synchronized.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 372c0e9f-4a05-4471-a54e-b4592e68161c
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
packages/i18next-type-generator/README.mdpackages/i18next-type-generator/package.jsonpackages/i18next-type-generator/src/cli.tspackages/i18next-type-generator/src/generate.tspackages/i18next-type-generator/tests/generate.test.tspackages/i18next-type-generator/vitest.config.tspackages/shared-http-pieces/src/@types/i18next.d.ts
- Remove initial release notes from CHANGELOG.md for clarity. - Update README.md to include the new `--indentation` option for controlling output formatting.
…eration features - Introduce tests for CLI commands including version and help flags. - Validate type generation with various indentation options and error handling for invalid inputs. - Implement tests for fallback mechanisms when formatting fails with `oxfmt` and `prettier`. - Ensure cleanup of temporary directories after tests to maintain isolation.



🔗 Linked issue
Port of skyra-project/archid-components#273
🧭 Context
The original ArchId Network monorepo introduced
@skyra/i18next-type-generatorto replace hand-maintainedLanguageKeysand legacyT/FTtype helpers with i18next v23+ native TypeScript support. This PR ports that work tostars-componentsunder the@wolfstarscope.📚 Description
Adds
@wolfstar/i18next-type-generator, a CLI that walks locale JSON files and emits ani18nextCustomTypeOptionsaugmentation. Updates@wolfstar/http-framework-i18nto i18next v25 with namespace-awaregetT/getSupportedLanguageThelpers, and removes the deprecatedT,FT,resolveKey, andresolveUserKeyAPIs.@wolfstar/shared-http-piecesdropsLanguageKeysin favour of generated types and directTFunction<'commands/shared'>usage.Key changes
LanguageKeys+T()/FT()@wolfstar/i18next-type-generatorCLIhttp-framework-i18nTFunctionaugmentationshared-http-piecesLanguageKeys.Commands.Shared.*keyst('infoFieldUptimeTitle')with typed namespace3.0.1semverType of Change
Pre-flight Checklist
Summary by CodeRabbit
@wolfstar/i18next-type-generatorCLI for generating i18next TypeScript declaration files from locale JSON.LocalePrefixKey-style key approach; some previous helper exports and LanguageKeys-style constants were removed/updated.