Skip to content

Commit 182ecbd

Browse files
committed
fix(@angular/build): allow explicitly disabling TypeScript incremental mode
If the TypeScript `incremental` option is explicitly set to `false`, the `application` builder will no longer attempt to enable and use incremental compilation mode via stored TypeScript build file information. This prevents an potential build time error that would otherwise occur due to the `tsBuildInfoFile` option being set without the `incremental` option. Behavior remains the same if the option is not present or set to `true`.
1 parent da2a6bd commit 182ecbd

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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: "TypeScript explicit incremental option usage"', () => {
14+
it('should successfully build with incremental disabled', async () => {
15+
// Disable tsconfig incremental option in tsconfig
16+
await harness.modifyFile('tsconfig.json', (content) => {
17+
const tsconfig = JSON.parse(content);
18+
tsconfig.compilerOptions.incremental = false;
19+
20+
return JSON.stringify(tsconfig);
21+
});
22+
23+
harness.useTarget('build', {
24+
...BASE_OPTIONS,
25+
});
26+
27+
const { result } = await harness.executeOnce();
28+
29+
expect(result?.success).toBe(true);
30+
});
31+
});
32+
});

packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export function createCompilerPlugin(
284284
location: null,
285285
notes: [
286286
{
287-
text: error instanceof Error ? error.stack ?? error.message : `${error}`,
287+
text: error instanceof Error ? (error.stack ?? error.message) : `${error}`,
288288
location: null,
289289
},
290290
],
@@ -315,7 +315,7 @@ export function createCompilerPlugin(
315315
location: null,
316316
notes: [
317317
{
318-
text: error instanceof Error ? error.stack ?? error.message : `${error}`,
318+
text: error instanceof Error ? (error.stack ?? error.message) : `${error}`,
319319
location: null,
320320
},
321321
],
@@ -537,9 +537,12 @@ function createCompilerOptionsTransformer(
537537
compilerOptions.compilationMode = 'full';
538538
}
539539

540-
// Enable incremental compilation by default if caching is enabled
541-
if (pluginOptions.sourceFileCache?.persistentCachePath) {
542-
compilerOptions.incremental ??= true;
540+
// Enable incremental compilation by default if caching is enabled and incremental is not explicitly disabled
541+
if (
542+
compilerOptions.incremental !== false &&
543+
pluginOptions.sourceFileCache?.persistentCachePath
544+
) {
545+
compilerOptions.incremental = true;
543546
// Set the build info file location to the configured cache directory
544547
compilerOptions.tsBuildInfoFile = path.join(
545548
pluginOptions.sourceFileCache?.persistentCachePath,

0 commit comments

Comments
 (0)