robrich / gulp-if

Conditionally run a task
MIT License
655 stars 26 forks source link

surprising behavior in gulp-util.combine(gulp-if) #17

Closed disruptek closed 10 years ago

disruptek commented 10 years ago

This may well be related to #13 or #6, but here's a small test that may be useful:

var gulp = require('gulp');
var util = require('gulp-util');
var gif = require('gulp-if');
var log = require('gulp-filelog');

gulp.task('works1', function() {
        combined = util.combine(
                log('A'));
        gulp.src('test/*').pipe(combined()).pipe(log('C'));
});

gulp.task('works2', function() {
        combined = util.combine(
                log('A'),
                log('B'));
        gulp.src('test/*').pipe(combined()).pipe(log('C'));
});

gulp.task('broken1', function() {
        combined = util.combine(
                gif(true, log('A')));
        gulp.src('test/*').pipe(combined()).pipe(log('C'));
});

gulp.task('broken2', function() {
        combined = util.combine(
                gif(true, log('A')),
                gif(true, log('B')));
        gulp.src('test/*').pipe(combined()).pipe(log('C'));
});

Output against a directory with two files in it:

[gulp] Running 'works1'...
[gulp] Finished 'works1' in 7.17 ms
[gulp] [A] [1] [test/five]
[gulp] [C] [1] [test/five]
[gulp] [A] [2] [test/four]
[gulp] [C] [2] [test/four]
[gulp] [A] Found [2] files.

[gulp] Running 'works2'...
[gulp] Finished 'works2' in 8.56 ms
[gulp] [A] [1] [test/five]
[gulp] [B] [1] [test/five]
[gulp] [C] [1] [test/five]
[gulp] [A] [2] [test/four]
[gulp] [B] [2] [test/four]
[gulp] [C] [2] [test/four]
[gulp] [A] Found [2] files.

[gulp] Running 'broken1'...
[gulp] Finished 'broken1' in 7.22 ms
[gulp] [A] [1] [test/five]
[gulp] [C] [1] [test/five]
[gulp] [A] [2] [test/four]
[gulp] [C] [2] [test/four]
[gulp] [A] Found [2] files.
[gulp] [C] Found [2] files.

[gulp] Running 'broken2'...
[gulp] Finished 'broken2' in 8.47 ms
[gulp] [A] [1] [test/five]
[gulp] [B] [1] [test/five]
[gulp] [C] [1] [test/five]
disruptek commented 10 years ago

Took a closer look at this and it seems to be due to gulpjs/gulp-util#27; the lazypipe substitution for gulp-util.combine solves the problem. Sorry for the noise.