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(webpack): fix some problems with errors not reported. #3444

Merged
merged 1 commit into from
Dec 7, 2016
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
51 changes: 26 additions & 25 deletions packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ export class AotPlugin implements Tapable {
});

// Virtual file system.
compiler.resolvers.normal.plugin('resolve', (request: any, cb?: () => void) => {
compiler.resolvers.normal.plugin('resolve', (request: any, cb?: (err?: any) => void) => {
if (request.request.match(/\.ts$/)) {
this.done.then(() => cb());
this.done
.then(() => cb())
.catch((err) => cb(err));
} else {
cb();
}
Expand All @@ -212,9 +214,8 @@ export class AotPlugin implements Tapable {

private _make(compilation: any, cb: (err?: any, request?: any) => void) {
this._compilation = compilation;

if (this._compilation._ngToolsWebpackPluginInstance) {
cb(new Error('An @ngtools/webpack plugin already exist for this compilation.'));
return cb(new Error('An @ngtools/webpack plugin already exist for this compilation.'));
}
this._compilation._ngToolsWebpackPluginInstance = this;

Expand All @@ -227,28 +228,28 @@ export class AotPlugin implements Tapable {
basePath: this.basePath
};

let promise = Promise.resolve();
if (!this._skipCodeGeneration) {
// Create the Code Generator.
const codeGenerator = ngCompiler.CodeGenerator.create(
this._angularCompilerOptions,
i18nOptions,
this._program,
this._compilerHost,
new ngCompiler.NodeReflectorHostContext(this._compilerHost),
this._resourceLoader
);

// We need to temporarily patch the CodeGenerator until either it's patched or allows us
// to pass in our own ReflectorHost.
// TODO: remove this.
patchReflectorHost(codeGenerator);
promise = promise.then(() => codeGenerator.codegen({
transitiveModules: true
}));
}
this._donePromise = Promise.resolve()
.then(() => {
if (this._skipCodeGeneration) {
return;
}

this._donePromise = promise
// Create the Code Generator.
const codeGenerator = ngCompiler.CodeGenerator.create(
this._angularCompilerOptions,
i18nOptions,
this._program,
this._compilerHost,
new ngCompiler.NodeReflectorHostContext(this._compilerHost),
this._resourceLoader
);

// We need to temporarily patch the CodeGenerator until either it's patched or allows us
// to pass in our own ReflectorHost.
// TODO: remove this.
patchReflectorHost(codeGenerator);
return codeGenerator.codegen({ transitiveModules: true });
})
.then(() => {
// Create a new Program, based on the old one. This will trigger a resolution of all
// transitive modules, which include files that might just have been generated.
Expand Down
17 changes: 15 additions & 2 deletions packages/angular-cli/tasks/build-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NgCliWebpackConfig } from '../models/webpack-config';
import { getWebpackStatsConfig } from '../models/';
import { CliConfig } from '../models/config';


// Configure build and output;
let lastHash: any = null;

Expand Down Expand Up @@ -36,7 +37,9 @@ export default <any>Task.extend({

return new Promise((resolve, reject) => {
webpackCompiler.run((err: any, stats: any) => {
if (err) { return reject(err); }
if (err) {
return reject(err);
}

// Don't keep cache
// TODO: Make conditional if using --watch
Expand All @@ -47,8 +50,18 @@ export default <any>Task.extend({
process.stdout.write(stats.toString(statsConfig) + '\n');
}

return stats.hasErrors() ? reject() : resolve();
if (stats.hasErrors()) {
reject();
} else {
resolve();
}
});
})
.catch((err: Error) => {
if (err) {
this.ui.writeError('\nAn error occured during the build:\n' + ((err && err.stack) || err));
}
throw err;
});
}
});
4 changes: 1 addition & 3 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ export default Task.extend({

const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
return new Promise((resolve, reject) => {
server.listen(serveTaskOptions.port,
`${serveTaskOptions.host}`,
function(err: any, stats: any) {
server.listen(serveTaskOptions.port, `${serveTaskOptions.host}`, (err: any, stats: any) => {
if (err) {
console.error(err.stack || err);
if (err.details) { console.error(err.details); }
Expand Down