Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/build): ensure full rebuild after initial error build in watch mode #29568

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export async function* runEsBuildBuildAction(
return;
}

// Used to force a full result on next rebuild if there were initial errors.
// This ensures at least one full result is emitted.
let hasInitialErrors = result.errors.length > 0;

// Wait for changes and rebuild as needed
const currentWatchFiles = new Set(result.watchFiles);
try {
Expand Down Expand Up @@ -201,10 +205,13 @@ export async function* runEsBuildBuildAction(
result,
outputOptions,
changes,
incrementalResults ? rebuildState : undefined,
incrementalResults && !hasInitialErrors ? rebuildState : undefined,
)) {
yield outputResult;
}

// Clear initial build errors flag if no errors are now present
hasInitialErrors &&= result.errors.length > 0;
}
} finally {
// Stop the watcher and cleanup incremental rebuild state
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { concatMap, count, take, timeout } from 'rxjs';
import { executeDevServer } from '../../index';
import { describeServeBuilder } from '../jasmine-helpers';
import { BASE_OPTIONS, BUILD_TIMEOUT, DEV_SERVER_BUILDER_INFO } from '../setup';
import { logging } from '@angular-devkit/core';

describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
describe('Behavior: "Rebuild Error Detection"', () => {
beforeEach(() => {
setupTarget(harness);
});

it('Emits full build result with incremental enabled and initial build has errors', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
watch: true,
});

// Missing ending `>` on the div will cause an error
await harness.appendToFile('src/app/app.component.html', '<div>Hello, world!</div');

const buildCount = await harness
.execute({ outputLogsOnFailure: false })
.pipe(
timeout(BUILD_TIMEOUT),
concatMap(async ({ result, logs }, index) => {
switch (index) {
case 0:
expect(result?.success).toBeFalse();
debugger;
expect(logs).toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('Unexpected character "EOF"'),
}),
);

await harness.appendToFile('src/app/app.component.html', '>');

break;
case 1:
expect(result?.success).toBeTrue();
expect(logs).not.toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('Unexpected character "EOF"'),
}),
);
break;
}
}),
take(2),
count(),
)
.toPromise();

expect(buildCount).toBe(2);
});
});
});
2 changes: 2 additions & 0 deletions packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export async function* serveWithVite(
},
});
}

yield { baseUrl: '', success: false };
continue;
}
// Clear existing error overlay on successful result
Expand Down
6 changes: 6 additions & 0 deletions tests/legacy-cli/e2e/tests/build/jit-ngmodule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export default async function () {
};
}

// Remove bundle budgets due to the increased size from JIT
build.configurations.production = {
...build.configurations.production,
budgets: undefined,
};

build.options.aot = false;
});
// Test it works
Expand Down