Skip to content

Commit d61b252

Browse files
Alanalexeagle
Alan
authored andcommitted
fix(@ngtools/webpack): rebuilding project with errors reports cannot find .ts files in JIT
When the first build in JIT has an error we are not emitting files. This ends up causing an issue because subsequent builds only trigger partial emits of files and only emits the full set of files if the number of files changed is greater than 20. This logic adds the behavior that we only enter the 'only 20 files' part when the previous build was successful. Fixes #14644
1 parent 7f251b2 commit d61b252

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

packages/angular_devkit/build_angular/test/browser/rebuild_spec_large.ts

+42-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { Architect } from '@angular-devkit/architect';
1111
import { TestLogger } from '@angular-devkit/architect/testing';
12-
import { normalize, virtualFs } from '@angular-devkit/core';
12+
import { logging, normalize, virtualFs } from '@angular-devkit/core';
1313
import { debounceTime, take, takeWhile, tap } from 'rxjs/operators';
1414
import { createArchitect, host, lazyModuleFiles, lazyModuleStringImport } from '../utils';
1515

@@ -68,14 +68,11 @@ describe('Browser Builder rebuilds', () => {
6868

6969
const overrides = { watch: true };
7070

71-
let buildCount = 0;
7271
let phase = 1;
7372
const run = await architect.scheduleTarget(target, overrides);
7473
await run.output.pipe(
7574
tap(result => {
7675
expect(result.success).toBe(true, 'build should succeed');
77-
buildCount++;
78-
7976
const hasLazyChunk = host.scopedSync().exists(normalize('dist/lazy-lazy-module.js'));
8077
switch (phase) {
8178
case 1:
@@ -205,6 +202,47 @@ describe('Browser Builder rebuilds', () => {
205202
).toPromise();
206203
});
207204

205+
it('rebuilds after errors in JIT', async () => {
206+
const origContent = virtualFs.fileBufferToString(
207+
host.scopedSync().read(normalize('src/app/app.component.ts')));
208+
host.appendToFile('./src/app/app.component.ts', `console.logg('error')`);
209+
210+
const overrides = { watch: true, aot: false };
211+
let buildNumber = 0;
212+
const logger = new logging.Logger('');
213+
let logs: string[] = [];
214+
logger.subscribe(e => logs.push(e.message));
215+
216+
const run = await architect.scheduleTarget(target, overrides, { logger });
217+
await run.output.pipe(
218+
debounceTime(1000),
219+
tap((buildEvent) => {
220+
buildNumber ++;
221+
switch (buildNumber) {
222+
case 1:
223+
// The first build should error out with an error.
224+
expect(buildEvent.success).toBe(false);
225+
expect(logs.join()).toContain(`Property 'logg' does not exist on type 'Console'`);
226+
logs = [];
227+
// Fix the error.
228+
host.writeMultipleFiles({ 'src/app/app.component.ts': `
229+
${origContent}
230+
console.errorr('error');
231+
`});
232+
break;
233+
234+
case 2:
235+
// The second build should have everything fixed.
236+
expect(buildEvent.success).toBe(true);
237+
expect(logs.join()).not.toContain('Module build failed');
238+
break;
239+
}
240+
}),
241+
take(2),
242+
).toPromise();
243+
await run.stop();
244+
});
245+
208246
it('rebuilds after errors in AOT', async () => {
209247
// Save the original contents of `./src/app/app.component.ts`.
210248
const origContent = virtualFs.fileBufferToString(

packages/ngtools/webpack/src/angular_compiler_plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ export class AngularCompilerPlugin {
11921192
'AngularCompilerPlugin._emit.ts', diagMode));
11931193

11941194
if (!hasErrors(allDiagnostics)) {
1195-
if (this._firstRun || changedTsFiles.size > 20) {
1195+
if (this._firstRun || changedTsFiles.size > 20 || this._emitSkipped) {
11961196
emitResult = tsProgram.emit(
11971197
undefined,
11981198
undefined,

0 commit comments

Comments
 (0)