Skip to content

Commit 8db0703

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

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-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();
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
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', ['build', '--watch'], validBundleRegEx)
22+
// Check AOT templates are up to date with current code.
23+
.then(() => expectToFail(() =>
24+
expectFileToMatch('dist/main.bundle.js', '$$_E2E_GOLDEN_VALUE_1')))
25+
.then(() => appendToFile('./src/app/app.component.html', '<p> $$_E2E_GOLDEN_VALUE_1 </p>'))
26+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 10000))
27+
.then(() => expectFileToMatch('dist/main.bundle.js', '$$_E2E_GOLDEN_VALUE_1'))
28+
.then(() => killAllProcesses(), (err: any) => {
29+
killAllProcesses();
30+
throw err;
31+
});
32+
}

0 commit comments

Comments
 (0)