Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Error out on TypeScript error #55

Open
guillaumejenkins opened this issue Nov 30, 2016 · 2 comments
Open

Error out on TypeScript error #55

guillaumejenkins opened this issue Nov 30, 2016 · 2 comments

Comments

@guillaumejenkins
Copy link

I would like my gulp task to fail if there were TypeScript compilation errors. I couldn't find a way to do this. If it's not already supported, could you consider adding an option for it?

@jrieken
Copy link
Owner

jrieken commented Dec 1, 2016

The build-function accepts an error handler which is called for each compilation issue. You should use that make your outer task fail.

@guillaumejenkins
Copy link
Author

guillaumejenkins commented Dec 5, 2016

I see; thanks for the help. However, in the usage example, you create the compiler outside of the gulp task:

    var tsb = require('gulp-tsb');

    // create and keep compiler
    var compilation = tsb.create({
        target: 'es5',
        module: 'commonjs',
        declaration: false
    });

    gulp.task('build', function() {
        return gulp.src('src/**/*.ts')
            .pipe(compilation()) // <- new compilation
            .pipe(gulp.dest(''));
    });

This means we don't have access to the gulp task's callback, which is what we need to invoke in order to make the task fail. Could it be possible to have the IncrementalCompiler take the error callback as argument instead of the create function? Then we can do something like:

    gulp.task('build', function(gulpCb) {
        return gulp.src('src/**/*.ts')
            .pipe(compilation(gulpCb)) // <- Pass the gulp callback (or any other error handler) directly to the compilation 
            .pipe(gulp.dest(''));
    });

Otherwise, we need to recreate the compiler inside the gulp task every time we run the task:

    gulp.task('build', function(gulpCb) {
        var compilation = tsb.create({ ... }, /*verbose*/ true, /*json*/ false, /*onError*/ gulpCb);
        return gulp.src('src/**/*.ts')
            .pipe(compilation()) // <- new compilation
            .pipe(gulp.dest(''));
    });

@jrieken Is there any downside to calling tsb.create() every time we run a task? Do we lose anything by not reusing the same compiler?

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

No branches or pull requests

2 participants