Repository navigation
refactor(@angular/build): avoid loading localize tools and babel in i18n inliner worker - #34194
Conversation
…18n inliner worker Previously, `i18n-inliner-worker.ts` dynamically loaded `@angular/localize/tools` to invoke its `translate()` function and `Diagnostics` class. Importing `@angular/localize/tools` eagerly pulls in `@babel/core`, `@angular/compiler-cli`, and `@angular/compiler`, consuming ~180 ms of CPU latency and ~32 MB of heap per worker thread upon first translation. Since the inliner only performs string translation replacements using AST locations already discovered via OXC, the full Babel transformation and compiler tooling bundle is unnecessary. This updates `i18n-inliner-worker.ts` to directly import low-level runtime functions (`ɵtranslate`, `ɵisMissingTranslationError`, `ɵmakeTemplateObject`) from `@angular/localize` and manage diagnostics via a direct message array. This completely avoids loading `@angular/localize/tools` and its heavy transitive dependencies.
There was a problem hiding this comment.
Code Review
This pull request refactors the i18n inliner worker to remove the dependency on @angular/localize/tools by directly utilizing low-level runtime functions from @angular/localize for message translation. Feedback on the changes suggests improving error handling in the new translateMessage function by verifying that the caught error is an instance of Error before accessing its message property, preventing potential runtime issues.
…el in i18n inliner worker
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Previously,
i18n-inliner-worker.tsdynamically loaded@angular/localize/toolsto invoke itstranslate()function andDiagnosticsclass. Importing@angular/localize/toolseagerly pulls in@babel/core,@angular/compiler-cli, and@angular/compiler, consuming ~180 ms of CPU latency and ~32 MB of heap per worker thread upon first translation.Since the inliner only performs string translation replacements using AST locations already discovered via OXC, the full Babel transformation and compiler tooling bundle is unnecessary.
This updates
i18n-inliner-worker.tsto directly import low-level runtime functions (ɵtranslate,ɵisMissingTranslationError,ɵmakeTemplateObject) from@angular/localizeand manage diagnostics via a direct message array. This completely avoids loading@angular/localize/toolsand its heavy transitive dependencies.