From 58fe0b0e72fbea01c059d507512cdedf30d5272d Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Fri, 21 Aug 2015 09:17:54 -0600 Subject: [PATCH 1/2] Definitions for gulp-plumber --- gulp-plumber/gulp-plumber-tests.ts | 36 +++++++++++++++++++++ gulp-plumber/gulp-plumber.d.ts | 51 ++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 gulp-plumber/gulp-plumber-tests.ts create mode 100644 gulp-plumber/gulp-plumber.d.ts diff --git a/gulp-plumber/gulp-plumber-tests.ts b/gulp-plumber/gulp-plumber-tests.ts new file mode 100644 index 000000000..cf055dad5 --- /dev/null +++ b/gulp-plumber/gulp-plumber-tests.ts @@ -0,0 +1,36 @@ +/// +/// +/// + +import gulp = require('gulp'); +import plumber = require('gulp-plumber'); + +//default behavior +gulp.src('./src/*.ext') + .pipe(plumber()) + .pipe(gulp.dest('./dist')); + +//error handler function +gulp.src('./src/*.ext') + .pipe(plumber((error) => { + console.log(error); + })) + .pipe(gulp.dest('./dist')); + +gulp.src('./src/*.ext') + .pipe(plumber({})) + .pipe(gulp.dest('./dist')); + +gulp.src('./src/*.ext') + .pipe(plumber({ inherit: false })) + .pipe(gulp.dest('./dist')); + +gulp.src('./src/*.ext') + .pipe(plumber({ errorHandler: (error) => console.log(error) })) + .pipe(gulp.dest('./dist')); + +//plumber.stop() +gulp.src('./src/*.scss') + .pipe(plumber()) + .pipe(plumber.stop()) + .pipe(gulp.dest('./dist')); \ No newline at end of file diff --git a/gulp-plumber/gulp-plumber.d.ts b/gulp-plumber/gulp-plumber.d.ts new file mode 100644 index 000000000..0301affd6 --- /dev/null +++ b/gulp-plumber/gulp-plumber.d.ts @@ -0,0 +1,51 @@ +// Type definitions for gulp-plumber +// Project: https://github.com/floatdrop/gulp-plumber +// Definitions by: Joe Skeen +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +/** Prevent pipe breaking caused by errors from gulp plugins */ +declare module 'gulp-plumber' { + + /** Prevent pipe breaking caused by errors from gulp plugins */ + interface GulpPlumber { + /** + * Returns Stream, that fixes pipe methods on Streams that are next in pipeline. + * + * @param options Sets options as described in the Options interface + */ + (options?: Options): NodeJS.ReadWriteStream; + /** + * Returns Stream, that fixes pipe methods on Streams that are next in pipeline. + * + * @param errorHandler the function to be attached to the stream on('error') + */ + (errorHandler: ErrorHandlerFunction): NodeJS.ReadWriteStream; + /** returns default behaviour for pipeline after it was piped */ + stop(): NodeJS.ReadWriteStream; + } + + interface Options { + /** + * Handle errors in underlying streams and output them to console. Default true. + * If function passed, it will be attached to stream on('error') + * If false passed, error handler will not be attached + * If undefined passed, default error handler will be attached + */ + errorHandler?: ErrorHandlerFunction | boolean; + /** Monkeypatch pipe functions in underlying streams in pipeline. Default true. */ + inherit?: boolean; + } + + /** an error handler function to be attached to the stream on('error') */ + interface ErrorHandlerFunction { + /** an error handler function to be attached to the stream on('error') */ + (error): void; + } + + /** Prevent pipe breaking caused by errors from gulp plugins */ + var gulpPlumber: GulpPlumber; + + export = gulpPlumber; +} From 4e950fdf8cbd5a8b001be640046f98935c08ce61 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Fri, 21 Aug 2015 09:26:23 -0600 Subject: [PATCH 2/2] add explicit any type for error handler parameter (since any type can be thrown in JS) --- gulp-plumber/gulp-plumber.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulp-plumber/gulp-plumber.d.ts b/gulp-plumber/gulp-plumber.d.ts index 0301affd6..693c4cbf9 100644 --- a/gulp-plumber/gulp-plumber.d.ts +++ b/gulp-plumber/gulp-plumber.d.ts @@ -41,7 +41,7 @@ declare module 'gulp-plumber' { /** an error handler function to be attached to the stream on('error') */ interface ErrorHandlerFunction { /** an error handler function to be attached to the stream on('error') */ - (error): void; + (error: any): void; } /** Prevent pipe breaking caused by errors from gulp plugins */