Skip to content

Commit 1973972

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

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-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();
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
killAllProcesses,
3+
waitForAnyProcessOutputToMatch,
4+
execAndWaitForOutputToMatch,
5+
} from '../../../utils/process';
6+
import { appendToFile, expectFileToMatch } from '../../../utils/fs';
7+
import { expectToFail } from '../../../utils/utils';
8+
import { getGlobalVariable } from '../../../utils/env';
9+
import { request } from '../../../utils/http';
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+
// Check AOT templates are up to date with current code.
24+
.then(() => request('http://localhost:4200/main.bundle.js'))
25+
.then((body) => {
26+
if (body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
27+
throw new Error('Expected golden value 1 to not be present.');
28+
}
29+
})
30+
.then(() => appendToFile('./src/app/app.component.html', '<p> $$_E2E_GOLDEN_VALUE_1 </p>'))
31+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 10000))
32+
.then(() => request('http://localhost:4200/main.bundle.js'))
33+
.then((body) => {
34+
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
35+
throw new Error('Expected golden value 1.');
36+
}
37+
})
38+
.then(() => killAllProcesses(), (err: any) => {
39+
killAllProcesses();
40+
throw err;
41+
});
42+
}

0 commit comments

Comments
 (0)