Skip to content

Commit 9459cde

Browse files
committed
fix(@angular-devkit/build-angular): show warning when using TypeScript target older then ES2022 in esbuild builder
This commits adds a warning similar to that in the Webpack builder.
1 parent 0a196f8 commit 9459cde

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ export function createCompilerPlugin(
169169
name: 'angular-compiler',
170170
// eslint-disable-next-line max-lines-per-function
171171
async setup(build: PluginBuild): Promise<void> {
172+
let setupWarnings: PartialMessage[] | undefined;
173+
172174
// This uses a wrapped dynamic import to load `@angular/compiler-cli` which is ESM.
173175
// Once TypeScript provides support for retaining dynamic imports this workaround can be dropped.
174176
const compilerCli = await loadEsmModule<typeof import('@angular/compiler-cli')>(
@@ -223,7 +225,19 @@ export function createCompilerPlugin(
223225
// which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
224226
compilerOptions.target = ts.ScriptTarget.ES2022;
225227
compilerOptions.useDefineForClassFields ??= false;
226-
// TODO: show warning about this override when we have access to the logger.
228+
229+
(setupWarnings ??= []).push({
230+
text:
231+
'TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and ' +
232+
'"false" respectively by the Angular CLI.',
233+
location: { file: pluginOptions.tsconfig },
234+
notes: [
235+
{
236+
text: `To control ECMA version and features use the Browerslist configuration. ' +
237+
'For more information, see https://github.com/browserslist/browsers§list'`,
238+
},
239+
],
240+
});
227241
}
228242

229243
// The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
@@ -237,7 +251,12 @@ export function createCompilerPlugin(
237251
const babelDataCache = new Map<string, string>();
238252

239253
build.onStart(async () => {
240-
const result: OnStartResult = {};
254+
const result: OnStartResult = {
255+
warnings: setupWarnings,
256+
};
257+
258+
// Reset the setup warnings so that they are only shown during the first build.
259+
setupWarnings = undefined;
241260

242261
// Reset debug performance tracking
243262
resetCumulativeDurations();

0 commit comments

Comments
 (0)