From 4097ea271de011ff680801439d7205059d225306 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Wed, 23 Aug 2017 13:36:14 +0100 Subject: [PATCH] fix(@ngtools/webpack): wait for plugin when resolving ts requests Fix #5137 --- packages/@ngtools/webpack/src/plugin.ts | 5 ++- tests/e2e/tests/build/aot/aot-rebuild.ts | 45 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/tests/build/aot/aot-rebuild.ts diff --git a/packages/@ngtools/webpack/src/plugin.ts b/packages/@ngtools/webpack/src/plugin.ts index 12261cc786dd..33b9021c3eac 100644 --- a/packages/@ngtools/webpack/src/plugin.ts +++ b/packages/@ngtools/webpack/src/plugin.ts @@ -378,8 +378,11 @@ export class AotPlugin implements Tapable { compiler.plugin('after-resolvers', (compiler: any) => { // Virtual file system. + // Wait for the plugin to be done when requesting `.ts` files directly (entry points), or + // when the issuer is a `.ts` file. compiler.resolvers.normal.plugin('before-resolve', (request: any, cb: () => void) => { - if (request.request.match(/\.ts$/)) { + if (request.request.endsWith('.ts') + || (request.context.issuer && request.context.issuer.endsWith('.ts'))) { this.done!.then(() => cb(), () => cb()); } else { cb(); diff --git a/tests/e2e/tests/build/aot/aot-rebuild.ts b/tests/e2e/tests/build/aot/aot-rebuild.ts new file mode 100644 index 000000000000..b8b3f012b0d8 --- /dev/null +++ b/tests/e2e/tests/build/aot/aot-rebuild.ts @@ -0,0 +1,45 @@ +import { + killAllProcesses, + waitForAnyProcessOutputToMatch, + execAndWaitForOutputToMatch, +} from '../../../utils/process'; +import { appendToFile } from '../../../utils/fs'; +import { getGlobalVariable } from '../../../utils/env'; +import { request } from '../../../utils/http'; +import { wait } from '../../../utils/utils'; + +const validBundleRegEx = /webpack: bundle is now VALID|webpack: Compiled successfully./; + +export default function () { + if (process.platform.startsWith('win')) { + return Promise.resolve(); + } + // Skip this in ejected tests. + if (getGlobalVariable('argv').eject) { + return Promise.resolve(); + } + + return execAndWaitForOutputToMatch('ng', ['serve', '--aot'], validBundleRegEx) + // Wait before editing a file. + // Editing too soon seems to trigger a rebuild and throw polling/watch out of whack. + .then(() => wait(2000)) + // Check AOT templates are up to date with current code. + .then(() => request('http://localhost:4200/main.bundle.js')) + .then((body) => { + if (body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) { + throw new Error('Expected golden value 1 to not be present.'); + } + }) + .then(() => appendToFile('src/app/app.component.html', '

$$_E2E_GOLDEN_VALUE_1

')) + .then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 20000)) + .then(() => request('http://localhost:4200/main.bundle.js')) + .then((body) => { + if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) { + throw new Error('Expected golden value 1.'); + } + }) + .then(() => killAllProcesses(), (err: any) => { + killAllProcesses(); + throw err; + }); +}