提交 59c4f24c 编写于 作者: J Joao Moreno

gulp: beware of es.merge and empty arrays

fixes the internal builds
上级 fa614d82
...@@ -135,29 +135,33 @@ exports.optimizeTask = function(opts) { ...@@ -135,29 +135,33 @@ exports.optimizeTask = function(opts) {
var loaderConfig = opts.loaderConfig; var loaderConfig = opts.loaderConfig;
var bundledFileHeader = opts.header; var bundledFileHeader = opts.header;
var out = opts.out; var out = opts.out;
return function() { return function() {
var bundles = es.through(); var bundlesStream = es.through();
bundle.bundle(entryPoints, loaderConfig, function(err, result) { 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(); var otherSourcesStream = es.through();
(function() {
var otherSourcesStreamArr = []; var otherSourcesStreamArr = [];
gulp.src(otherSources, { base: 'out-build' }) gulp.src(otherSources, { base: 'out-build' })
.pipe(es.through(function write(data) { .pipe(es.through(function (data) {
otherSourcesStreamArr.push(toConcatStream(bundledFileHeader, [data], data.relative)); otherSourcesStreamArr.push(toConcatStream(bundledFileHeader, [data], data.relative));
}, function end() { }, function () {
if (!otherSourcesStreamArr.length) {
setTimeout(function () { otherSourcesStream.emit('end'); }, 0);
} else {
es.merge(otherSourcesStreamArr).pipe(otherSourcesStream); es.merge(otherSourcesStreamArr).pipe(otherSourcesStream);
})) }
})(); }));
var result = es.merge( var result = es.merge(
loader(bundledFileHeader), loader(bundledFileHeader),
bundles, bundlesStream,
otherSourcesStream, otherSourcesStream,
gulp.src(resources, { base: 'out-build' }) gulp.src(resources, { base: 'out-build' })
); );
......
...@@ -2,7 +2,8 @@ declare module "event-stream" { ...@@ -2,7 +2,8 @@ declare module "event-stream" {
import { Stream } from 'stream'; import { Stream } from 'stream';
import { ThroughStream } from 'through'; 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 concat(...stream: Stream[]): ThroughStream;
function duplex(istream: Stream, ostream: Stream): ThroughStream; function duplex(istream: Stream, ostream: Stream): ThroughStream;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册