Skip to content

Commit 9ee3922

Browse files
hanslBrocco
authored andcommitted
feat(aot): do not populate the whole filesystem if nothing changed (#2490)
1 parent 2160003 commit 9ee3922

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

packages/angular-cli/models/webpack-build-typescript.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export const getWebpackAotConfigPartial = function(projectRoot: string, appConfi
6161
plugins: [
6262
new NgcWebpackPlugin({
6363
project: path.resolve(projectRoot, appConfig.root, appConfig.tsconfig),
64-
baseDir: path.resolve(projectRoot, ''),
64+
baseDir: path.resolve(projectRoot, appConfig.root),
6565
main: path.join(projectRoot, appConfig.root, appConfig.main),
66-
genDir: path.resolve(projectRoot, '')
66+
genDir: path.resolve(projectRoot, appConfig.root)
6767
}),
6868
]
6969
};

packages/webpack/src/compiler_host.ts

+8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
9191
private _delegate: ts.CompilerHost;
9292
private _files: {[path: string]: VirtualFileStats} = Object.create(null);
9393
private _directories: {[path: string]: VirtualDirStats} = Object.create(null);
94+
private _changed = false;
9495

9596
constructor(private _options: ts.CompilerOptions, private _setParentNodes = true) {
9697
this._delegate = ts.createCompilerHost(this._options, this._setParentNodes);
@@ -104,10 +105,15 @@ export class WebpackCompilerHost implements ts.CompilerHost {
104105
this._directories[p] = new VirtualDirStats(p);
105106
p = dirname(p);
106107
}
108+
109+
this._changed = true;
107110
}
108111

109112
populateWebpackResolver(resolver: any) {
110113
const fs = resolver.fileSystem;
114+
if (!this._changed) {
115+
return;
116+
}
111117

112118
for (const fileName of Object.keys(this._files)) {
113119
const stats = this._files[fileName];
@@ -121,6 +127,8 @@ export class WebpackCompilerHost implements ts.CompilerHost {
121127
fs._statStorage.data[path] = [null, stats];
122128
fs._readdirStorage.data[path] = [null, files.concat(dirs)];
123129
}
130+
131+
this._changed = false;
124132
}
125133

126134
fileExists(fileName: string): boolean {

packages/webpack/src/plugin.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ export class NgcWebpackPlugin {
9898
return callback();
9999
}
100100

101-
result.resource = this.genDir;
102-
result.recursive = true;
103-
result.dependencies.forEach((d: any) => d.critical = false);
104-
result.resolveDependencies = createResolveDependenciesFromContextMap((_: any, cb: any) => {
105-
return cb(null, this.lazyRoutes);
101+
this.done.then(() => {
102+
result.resource = this.genDir;
103+
result.recursive = true;
104+
result.dependencies.forEach((d: any) => d.critical = false);
105+
result.resolveDependencies = createResolveDependenciesFromContextMap(
106+
(_: any, cb: any) => cb(null, this.lazyRoutes));
107+
108+
return callback(null, result);
106109
});
107-
108-
return callback(null, result);
109110
});
110111
});
111112

@@ -119,7 +120,7 @@ export class NgcWebpackPlugin {
119120

120121
// Virtual file system.
121122
compiler.resolvers.normal.plugin('resolve', (request: any, cb?: () => void) => {
122-
// populate the file system cache with the virtual module
123+
// Populate the file system cache with the virtual module.
123124
this.compilerHost.populateWebpackResolver(compiler.resolvers.normal);
124125
if (cb) {
125126
cb();

tests/e2e/tests/test/e2e.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ export default function() {
1717
return expectToFail(() => ng('e2e'))
1818
// These should work.
1919
.then(() => _runServeAndE2e())
20-
.then(() => _runServeAndE2e('--prod'));
20+
.then(() => _runServeAndE2e('--prod'))
21+
.then(() => _runServeAndE2e('--aot'))
22+
.then(() => _runServeAndE2e('--aot', '--prod'));
2123
}

0 commit comments

Comments
 (0)