2

I've getting a task that never completes. It prints the starting message, but not the finishing message. However, if I pipe the stream to gulp-debug, it's fixed and now magically works. Any what's wrong with the stream?

gulp.task('copy-src-mobile',function(){

  return merge(
    gulp.src('./Web/app/**')
      .pipe(replace(/\/app\//g,'app\/'))
      .pipe(replace(trunacteAbsoluteUrlRegex,'$1=$2'))
      .pipe(gulp.dest(deployTo + 'app'))
    ,gulp.src('Web/js/**').pipe(gulp.dest(deployTo+'js'))
    ,gulp.src('Web/fonts/**').pipe(gulp.dest(deployTo+'fonts'))
    ,gulp.src('Web/img/**').pipe(gulp.dest(deployTo+'img'))
    ,gulp.src('Web/css/**.css').pipe(gulp.dest(deployTo+'css'))
  )
  .pipe(debug({verbose: false})) //If I comment this out, the task never finishes
  ;
});
heneryville
  • 2,853
  • 1
  • 23
  • 30
  • I had [similar troubles](http://stackoverflow.com/questions/26206538/why-do-some-gulp-streams-flow-by-default-while-others-do-not) – hurrymaplelad Oct 05 '14 at 23:54

1 Answers1

3

Since you are returning a stream (result of merge) from your task Gulp waits for this stream to be drained. But looking at your Gulp task there is no one reading from the merged stream so it never ends hence your task never finishes. Adding debug helps since I guess it drains the stream.

This is not-obvious part of working with streams in Gulp, but it is going to get better with this commit in orchestrator: https://github.com/orchestrator/orchestrator/commit/1d9926dc28087ae5de5fdd904ae6111966cb4ea6. Not sure when this one is going to be part of the official Gulp release so for now you can do either one of those:

  • don't use stream merging and put each pipe that you are merging currently into a separate gulp task
  • drain the merged stream

EDIT: actually it looks like gulp has dependency on the Orchestrator specified as ^0.3.0 so just updating your npm dependencies might solve the issue.

pkozlowski.opensource
  • 117,202
  • 60
  • 326
  • 286