fix: support TypeScript 7 and Bun for locale file transpilation - #795
Open
shadoworion wants to merge 1 commit into
Open
fix: support TypeScript 7 and Bun for locale file transpilation#795shadoworion wants to merge 1 commit into
shadoworion wants to merge 1 commit into
Conversation
TypeScript 7 (the Go-based compiler) no longer ships the JavaScript
compiler API: 'ts.createProgram' does not exist and the package's main
entry only exposes version information. The generator now resolves a
transpilation strategy at runtime:
1. Bun: locale files are bundled with the native 'Bun.build' API —
no 'typescript' installation needed at all
2. TypeScript <= 6: the existing 'ts.createProgram' path, now behind a
lazy import with feature detection
3. TypeScript 7: the installed package's 'tsc' CLI is spawned with the
same compiler flags (emit still happens despite '--noLib' type
errors, so the exit code is ignored)
The TypeScript version used for feature-gating the generated syntax is
detected lazily as well ('versionMajorMinor', then the package.json
version, then a modern default), so a missing or API-less 'typescript'
package no longer crashes the CLI, importer or exporter at import time.
'typescript' is now an optional peer dependency for Bun-only setups.
Also fixes a missing 'await' in 'detectLocationOfCompiledBaseTranslation'
that made its early-return dead code.
Ref: codingcommons#794
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
TypeScript 7 (the Go-based compiler, stable since
typescript@7.0.x) no longer ships the JavaScript compiler API:ts.createProgramdoes not exist and the package's main entry only exposes version information. This breaks the generator withts.createProgram is not a function.Fixes #794
Solution
The generator now resolves a transpilation strategy for locale files at runtime:
process.versions.bun): locale files are bundled with the nativeBun.buildAPI — notypescriptinstallation needed at allts.createProgrampath, unchanged, but behind a lazy import with feature detection (typeof ts.createProgram === 'function')tscCLI is spawned (process.execPath+bin/tsc, no shell) with the same compiler flags;tscemits even when it reports type errors (guaranteed because of--noLib), so the exit code is ignored and success is determined by the emitted filesThe TypeScript version used for feature-gating the generated syntax (
satisfies, template literal types, …) is detected lazily as well:versionMajorMinor→typescript/package.jsonversion → a modern default. A missing or API-lesstypescriptpackage therefore no longer crashes the CLI, importer or exporter at module-import time.typescriptis now an optional peer dependency for Bun-only setups.Also fixes a pre-existing bug: a missing
awaitoncontainsFolders()indetectLocationOfCompiledBaseTranslationmade its early-return dead code.Verification
tsc --noEmit+ eslint pass; e2e run against a sample project (dictionary with JSON import) produces output identical to the published package7.0.x, dictionary parsed via the spawnedtscCLI (all flags accepted by the native compiler), correct types generatedtypescriptinstalled (Node): graceful info log (assuming version >= 5.5) and an actionable error messagetypescriptinstalled, watch mode regenerates types on dictionary changes, bothTypeScriptandJavaScript(module.exports) output formats work, JSON imports are bundled natively🤖 Generated with Claude Code