gulp-if
gulp-if copied to clipboard
Stream doesn't end when using fn as condition.
When I use a function as condition, stream never ends. An example probably works best.
In this case, everything ends up in dist, and stream ends.
gulp.task('copy', function() {
return gulp
.src('path/to/stuff')
.pipe(gulpif(false, fail())
.pipe(gulp.dest('dist');
});
So in console you see:
Staring 'copy'...
Finished 'copy' after 4ms
In the function case everything still ends up in dist, but stream doesn't end.
function returnfalse() { return false }
gulp.task('copy', function() {
return gulp
.src('path/to/stuff')
.pipe(gulpif(returnfalse, fail())
.pipe(gulp.dest('dist');
});
In console you see:
Starting 'copy'...
[process exits]
Obviously this is an issue because we need the stream to end for other tasks to know it completed (it can't be a dependency task otherwise).
Am I doing something wrong? It seems like these cases should behave identically.
Do you have a gist or pastebin or example github repo that demonstrates this behavior?
Sure, I created a repo that shows each scenario. Had to point to a different version of gulp-fail
since that was broken also.
Run through each task. When fail is invoked we don't expect the stream to end of course (since we exit early). But when we move through successfully, end should be called, and yet it is only called when a a boolean is passed. I've seen this a number of times, and clearly whoever created gulp-exit has also. If I have time, I'll track it down, and submit a PR, but currently I don't have the time.
FWIW this is running in node v5.2
I'm wondering if 6 years later, there is a solution... as I face the same problem.