Skip to content

Commit 0580230

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/build-angular): configure AOT compiler to skip class metadata in esbuild
The esbuild plugin used within the esbuild-based browser application builder will not use the newly introduced internal `supportTestBed` AOT compiler option to disable the emit of class metadata functions within the output code. This removes the need to perform an additional transformation of the AOT compiler generated code to immediately remove the class metadata. The class metadata is only needed when using TestBed with AOT generated code but testing infrastructure within the CLI only performs unit-testing in JIT mode. In the future event, that AOT enabled unit-testing is supported, this compiler option can be enabled for test related builds.
1 parent 3bc37e3 commit 0580230

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { buildApplication } from '../../index';
10+
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
11+
12+
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
13+
describe('Behavior: "Angular metadata"', () => {
14+
it('should not emit any AOT class metadata functions', async () => {
15+
harness.useTarget('build', {
16+
...BASE_OPTIONS,
17+
});
18+
19+
const { result } = await harness.executeOnce();
20+
expect(result?.success).toBe(true);
21+
22+
harness.expectFile('dist/main.js').content.not.toContain('setClassMetadata');
23+
});
24+
});
25+
});

packages/angular_devkit/build_angular/src/tools/esbuild/angular/angular-compilation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export abstract class AngularCompilation {
4545
allowEmptyCodegenFiles: false,
4646
annotationsAs: 'decorators',
4747
enableResourceInlining: false,
48+
supportTestBed: false,
4849
}),
4950
);
5051
}

0 commit comments

Comments
 (0)