@angular/localize should not depend on @angular/compiler

This issue has been created since 2022-11-22.

Which @angular/* package(s) are the source of the bug?


Is this a regression?



Currently @angular/localize depends on @angular/compiler https://github.com/angular/angular/blob/main/packages/localize/src/utils/src/messages.ts#L8

@angular/complier is a huge package that does not execute outside of node.js. For this reason, it is not possible to use it with edge functions.

Please provide a link to a minimal reproduction of the bug


Please provide the exception or error you saw

`@angular/compiler` can not be loaded at edge functions such as Cloudflare, Netlify, etc...

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

I think the computeMsgId should be in @angular/localize (and @angular/compiler can import it from there)

petebacondarwin wrote this answer on 2022-11-22

Yeah, I agree. I had planned to move it over but because the code was tightly bound to the ViewEngine digest it would have required code duplication. Hopefully now that ViewEngine is done, we can just move it over.

petebacondarwin wrote this answer on 2022-11-22

Although I see that it is still needed for legacy IDs... reversing the import dependency seems reasonable.

mhevery wrote this answer on 2022-11-22

I don't suppose that @petebacondarwin would be up for it?

AndrewKushnir wrote this answer on 2022-11-23

@mhevery thanks for creating this ticket!

Moving the computeMsgId function (and supporting code) to the @angular/localize and reversing the dependency (make @angular/compiler import @angular/localize) makes sense. This would also require some updates in g3, since we currently do not import the @angular/localize package. In this case, we can have a separate sub-package/entrypoint like @angular/localize/digest (which would only contain the message computation logic) and this would make it easier to import into g3 and minimize the code that the compiler package would depend on.

@petebacondarwin if you have some time to help with this (I see that you've assigned this ticket to yourself) - that'd be great and I can help with g3 side of things.

petebacondarwin wrote this answer on 2022-11-23

Voila! I am not sure if this counts as breaking. I thought there might be some G3 changes

AndrewKushnir wrote this answer on 2022-11-23

Thanks @petebacondarwin 👍

I was looking at it more and realized that we do not have the @angular/localize package in Angular apps by default (it's brought in after running ng add @angular/localize). In this case, if we move the code that compiler needs to the localize package, this would require us to always include @angular/localize by default. I'm wondering if a possible solution might be to have a sub-package in @angular/compiler instead (like @angular/compiler/digest) and use that sub-package as a dependency for the @angular/localize (instead of relying on the entire @angular/compiler). WDYT?

petebacondarwin wrote this answer on 2022-11-23

This is the main reason we avoided doing this in the first place. There is no easy solution.

There is no real reason why the function should be owned by the compiler any more than the localize package.
Interestingly, it is only needed by the compiler if the template uses i18n markers.

Perhaps in this case we could get away with a bit of code duplication, and just have the computeMsgId() function copied in both packages??

AndrewKushnir wrote this answer on 2022-11-23

There is no real reason why the function should be owned by the compiler any more than the localize package.
Interestingly, it is only needed by the compiler if the template uses i18n markers.

Yeah, we'd need to do some refactoring in the i18n subsystem in the compiler. Since ViewEngine code is removed, we could probably also remove/simplify some extra code that does translation extraction and merging.

Perhaps in this case we could get away with a bit of code duplication, and just have the computeMsgId() function copied in both packages??

This might be an option, but we'd need to make sure this code never diverges to ensure the message IDs computation is the same. We can put together some tests (to make sure key files are the same), but at this point it might be easier to create a sub-package inside a compiler? @petebacondarwin @clydin do you see any potential issues with this approach?

petebacondarwin wrote this answer on 2022-11-23

I don't suppose you would accept a bazel package that is consumed by both the localize and compiler packages?
That way there would be duplication in the final npm packages, but not in the source?

It seems a shame that if you want to use @angular/localize you have to also install @angular/compiler just to get access to @angular/compiler/digest and this one function.

mhevery wrote this answer on 2022-11-23

I don't see any issue either way but:

  • If we have a sub-package in the compiler for external systems such as Qwik, it is very strange that they now have to download a huge Angular compiler even though they don't need it. So aesthetically, this seems wrong. Looking forward long term if other systems would want to adopt $localize a dependency on angular compiler would be considered a problem
  • My personal favorite would be to just duplicate the code.
AndrewKushnir wrote this answer on 2022-11-23

I've replied on Pete's PR (#48178 (comment)), posting here for visibility as well: it looks like code duplication is the best option for now and we'll followup with extra cleanup to the i18n subsystem afterwards.

petebacondarwin wrote this answer on 2022-11-23

Regarding removing code that was there to support ViewEngine... is there a plan to remove the "legacy ID" support from i18n? This support results in quite a lot of the digest.ts code that could be removed otherwise.

petebacondarwin wrote this answer on 2022-11-23

As @JoostK points out, even if we move/copy the computeMsg() function to @angular/localize, it still depends upon @angular/compiler-cli (due to the need for imports like FileSystem, Logger, and source-map flattening in the localize tooling.
So when you install @angular/localize you are still going to get both @angular/compiler-cli and transiently @angular/compiler as well.

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2022-12-01
Star Count 85220
Watcher Count 3042
Fork Count 22607
Issue Count 1316


Issue Title Created Date Comment Count Updated Date
<inline asm>:1:1: error: unknown directive 2 2021-04-26 2022-08-02
Ability to use external player. 2 2021-10-01 2022-10-27
Uncaught (in promise) TypeError: h is not a function 2 2021-06-13 2022-11-22
[Addition]: EDA-IoT Cluster (7 HS) 1 2022-07-29 2022-08-06
Ajuda para teste Teste de unidade para o CommandHandler e assert do evento publicado 1 2021-05-20 2022-09-15
Docs issue with `setcap` 3 2022-01-13 2022-11-04
Using multithreading 2 2021-05-25 2022-11-10
Installing with curl doesn't work anymore 1 2022-10-17 2022-11-06
C stack overflow in error handler 11 2014-01-31 2022-11-15
use luasocket i get error 2 2021-06-27 2022-11-15
Get-Vsan or New-VsanDiskGroups failing with exception 3 2022-03-31 2022-11-13
Was senden wir für Scancodes und wie funktionieren Sonderzeichen? 5 2021-04-15 2022-11-05
defaultprops-typings.spec.tsx has wrong parameter name 0 2022-10-13 2022-11-11
sonoff Light has 3 power switch 2 2019-10-02 2022-11-23
Incrementing variable in custom script increments other variables not targetted 1 2022-01-28 2022-10-18
面试官:说说你对 TypeScript 中函数的理解?与 JavaScript 函数的区别? 0 2021-09-14 2022-10-03
[软技能] 第1115天 Service Worker是如何保证离线缓存资源更新的? 0 2022-05-04 2022-10-18
fixest::i() not playing nice with marginaleffects 7 2022-09-08 2022-10-05
routes.js refers to local disk 8 2021-08-25 2022-11-17
Add a TPM signature verifier example 0 2021-03-18 2022-11-09
Duplicate Identifier 'FilePondFile' 2 2021-07-24 2022-10-01
PKey.__cmp__ throws exception for all valid inputs 3 2021-08-25 2022-09-28
Billing Address must have a Correct Format 4 2021-11-18 2022-11-21
Triggered builds executed in the wrong order 2 2022-05-11 2022-11-12
Links clicked in Electron apps don't open in Firefox 8 2022-03-20 2022-11-10
Bring Lighthouse results page into a first-class results tempate (header, etc) 0 2022-02-03 2022-11-16
[Feature] Add a performers nav-tab on studio pages 1 2022-08-26 2022-11-18
Dynamo not working with REVIT2022 1 2021-04-25 2022-11-22
Allow home files symlinked to global location 2 2022-09-23 2022-11-09
Toolbars disappearing on Safari 2 2022-07-21 2022-08-18
指令操作显示后能否支持点击其他区域隐藏而不需要手动调用隐藏 3 2021-06-08 2022-11-15
drivers: qdec_sam: position measurement unstable if adc_sam_afec driver is enabled 0 2022-01-26 2022-02-05
doc should note if function return not curry function 2 2022-04-19 2022-11-05
DataTable: Payara IllegalArgumentException when using Array instead of List as selection value 18 2021-10-12 2022-11-09
[Question] StandardAuthenticator 用户认证模式如何找回admin 密码 1 2021-08-04 2022-08-04
4626-jee9-ref-page-corrections-rework 0 2021-11-22 2022-09-20
ys command not working 1 2022-07-07 2022-11-19
clusterfuzzlite: Deleting unaffected fuzzers should not happen when uploading a build 0 2021-09-27 2022-11-01
Set target platform automatically when creating sql project from database in VSCode 0 2022-09-09 2022-09-17
[FEATURE]API自动化场景调试报告-针对请求报文和响应报文可在页面上进行关键字搜索,便于找到未提取变量的出处 1 2022-06-27 2022-10-01
Need help for finding information and documents? Comment on this issue and someone will help you. 0 2021-06-08 2022-10-10
Header overlap with content issue 3 2021-07-29 2022-11-21
[Bug] [Kong]report trace info not working 6 2022-07-28 2022-08-25
Move Protocol Macro param docs to comment blocks in macro file 0 2022-08-10 2022-09-05
Would be great to add some social logo icons 0 2022-02-24 2022-10-06
Select GPU in case of multiple options 5 2022-11-10 2022-11-23
libraries-jitstress failure in System.Diagnostics.Tests.StackFrameTests.Ctor_FNeedFileInfo 18 2022-05-10 2022-10-16
Is there a way to specify option groups for a command? 4 2021-06-29 2022-09-29
Microsoft Security Advisory CVE 2022-23267 | .NET Denial of Service Vulnerability 1 2022-05-10 2022-11-29
I want to hover text color of my PopupMenuButton in Flutter. 3 2022-09-22 2022-11-22