Skip to content

Commit b526672

Browse files
committed
fix(@ngtools/webpack): wait for plugin when resolving ts requests
Fix angular#5137
1 parent d6c07c7 commit b526672

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

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

379379
compiler.plugin('after-resolvers', (compiler: any) => {
380380
// Virtual file system.
381+
// Wait for the plugin to be done when requesting `.ts` files directly (entry points), or
382+
// when the issuer is a `.ts` file.
381383
compiler.resolvers.normal.plugin('before-resolve', (request: any, cb: () => void) => {
382-
if (request.request.match(/\.ts$/)) {
384+
if (request.request.endsWith('.ts')
385+
|| (request.context.issuer && request.context.issuer.endsWith('.ts'))) {
383386
this.done!.then(() => cb(), () => cb());
384387
} else {
385388
cb();
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
10+
const validBundleRegEx = /webpack: bundle is now VALID|webpack: Compiled successfully./;
11+
12+
export default function () {
13+
if (process.platform.startsWith('win')) {
14+
return Promise.resolve();
15+
}
16+
// Skip this in ejected tests.
17+
if (getGlobalVariable('argv').eject) {
18+
return Promise.resolve();
19+
}
20+
21+
return execAndWaitForOutputToMatch('ng', ['serve', '--aot'], validBundleRegEx)
22+
// Check AOT templates are up to date with current code.
23+
.then(() => request('http://localhost:4200/main.bundle.js'))
24+
.then((body) => {
25+
if (body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
26+
throw new Error('Expected golden value 1 to not be present.');
27+
}
28+
})
29+
.then(() => console.log('before append'))
30+
.then(() => appendToFile('src/app/app.component.html', '<p> $$_E2E_GOLDEN_VALUE_1 </p>'))
31+
.then(() => console.log('after append'))
32+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 20000))
33+
.then(() => request('http://localhost:4200/main.bundle.js'))
34+
.then((body) => {
35+
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
36+
throw new Error('Expected golden value 1.');
37+
}
38+
})
39+
.then(() => killAllProcesses(), (err: any) => {
40+
killAllProcesses();
41+
throw err;
42+
});
43+
}

0 commit comments

Comments
 (0)