just-jeb / angular-builders

Angular build facade extensions (Jest and custom webpack configuration)
MIT License
1.14k stars 198 forks source link

fix(custom-esbuild): add extract-i18n builder #1711

Closed kamilchlebek closed 5 months ago

kamilchlebek commented 7 months ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

We successfully switched from using webpack to esbuild thanks to @angular-builders/custom-esbuild:application.

However once we tried to extract i18n messages our xlf file had 0 items inside.

It turned out that angular checks builder name to decide whether to use webpack/esbuild strategy - https://github.com/angular/angular-cli/blob/c2b8d84e360f0508e73f7c502516f898f067c03b/packages/angular_devkit/build_angular/src/builders/extract-i18n/builder.ts#L64-L65

What is the new behavior?

Proposed @angular-builders/custom-esbuild:extract-i18n builder temporarily overrides builder name, strips unsupported configuration options and then runs default @angular-devkit/build-angular:extract-i18n builder.

For the reference, nx is doing the same: https://github.com/nrwl/nx/pull/21802

Does this PR introduce a breaking change?

[ ] Yes
[x] No
just-jeb commented 7 months ago

Hey, thanks for submitting the PR! One question - wouldn't removing plugins mean that the build flow and the extract flow might be different and therefore the extraction might not work as expected?

kamilchlebek commented 7 months ago

That's very good question! I'll dig deeper to find out if this may or may not be the issue.

kamilchlebek commented 7 months ago

@just-jeb

Here are my latest findings. Unfortunately without help from angular team I can't do more (https://github.com/angular/angular-cli/issues/27264).

Currently there's no way to have exactly the same build & extract flow - angular will not pass any extensions when executing i18n builder:

https://github.com/angular/angular-cli/blob/1034bb155b58a5f18eecf56409a3ff99d2ca4474/packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts#L59

just-jeb commented 7 months ago

@kamilchlebek thanks for the update. Seems like we're blocked here until Angular CLI implement your request. Probably submitting a PR could speed it up.

Side note: they won't expose the plugins functionality directly from Angular CLI builders, this has been their official policy and that's the reason custom builders exist 😄.

just-jeb commented 5 months ago

Closing until it's unblocked