Skip to content

Commit 1d5aa4d

Browse files
committed
fix(bazel): conditionally add esbuild optimization plugins
This update prevents the inclusion of esbuild optimization plugins when both linking and downleveling are disabled. It also removes //shared-scripts/angular-optimization:js_lib from the spec-bundle unless explicit linking is required. This change addresses a circular dependency issue previously observed with this rule in the Angular CLI, leading to the removal of a related patch. For more details, see: https://github.com/angular/angular-cli/blob/3c9697a8c34a5e0f3470bde73f11f9f32107f42e/.yarn/patches/%40angular-build-tooling-https-06f4984cdf.patch
1 parent 7c95800 commit 1d5aa4d

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

bazel/spec-bundling/esbuild.config-tmpl.mjs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,38 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {createEsbuildAngularOptimizePlugin} from '@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs';
9+
const downlevelAsyncAwait = TMPL_DOWNLEVEL_ASYNC_AWAIT;
10+
const enableLinker = TMPL_RUN_LINKER;
11+
12+
// List of esbuild plugins.
13+
const plugins = [];
14+
if (enableLinker || downlevelAsyncAwait) {
15+
const {createEsbuildAngularOptimizePlugin} = await import(
16+
'@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs'
17+
);
18+
19+
plugins.push(
20+
await createEsbuildAngularOptimizePlugin({
21+
optimize: undefined,
22+
downlevelAsyncGeneratorsIfPresent: downlevelAsyncAwait,
23+
enableLinker: enableLinker
24+
? {
25+
ensureNoPartialDeclaration: true,
26+
linkerOptions: {
27+
// JIT mode is needed for tests overriding components/modules etc.
28+
linkerJitMode: true,
29+
unknownDeclarationVersionHandling: TMPL_LINKER_UNKNOWN_DECLARATION_HANDLING,
30+
},
31+
}
32+
: undefined,
33+
}),
34+
);
35+
}
1036

1137
// List of supported features as per ESBuild. See:
1238
// https://esbuild.github.io/api/#supported.
1339
const supported = {};
1440

15-
const downlevelAsyncAwait = TMPL_DOWNLEVEL_ASYNC_AWAIT;
16-
1741
// Async/Await can be downleveled so that ZoneJS can intercept. See:
1842
// https://github.com/angular/angular-cli/blob/afe9feaa45913/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts#L313-L318.
1943
if (downlevelAsyncAwait) {
@@ -35,20 +59,5 @@ export default {
3559
// https://esbuild.github.io/api/#keep-names.
3660
keepNames: true,
3761
supported,
38-
plugins: [
39-
await createEsbuildAngularOptimizePlugin({
40-
optimize: undefined,
41-
downlevelAsyncGeneratorsIfPresent: downlevelAsyncAwait,
42-
enableLinker: TMPL_RUN_LINKER
43-
? {
44-
ensureNoPartialDeclaration: true,
45-
linkerOptions: {
46-
// JIT mode is needed for tests overriding components/modules etc.
47-
linkerJitMode: true,
48-
unknownDeclarationVersionHandling: TMPL_LINKER_UNKNOWN_DECLARATION_HANDLING,
49-
},
50-
}
51-
: undefined,
52-
}),
53-
],
62+
plugins,
5463
};

bazel/spec-bundling/spec-bundle.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ def spec_bundle(
6060
linker_unknown_declaration_handling = linker_unknown_declaration_handling,
6161
)
6262

63+
esbuild_config_deps = []
64+
if run_angular_linker or downlevel_async_await:
65+
esbuild_config_deps = ["//shared-scripts/angular-optimization:js_lib"]
66+
6367
esbuild_config(
6468
name = "%s_config" % name,
6569
config_file = ":%s_config_file" % name,
6670
testonly = True,
67-
deps = ["//shared-scripts/angular-optimization:js_lib"],
71+
deps = esbuild_config_deps,
6872
)
6973

7074
if is_browser_test and not workspace_name:

0 commit comments

Comments
 (0)