Skip to content

Commit aa34b28

Browse files
filipesilvahansl
authored andcommitted
fix(@ngtools/webpack): wait for plugin when resolving ts requests
Fix #5137
1 parent df7e631 commit aa34b28

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

packages/@ngtools/webpack/src/plugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,11 @@ export class AotPlugin implements Tapable {
382382

383383
compiler.plugin('after-resolvers', (compiler: any) => {
384384
// Virtual file system.
385+
// Wait for the plugin to be done when requesting `.ts` files directly (entry points), or
386+
// when the issuer is a `.ts` file.
385387
compiler.resolvers.normal.plugin('before-resolve', (request: any, cb: () => void) => {
386-
if (request.request.match(/\.ts$/)) {
388+
if (request.request.endsWith('.ts')
389+
|| (request.context.issuer && request.context.issuer.endsWith('.ts'))) {
387390
this.done!.then(() => cb(), () => cb());
388391
} else {
389392
cb();
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
killAllProcesses,
3+
waitForAnyProcessOutputToMatch,
4+
execAndWaitForOutputToMatch,
5+
} from '../../../utils/process';
6+
import { appendToFile } from '../../../utils/fs';
7+
import { getGlobalVariable } from '../../../utils/env';
8+
import { request } from '../../../utils/http';
9+
import { wait } from '../../../utils/utils';
10+
11+
const validBundleRegEx = /webpack: bundle is now VALID|webpack: Compiled successfully./;
12+
13+
export default function () {
14+
if (process.platform.startsWith('win')) {
15+
return Promise.resolve();
16+
}
17+
// Skip this in ejected tests.
18+
if (getGlobalVariable('argv').eject) {
19+
return Promise.resolve();
20+
}
21+
22+
return execAndWaitForOutputToMatch('ng', ['serve', '--aot'], validBundleRegEx)
23+
// Wait before editing a file.
24+
// Editing too soon seems to trigger a rebuild and throw polling/watch out of whack.
25+
.then(() => wait(2000))
26+
// Check AOT templates are up to date with current code.
27+
.then(() => request('http://localhost:4200/main.bundle.js'))
28+
.then((body) => {
29+
if (body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
30+
throw new Error('Expected golden value 1 to not be present.');
31+
}
32+
})
33+
.then(() => appendToFile('src/app/app.component.html', '<p> $$_E2E_GOLDEN_VALUE_1 </p>'))
34+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 20000))
35+
.then(() => request('http://localhost:4200/main.bundle.js'))
36+
.then((body) => {
37+
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
38+
throw new Error('Expected golden value 1.');
39+
}
40+
})
41+
.then(() => killAllProcesses(), (err: any) => {
42+
killAllProcesses();
43+
throw err;
44+
});
45+
}

0 commit comments

Comments
 (0)