From 59c4f24c488d518b6a7da12b530cf1f1d825957c Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Sat, 21 Nov 2015 14:40:41 +0100 Subject: [PATCH] gulp: beware of es.merge and empty arrays fixes the internal builds --- build/gulpfile.common.js | 28 ++++++++++++++++------------ build/lib/typings/event-stream.d.ts | 3 ++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/build/gulpfile.common.js b/build/gulpfile.common.js index b7ebd035e87..ea703727b0c 100644 --- a/build/gulpfile.common.js +++ b/build/gulpfile.common.js @@ -135,29 +135,33 @@ exports.optimizeTask = function(opts) { var loaderConfig = opts.loaderConfig; var bundledFileHeader = opts.header; var out = opts.out; + return function() { - var bundles = es.through(); + var bundlesStream = es.through(); bundle.bundle(entryPoints, loaderConfig, function(err, result) { - if (err) { return bundles.emit('error', JSON.stringify(err)); } + if (err) { return bundlesStream.emit('error', JSON.stringify(err)); } - toBundleStream(bundledFileHeader, result).pipe(bundles); + toBundleStream(bundledFileHeader, result).pipe(bundlesStream); }); var otherSourcesStream = es.through(); - (function() { - var otherSourcesStreamArr = []; - gulp.src(otherSources, { base: 'out-build' }) - .pipe(es.through(function write(data) { - otherSourcesStreamArr.push(toConcatStream(bundledFileHeader, [data], data.relative)); - }, function end() { + var otherSourcesStreamArr = []; + + gulp.src(otherSources, { base: 'out-build' }) + .pipe(es.through(function (data) { + otherSourcesStreamArr.push(toConcatStream(bundledFileHeader, [data], data.relative)); + }, function () { + if (!otherSourcesStreamArr.length) { + setTimeout(function () { otherSourcesStream.emit('end'); }, 0); + } else { es.merge(otherSourcesStreamArr).pipe(otherSourcesStream); - })) - })(); + } + })); var result = es.merge( loader(bundledFileHeader), - bundles, + bundlesStream, otherSourcesStream, gulp.src(resources, { base: 'out-build' }) ); diff --git a/build/lib/typings/event-stream.d.ts b/build/lib/typings/event-stream.d.ts index 6906a0d8679..2867c3eff36 100644 --- a/build/lib/typings/event-stream.d.ts +++ b/build/lib/typings/event-stream.d.ts @@ -2,7 +2,8 @@ declare module "event-stream" { import { Stream } from 'stream'; import { ThroughStream } from 'through'; - function merge(...stream: Stream[]): ThroughStream; + function merge(streams: Stream[]): ThroughStream; + function merge(...streams: Stream[]): ThroughStream; function concat(...stream: Stream[]): ThroughStream; function duplex(istream: Stream, ostream: Stream): ThroughStream; -- GitLab