From b2db6401cc0477232d2f5d3474e2a20309abfaac Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Mon, 18 Jan 2016 15:08:49 +0100 Subject: [PATCH] chore(build): remove use of q.denodeify This change also makes webpack properly reject promise on build errors Closes #6546 --- gulpfile.js | 10 ++++------ tools/build/webpack/promiseify.js | 32 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 tools/build/webpack/promiseify.js diff --git a/gulpfile.js b/gulpfile.js index 104677f0f8..31266f44f3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -717,12 +717,11 @@ gulp.task('build.payload.js', ['build.js'], function(done) { }); gulp.task('!build.payload.js.webpack', function() { - var q = require('q'); - var webpack = q.denodeify(require('webpack')); + var webpack = require('./tools/build/webpack/promiseify'); var ES5_PROD_ROOT = __dirname + '/' + CONFIG.dest.js.prod.es5; - return q.all(PAYLOAD_TESTS_CONFIG.ts.cases.map(function(caseName) { + return Promise.all(PAYLOAD_TESTS_CONFIG.ts.cases.map(function(caseName) { var CASE_PATH = PAYLOAD_TESTS_CONFIG.ts.dist(caseName, 'webpack'); return webpack({ @@ -1346,8 +1345,7 @@ gulp.task('!bundles.js.docs', ['clean'], function() { }); gulp.task('!bundles.js.umd', ['build.js.dev'], function() { - var q = require('q'); - var webpack = q.denodeify(require('webpack')); + var webpack = require('./tools/build/webpack/promiseify'); function resolveOptions(devOrProd) { return { @@ -1403,7 +1401,7 @@ gulp.task('!bundles.js.umd', ['build.js.dev'], function() { }; } - return q.all([ + return Promise.all([ webpack(webPackConf([__dirname + '/tools/build/webpack/angular2-all.umd.js'], 'angular2-all', 'dev')), webpack(webPackConf([__dirname + '/tools/build/webpack/angular2-all.umd.js'], 'angular2-all', diff --git a/tools/build/webpack/promiseify.js b/tools/build/webpack/promiseify.js new file mode 100644 index 0000000000..a4a8612a5b --- /dev/null +++ b/tools/build/webpack/promiseify.js @@ -0,0 +1,32 @@ +var webpack = require('webpack'); + +/** + * Wraps the original `webpack` function to convert execution + * result to a promise and properly report errors. + * + * @param options + * @returns {Function} + */ +function webPackPromiseify(options) { + + return new Promise(function (resolve, reject) { + + webpack(options, function(err, stats) { + var jsonStats = stats.toJson() || {}; + var statsErrors = jsonStats.errors || []; + + if (err) { + return reject(err); + } + + if (statsErrors.length) { + return reject(statsErrors); + } + + return resolve(stats); + }); + + }); +} + +module.exports = webPackPromiseify;