Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): show warning when using TypeScrip…
Browse files Browse the repository at this point in the history
…t target older then ES2022 in esbuild builder

This commits adds a warning similar to that in the Webpack builder.
  • Loading branch information
alan-agius4 committed Oct 11, 2022
1 parent 0a196f8 commit 6c3f281
Showing 1 changed file with 21 additions and 2 deletions.
Expand Up @@ -169,6 +169,8 @@ export function createCompilerPlugin(
name: 'angular-compiler',
// eslint-disable-next-line max-lines-per-function
async setup(build: PluginBuild): Promise<void> {
let setupWarnings: PartialMessage[] | undefined;

// This uses a wrapped dynamic import to load `@angular/compiler-cli` which is ESM.
// Once TypeScript provides support for retaining dynamic imports this workaround can be dropped.
const compilerCli = await loadEsmModule<typeof import('@angular/compiler-cli')>(
Expand Down Expand Up @@ -223,7 +225,19 @@ export function createCompilerPlugin(
// which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
compilerOptions.target = ts.ScriptTarget.ES2022;
compilerOptions.useDefineForClassFields ??= false;
// TODO: show warning about this override when we have access to the logger.

(setupWarnings ??= []).push({
text:
'TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and ' +
'"false" respectively by the Angular CLI.',
location: { file: pluginOptions.tsconfig },
notes: [
{
text: `To control ECMA version and features use the Browerslist configuration. ' +
'For more information, see https://github.com/browserslist/browserslist#queries'`,
},
],
});
}

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

build.onStart(async () => {
const result: OnStartResult = {};
const result: OnStartResult = {
warnings: setupWarnings,
};

// Reset the setup warnings so that they are only shown during the first build.
setupWarnings = undefined;

// Reset debug performance tracking
resetCumulativeDurations();
Expand Down

0 comments on commit 6c3f281

Please sign in to comment.