Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopping dependent task, but not gulp #27

Open
callumacrae opened this issue Jan 12, 2015 · 4 comments
Open

Stopping dependent task, but not gulp #27

callumacrae opened this issue Jan 12, 2015 · 4 comments

Comments

@callumacrae
Copy link

I have the two following tasks:

gulp.task('js-quality', function () {
  return gulp.src('./src/js/**/*.js')
    .pipe(plugins.plumber({ errorHandler: onError }))
    .pipe(plugins.jscs())
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter(stylish));
});

gulp.task('js', ['js-quality'], function () {
  var bundler = browserify('./src/js/test.js');

  return bundler.bundle()
    .on('error', console.log.bind(console, 'Browserify Error'))
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('./demo/build'));
});

When js-quality fails, I want onError to be called (which pipes the error through to browser-sync and beeps), but I don't want the js task to run.

Is there any way to do this, or is this something I'll have to work around until Gulp 4?

@floatdrop
Copy link
Owner

@callumacrae you can try to reemit error event from onError handler. Or you can try to use callback version of js-quality task:

gulp.task('js-quality', function (cb) {
 gulp.src('./src/js/**/*.js')
    .pipe(plugins.plumber(function (err) { onError(err); cb(err); } ))
    .pipe(plugins.jscs())
    .pipe(plugins.jshint())
    .pipe(plugins.jshint.reporter(stylish))
    .on('end', cb);
});

@ivan-kleshnin
Copy link

I wonder how to make this work too.
Reemitting error event from handler leads to infinite recursions.
In cb version, callbacks will be called multiple times.
The only workaround to connect such tasks I found is global variables...

@pikeas
Copy link

pikeas commented Mar 13, 2015

+1 for the right way to do this, preferably compatible with Gulp4.

@vonagam
Copy link

vonagam commented Dec 2, 2015

In Gulp 3 you can call 'this.destroy()' in plumber error handler to prevent 'end' event from firing.

.pipe( plugins.plumber( { errorHandler: function ( error ) { 
  onError( error );
  this.destroy();
 } } ) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants