sindresorhus/gulp-debug

gulp-debug inside gulp-if gives misleading information

Closed this issue · 2 comments

I setup gulp-debug as a stream action of gulp-if and this prevents the debug output EXCEPT for the summary information.

For example when run in my gulp 'copy.js.dev' plugin:

gulp.src(normalFiles)
     .pipe(gulpif(debugout, debug({title:'copy.js.local normal files'})))
     .pipe(gulp.dest(JS_DEST));

When condition is true:

[13:00:04] Starting 'copy.js.local.dev'...
[13:00:04] Finished 'copy.js.local.dev' after 16 ms
[13:00:04] Finished 'build.dev' after 3.77 s
[13:00:04] copy.js.local normal files dist/dev/jslocal/setup-service-worker.js
[13:00:04] copy.js.local normal files 1 item

This is correct (except there seems to be a synchronicity problem which is most likely unrelated to gulp-debug).

When condition is false:

[13:00:49] Starting 'copy.js.local.dev'...
[13:00:49] Finished 'copy.js.local.dev' after 16 ms
[13:00:49] Finished 'build.dev' after 3.33 s
[13:00:49] copy.js.local normal files 0 items

The file is copied and because the gulp-debug didn't fire it didn't show the file. However the summary is still printed and is zero (0) not because no file was copied but because the debug line for that file wasn't printed. Somehow this seems to sit outside the copy-if condition. This is the issue.

"gulp-debug": "^2.1.2",
"gulp-if": "^2.0.1",

I would argue that's an issue with gulp-if. It shouldn't touch gulp-debug at all when the condition is false.

I believe the problem is that the debug() inside the gulp-if is still instantiated and the thought2 flush() function is called at the end regardless of if the thought2 transform() function is called. I'm not that familiar with thought2 to understand exactly what is going on here (In fact I'm new to most of this). In java-land and many other similar languages, this is like a finally() in exceptions that is called regardless of if the try or catch happens.

Perhaps a guard in the flush() to only run if the transform() runs would solve this problem.

re: https://github.com/sindresorhus/gulp-debug/blob/master/index.js

There is discussion about this at robrich/gulp-if#66

I'm closing this as you are correct and its a problem with gulp-if().