Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@ngtools/webpack): invalidate all the files changed #4542

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ export class AotPlugin implements Tapable {
apply(compiler: any) {
this._compiler = compiler;

compiler.plugin('invalid', (fileName: string) => {
compiler.plugin('invalid', () => {
// Turn this off as soon as a file becomes invalid and we're about to start a rebuild.
this._firstRun = false;
this._diagnoseFiles = {};

this._compilerHost.invalidate(fileName);
compiler.watchFileSystem.watcher.once('aggregated', (changes: string[]) => {
changes.forEach((fileName: string) => this._compilerHost.invalidate(fileName));
});
});

// Add lazy modules to the context module for @angular/core/src/linker
Expand Down
30 changes: 29 additions & 1 deletion tests/e2e/tests/build/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
silentExecAndWaitForOutputToMatch,
ng,
} from '../../utils/process';
import {writeFile} from '../../utils/fs';
import {writeFile, writeMultipleFiles, appendToFile, expectFileToMatch} from '../../utils/fs';
import {wait} from '../../utils/utils';
import {request} from '../../utils/http';


export default function() {
Expand Down Expand Up @@ -69,6 +70,33 @@ export default function() {
throw new Error('Expected webpack to create a new chunk, but did not.');
}
})
.then(() => wait(1000))
// Change multiple files and check that all of them are invalidated and recompiled.
.then(() => writeMultipleFiles({
'src/app/app.module.ts': `
console.log('$$_E2E_GOLDEN_VALUE_1');
export let X = '$$_E2E_GOLDEN_VALUE_2';
`,
'src/main.ts': `
import * as m from './app/app.module';
console.log(m.X);
console.log('$$_E2E_GOLDEN_VALUE_3');
`
}))
.then(() => waitForAnyProcessOutputToMatch(
/webpack: bundle is now VALID|webpack: Compiled successfully./, 10000))
.then(() => request('http://localhost:4200/main.bundle.js'))
.then((body) => {
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
throw new Error('Expected golden value 1.');
}
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_2/)) {
throw new Error('Expected golden value 2.');
}
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_3/)) {
throw new Error('Expected golden value 3.');
}
})
.then(() => killAllProcesses(), (err: any) => {
killAllProcesses();
throw err;
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ export function copyFile(from: string, to: string) {
}


export function writeMultipleFiles(fs: any) {
return Object.keys(fs)
.reduce((previous, curr) => {
return previous.then(() => writeFile(curr, fs[curr]));
}, Promise.resolve());
export function writeMultipleFiles(fs: { [path: string]: string }) {
return Promise.all(Object.keys(fs).map(fileName => writeFile(fileName, fs[fileName])));
}


Expand Down