diff --git a/types/gulp-uglify/composer.d.ts b/types/gulp-uglify/composer.d.ts new file mode 100644 index 0000000000..ec592ad5e8 --- /dev/null +++ b/types/gulp-uglify/composer.d.ts @@ -0,0 +1,18 @@ +import * as UglifyJS from 'uglify-js'; +import * as GulpUglify from 'gulp-uglify'; + +interface Composer { + (uglify: Uglify, log: Logger): typeof GulpUglify; +} + +interface Uglify { + minify: typeof UglifyJS.minify; +} + +interface Logger { + warn: typeof console.warn; +} + +declare const composer: Composer; + +export = composer; diff --git a/types/gulp-uglify/gulp-uglify-tests.ts b/types/gulp-uglify/gulp-uglify-tests.ts index 499ac15a37..172d7cae0b 100644 --- a/types/gulp-uglify/gulp-uglify-tests.ts +++ b/types/gulp-uglify/gulp-uglify-tests.ts @@ -1,17 +1,19 @@ import * as gulp from 'gulp'; import * as uglify from 'gulp-uglify'; +import pump = require('pump'); +import uglifyjs = require('uglify-js'); +import composer = require('gulp-uglify/composer'); -gulp.task('compress', function() { - var tsResult = gulp.src('lib/*.ts') +gulp.task('compress', () => { + const tsResult = gulp.src('lib/*.ts') .pipe(uglify()) .pipe(gulp.dest('dist')); }); -gulp.task('compress2', function() { - var tsResult = gulp.src('lib/*.ts') +gulp.task('compress2', () => { + const tsResult = gulp.src('lib/*.ts') .pipe(uglify({ mangle: false, - preserveComments: "some", compress: false, output: { max_line_len: 300 @@ -19,3 +21,34 @@ gulp.task('compress2', function() { })) .pipe(gulp.dest('dist')); }); + +gulp.task('compress', (cb) => { + pump([ + gulp.src('lib/*.js'), + uglify(), + gulp.dest('dist') + ], + cb + ); +}); + +const minify = composer(uglifyjs, console); + +gulp.task('compress', (cb) => { + // the same options as described above + const options = {}; + + pump([ + gulp.src('lib/*.js'), + minify(options), + gulp.dest('dist') + ], + cb + ); +}); + +gulp.task('compress', () => { + return gulp.src('lib/*.js') + .pipe(minify()) + .pipe(gulp.dest('dist')); +}); diff --git a/types/gulp-uglify/index.d.ts b/types/gulp-uglify/index.d.ts index 7dafe43efa..4b86c2f2e0 100644 --- a/types/gulp-uglify/index.d.ts +++ b/types/gulp-uglify/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for gulp-uglify +// Type definitions for gulp-uglify 3.0 // Project: https://github.com/terinjokes/gulp-uglify // Definitions by: Christopher Haws +// Leonard Thieu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -23,14 +24,6 @@ declare namespace GulpUglify { * Pass an object to specify custom compressor options. Pass false to skip compression completely. */ compress?: UglifyJS.CompressorOptions | boolean; - - /** - * A convenience option for options.output.comments. Defaults to preserving no comments. - * all - Preserve all comments in code blocks - * some - Preserve comments that start with a bang (!) or include a Closure Compiler directive (@preserve, @license, @cc_on) - * function - Specify your own comment preservation function. You will be passed the current node and the current comment and are expected to return either true or false. - */ - preserveComments?: string | ((node: any, comment: UglifyJS.Tokenizer) => boolean); } } diff --git a/types/gulp-uglify/tsconfig.json b/types/gulp-uglify/tsconfig.json index d0ae9de799..16668a9b9f 100644 --- a/types/gulp-uglify/tsconfig.json +++ b/types/gulp-uglify/tsconfig.json @@ -6,20 +6,18 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" ], - "paths": { - "q": [ "q/v0" ] - }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", + "composer.d.ts", "gulp-uglify-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/gulp-uglify/tslint.json b/types/gulp-uglify/tslint.json new file mode 100644 index 0000000000..a4bcc87748 --- /dev/null +++ b/types/gulp-uglify/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "callable-types": false + } +}