Skip to content

fix(bazel): conditionally add esbuild optimization plugins #2243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions bazel/spec-bundling/esbuild.config-tmpl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,38 @@
* found in the LICENSE file at https://angular.io/license
*/

import {createEsbuildAngularOptimizePlugin} from '@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs';
const downlevelAsyncAwait = TMPL_DOWNLEVEL_ASYNC_AWAIT;
const enableLinker = TMPL_RUN_LINKER;

// List of esbuild plugins.
const plugins = [];
if (enableLinker || downlevelAsyncAwait) {
const {createEsbuildAngularOptimizePlugin} = await import(
'@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs'
);

plugins.push(
await createEsbuildAngularOptimizePlugin({
optimize: undefined,
downlevelAsyncGeneratorsIfPresent: downlevelAsyncAwait,
enableLinker: enableLinker
? {
ensureNoPartialDeclaration: true,
linkerOptions: {
// JIT mode is needed for tests overriding components/modules etc.
linkerJitMode: true,
unknownDeclarationVersionHandling: TMPL_LINKER_UNKNOWN_DECLARATION_HANDLING,
},
}
: undefined,
}),
);
}

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

const downlevelAsyncAwait = TMPL_DOWNLEVEL_ASYNC_AWAIT;

// Async/Await can be downleveled so that ZoneJS can intercept. See:
// https://github.com/angular/angular-cli/blob/afe9feaa45913/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts#L313-L318.
if (downlevelAsyncAwait) {
Expand All @@ -35,20 +59,5 @@ export default {
// https://esbuild.github.io/api/#keep-names.
keepNames: true,
supported,
plugins: [
await createEsbuildAngularOptimizePlugin({
optimize: undefined,
downlevelAsyncGeneratorsIfPresent: downlevelAsyncAwait,
enableLinker: TMPL_RUN_LINKER
? {
ensureNoPartialDeclaration: true,
linkerOptions: {
// JIT mode is needed for tests overriding components/modules etc.
linkerJitMode: true,
unknownDeclarationVersionHandling: TMPL_LINKER_UNKNOWN_DECLARATION_HANDLING,
},
}
: undefined,
}),
],
plugins,
};
6 changes: 5 additions & 1 deletion bazel/spec-bundling/spec-bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ def spec_bundle(
linker_unknown_declaration_handling = linker_unknown_declaration_handling,
)

esbuild_config_deps = []
if run_angular_linker or downlevel_async_await:
esbuild_config_deps = ["//shared-scripts/angular-optimization:js_lib"]

esbuild_config(
name = "%s_config" % name,
config_file = ":%s_config_file" % name,
testonly = True,
deps = ["//shared-scripts/angular-optimization:js_lib"],
deps = esbuild_config_deps,
)

if is_browser_test and not workspace_name:
Expand Down