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

failReporter and gulp.watch don't work together #67

Open
ehaeusler opened this issue Apr 19, 2016 · 7 comments
Open

failReporter and gulp.watch don't work together #67

ehaeusler opened this issue Apr 19, 2016 · 7 comments

Comments

@ehaeusler
Copy link

Hi there,

In my current setup (Gulp 4.0.0-alpha.2) gulp.watch stops working after the first execution if I use failReporter. The task runs successfully, but further changes don't trigger another task. Without the failReporter, the watcher works. I even tried it with the endless option, but that prevents the task from executing entirely (Shell output stops at "Starting 'styles'....).

My gulpfile:

var gulp         = require('gulp'),
    autoprefixer = require('autoprefixer'),
    scss         = require('gulp-sass'),
    postcss      = require('gulp-postcss'),
    scsslint     = require('gulp-scss-lint'),
    sourcemaps   = require('gulp-sourcemaps'),
    importer     = require('sass-module-importer'),
    cleancss     = require('gulp-clean-css'),
    Cachebuster  = require('gulp-cachebust'),
    cachebust    = new Cachebuster();

gulp.task('styles', function ()
{
    return gulp
        .src('scss/**/*.scss')
        .pipe(sourcemaps.init())
        .pipe(scsslint())
        .pipe(scsslint.failReporter())
        .pipe(scss({importer: importer()}))
        .pipe(cachebust.resources())
        .pipe(postcss([autoprefixer({browsers: ['last 2 versions']})]))
        .pipe(cleancss())
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./styles'))
});

gulp.task('default', gulp.series('styles'));

gulp.task('watch', function ()
{
    return gulp.watch('scss/**/*.scss', gulp.series('styles'));
});
@juanfran
Copy link
Owner

sorry for waiting.

why do you need failReporter? the purpose of failReporter is fail when there are errors

@ehaeusler
Copy link
Author

ehaeusler commented Apr 29, 2016

Thats what I want it to do. If there are errors during linting, the task should fail so you are forced to fix them before recompiling. But if everything is ok, the task should continue like usual. Isn't that how you use failReporter?
--- Edit ---
Sorry, if that wasn't clear before: This happens when linting is successful. The task just doesn't activate again after further changes.

@juanfran
Copy link
Owner

juanfran commented May 4, 2016

I can't reproduce it, sorry. Are you getting any message on the first execution?

@dak
Copy link
Contributor

dak commented May 5, 2016

I ran into the same issue and ended up writing a custom report function to set the process.exitCode to 1 if there is an error:

function scsslint() {
    return gulp.src(paths, {
        since: gulp.lastRun('scsslint')
    })
    .pipe(pi.scssLint({
        config: 'gulp/.scss-lint.yml',
        customReport: (file) => {
            var colors = pi.util.colors;

            if (!file.scsslint.success) {
                process.exitCode = 1;

                pi.util.log(
                    colors.cyan(file.scsslint.issues.length) +
                    ' issues found in ' +
                    colors.magenta(file.path)
                );

                file.scsslint.issues.forEach((issue) => {
                    var severity = issue.severity === 'warning' ? colors.yellow(' [W] ') : colors.red(' [E] ');
                    var linter = issue.linter ? (`${issue.linter}: `) : '';
                    var logMsg = `${colors.cyan(file.relative)}:` +
                        colors.magenta(issue.line) +
                        severity +
                        colors.green(linter) +
                        issue.reason;

                    pi.util.log(logMsg);
                });
            }
        }
    }));
}
gulp.task('styles:watch', () => {
    gulp.watch(paths, options)
    .on('change', gulp.series(
        scsslint,
        // other tasks
    ));
});

@juanfran
Copy link
Owner

juanfran commented May 5, 2016

I've made a simple example of what I've tried https://github.com/juanfran/gulp-scss-lint/tree/test-bug/test-bug

@ehaeusler
Copy link
Author

I tried your example and don't run into the situation there. Maybe it's caused in combination with one of the other plugins. I'll try to isolate it and provide feedback, if I find something.

@dak If I understand you correctly, your change is based on the situation where errors do happen? Because I get no further execution after the first successfull run.

@dak
Copy link
Contributor

dak commented May 11, 2016

@ehaeusler It should continue to run even if warnings/errors are thrown (it won't stop the next tests from being run either). But if you're using any kind of continuous integration (like Travis CI), it will properly signal to that environment that the test failed (and if you integrate it with GitHub, can allow you to prevent merging commits with errors).

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

3 participants