floatdrop / gulp-plumber

Fixing Node pipes
MIT License
806 stars 32 forks source link

Freezes after first call in Gulp v4 watch #50

Closed yanneves closed 6 years ago

yanneves commented 7 years ago

I'm lead to believe the following works in earlier versions of Gulp. However, in Gulp v4 using the built-in gulp.watch method, this successfully swallows errors the first time a change is detected but prevents future changes being detected.

function errorHandler(err) {
  gutil.beep()
  this.emit('end')
}

// gulp.src( ... )
  .pipe(plumber({ errorHandler }))
  // .pipe( ... )

Is this project intended to support Gulp v4? Using Node v7.1.0.

floatdrop commented 7 years ago

This project was developed for v2 version of gulp, I think, and worked with v3. v4 planned ship this feature internally.

yanneves commented 7 years ago

Thanks for looking into this @floatdrop.

I've opted to use watch-spawn to handle watch tasks as a wrapper around Gulp, until this can be remedied.

radiocity commented 6 years ago

Plumber works fine with gulp4

let gulp = require('gulp'),
    sass = require('gulp-sass'),
    plumber = require('gulp-plumber'),
    prefixer = require('gulp-autoprefixer'),
    csso = require('gulp-csso'),
    config = require('../../config');

gulp.task('scss:build', (done) => {
    return new Promise((resolve, reject) => {
        gulp.src(config.src + 'scss/**/*.scss')
            .pipe(plumber())
            .pipe(sass({
                errLogToConsole: false,
                outputStyle: "expanded",
                sourceMap: false
            }))
            .pipe(prefixer(config.prefixer))
            .pipe(csso())
            .pipe(plumber.stop())
            .pipe(gulp.dest(config.dist + "css"))
            .pipe(global.livereload.reload({stream: true}))
            .on('end', resolve)
            .on('error', reject);
        done();
    })
});

gulp.task('scss:watch', () => {
    global.watch = true;
    gulp.watch(config.src + 'scss/**/*.scss', gulp.series('scss:build'))
    .on('all', (event, filepath) => {
            // Reserved for emmity
    });
});

global.livereload - instance of browsersync defined elsewhere.

Even with notifications:

//...
let color = require("colors");

let onError = function(error) {
    process.stderr.write(
        "\007\n" +
        color.red.bold.inverse(error.name) +
        color.white.bold(" in " + error.plugin) +
        color.white.bold("\n\nMessage\n") +
        color.red.bold(error.message) + "\n"
    )
    this.emit('end');
}
// ...
            .pipe(plumber({errorHandler: onError}))
// ...
fvsch commented 6 years ago

gulp-plumber is working for me with Gulp 4.0.0.

I’m using it to log errors to the console and with node-notifier (showing system notifications), so that watch tasks don’t fail on the first syntax error (e.g. when writing Sass code). Errors are indeed logged and the watch tasks keeps running.

yanneves commented 6 years ago

Lots of changes in both codebases since I raised this issue. Will close as I think this is now resolved - thanks!