From cb063692c49313d0accf9aa545f848bcba6bccea Mon Sep 17 00:00:00 2001 From: Romain Faust Date: Wed, 22 Aug 2018 01:55:02 +0200 Subject: [PATCH 1/6] [@types/imagemin] Add type definitions --- types/imagemin/imagemin-tests.ts | 10 ++++++++++ types/imagemin/index.d.ts | 25 +++++++++++++++++++++++++ types/imagemin/tsconfig.json | 23 +++++++++++++++++++++++ types/imagemin/tslint.json | 1 + 4 files changed, 59 insertions(+) create mode 100644 types/imagemin/imagemin-tests.ts create mode 100644 types/imagemin/index.d.ts create mode 100644 types/imagemin/tsconfig.json create mode 100644 types/imagemin/tslint.json diff --git a/types/imagemin/imagemin-tests.ts b/types/imagemin/imagemin-tests.ts new file mode 100644 index 0000000000..1cc39cdfe2 --- /dev/null +++ b/types/imagemin/imagemin-tests.ts @@ -0,0 +1,10 @@ +import * as Imagemin from 'imagemin'; + +const input = ['fileA.jpg', 'fileB.png']; +const output = 'output'; +const options = { plugins: [] }; + +Imagemin(input); +Imagemin(input, output); +Imagemin(input, options); +Imagemin(input, output, options); diff --git a/types/imagemin/index.d.ts b/types/imagemin/index.d.ts new file mode 100644 index 0000000000..531d2d54ab --- /dev/null +++ b/types/imagemin/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for imagemin 6.0 +// Project: https://github.com/imagemin/imagemin#readme +// Definitions by: Romain Faust +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare function imagemin(input: string[], outputOrOptions?: string | imagemin.Options, options?: imagemin.Options): Promise; + +declare namespace imagemin { + function buffer(buffer: Buffer, options?: Options): Promise; + + type Plugin = (input: Buffer) => Promise; + + interface Options { + plugins: Plugin[]; + } + + interface Result { + data: Buffer; + path: string; + } +} + +export = imagemin; diff --git a/types/imagemin/tsconfig.json b/types/imagemin/tsconfig.json new file mode 100644 index 0000000000..849754b4d0 --- /dev/null +++ b/types/imagemin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "imagemin-tests.ts" + ] +} diff --git a/types/imagemin/tslint.json b/types/imagemin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/imagemin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From f0e36582878999785925434fbf941d518124528f Mon Sep 17 00:00:00 2001 From: Romain Faust Date: Wed, 22 Aug 2018 02:04:30 +0200 Subject: [PATCH 2/6] Change [] for ReadonlyArray when possible --- types/imagemin/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/imagemin/index.d.ts b/types/imagemin/index.d.ts index 531d2d54ab..80ae9d2fe5 100644 --- a/types/imagemin/index.d.ts +++ b/types/imagemin/index.d.ts @@ -5,7 +5,7 @@ /// -declare function imagemin(input: string[], outputOrOptions?: string | imagemin.Options, options?: imagemin.Options): Promise; +declare function imagemin(input: ReadonlyArray, outputOrOptions?: string | imagemin.Options, options?: imagemin.Options): Promise; declare namespace imagemin { function buffer(buffer: Buffer, options?: Options): Promise; @@ -13,7 +13,7 @@ declare namespace imagemin { type Plugin = (input: Buffer) => Promise; interface Options { - plugins: Plugin[]; + plugins: ReadonlyArray; } interface Result { From 5625e639ab00979014a0eea183c38607ebe73ac2 Mon Sep 17 00:00:00 2001 From: Romain Faust Date: Wed, 22 Aug 2018 02:08:57 +0200 Subject: [PATCH 3/6] Add missing tests for imagemin.buffer --- types/imagemin/imagemin-tests.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/imagemin/imagemin-tests.ts b/types/imagemin/imagemin-tests.ts index 1cc39cdfe2..443ae9469e 100644 --- a/types/imagemin/imagemin-tests.ts +++ b/types/imagemin/imagemin-tests.ts @@ -1,5 +1,6 @@ import * as Imagemin from 'imagemin'; +const buffer = Buffer.from('Hello World!'); const input = ['fileA.jpg', 'fileB.png']; const output = 'output'; const options = { plugins: [] }; @@ -8,3 +9,6 @@ Imagemin(input); Imagemin(input, output); Imagemin(input, options); Imagemin(input, output, options); + +Imagemin.buffer(buffer); +Imagemin.buffer(buffer, options); From 9a6daf10c2fb89e718825d72223f5b07ef7d2d26 Mon Sep 17 00:00:00 2001 From: Romain Faust Date: Wed, 22 Aug 2018 15:49:50 +0200 Subject: [PATCH 4/6] Fix error with imagemin declaration. Fix how modules are imported --- types/imagemin/imagemin-tests.ts | 27 +++++++++++++++++---------- types/imagemin/index.d.ts | 7 ++++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/types/imagemin/imagemin-tests.ts b/types/imagemin/imagemin-tests.ts index 443ae9469e..45da266161 100644 --- a/types/imagemin/imagemin-tests.ts +++ b/types/imagemin/imagemin-tests.ts @@ -1,14 +1,21 @@ -import * as Imagemin from 'imagemin'; +import imagemin = require('imagemin'); -const buffer = Buffer.from('Hello World!'); -const input = ['fileA.jpg', 'fileB.png']; -const output = 'output'; +const input = ['/input/**/*']; +const output = '/output/dir'; const options = { plugins: [] }; +const handler = (result: imagemin.Result[]) => { + // ... +}; -Imagemin(input); -Imagemin(input, output); -Imagemin(input, options); -Imagemin(input, output, options); +imagemin(input).then(handler); +imagemin(input, output).then(handler); +imagemin(input, options).then(handler); +imagemin(input, output, options).then(handler); -Imagemin.buffer(buffer); -Imagemin.buffer(buffer, options); +const buffer = Buffer.from([ /* File content */ ]); +const bufferHandler = (result: Buffer) => { + // ... +}; + +imagemin.buffer(buffer).then(bufferHandler); +imagemin.buffer(buffer, options).then(bufferHandler); diff --git a/types/imagemin/index.d.ts b/types/imagemin/index.d.ts index 80ae9d2fe5..c848818f31 100644 --- a/types/imagemin/index.d.ts +++ b/types/imagemin/index.d.ts @@ -5,11 +5,10 @@ /// -declare function imagemin(input: ReadonlyArray, outputOrOptions?: string | imagemin.Options, options?: imagemin.Options): Promise; +declare function imagemin(input: ReadonlyArray, outputOrOptions?: string | imagemin.Options): Promise; +declare function imagemin(input: ReadonlyArray, output?: string, options?: imagemin.Options): Promise; declare namespace imagemin { - function buffer(buffer: Buffer, options?: Options): Promise; - type Plugin = (input: Buffer) => Promise; interface Options { @@ -20,6 +19,8 @@ declare namespace imagemin { data: Buffer; path: string; } + + function buffer(buffer: Buffer, options?: Options): Promise; } export = imagemin; From de1d976af971743b5bdded0303371f7729ecbe25 Mon Sep 17 00:00:00 2001 From: Romain Faust <11320210+romain-faust@users.noreply.github.com> Date: Thu, 23 Aug 2018 19:25:56 +0200 Subject: [PATCH 5/6] Simplify tests --- types/imagemin/imagemin-tests.ts | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/types/imagemin/imagemin-tests.ts b/types/imagemin/imagemin-tests.ts index 45da266161..42fa6e6ba6 100644 --- a/types/imagemin/imagemin-tests.ts +++ b/types/imagemin/imagemin-tests.ts @@ -1,21 +1,9 @@ import imagemin = require('imagemin'); -const input = ['/input/**/*']; -const output = '/output/dir'; -const options = { plugins: [] }; -const handler = (result: imagemin.Result[]) => { - // ... -}; +imagemin(['*.png']).then((results: imagemin.Result[]) => { /* ... */ }); +imagemin(['*.png'], 'dist').then((results: imagemin.Result[]) => { /* ... */ }); +imagemin(['*.png'], { plugins: [] }).then((results: imagemin.Result[]) => { /* ... */ }); +imagemin(['*.png'], 'dist', { plugins: [] }).then((results: imagemin.Result[]) => { /* ... */ }); -imagemin(input).then(handler); -imagemin(input, output).then(handler); -imagemin(input, options).then(handler); -imagemin(input, output, options).then(handler); - -const buffer = Buffer.from([ /* File content */ ]); -const bufferHandler = (result: Buffer) => { - // ... -}; - -imagemin.buffer(buffer).then(bufferHandler); -imagemin.buffer(buffer, options).then(bufferHandler); +imagemin.buffer(Buffer.from[/* ... */]).then((result: Buffer) => { /* ... */ }); +imagemin.buffer(Buffer.from[/* ... */], { plugins: [] }).then((result: Buffer) => { /* ... */ }); From e25a5cc4c09c24254ba99fec74f52517cc17dd6b Mon Sep 17 00:00:00 2001 From: Romain Faust Date: Thu, 23 Aug 2018 19:32:01 +0200 Subject: [PATCH 6/6] Add missing parenthesis --- types/imagemin/imagemin-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/imagemin/imagemin-tests.ts b/types/imagemin/imagemin-tests.ts index 42fa6e6ba6..88a91980d6 100644 --- a/types/imagemin/imagemin-tests.ts +++ b/types/imagemin/imagemin-tests.ts @@ -5,5 +5,5 @@ imagemin(['*.png'], 'dist').then((results: imagemin.Result[]) => { /* ... */ }); imagemin(['*.png'], { plugins: [] }).then((results: imagemin.Result[]) => { /* ... */ }); imagemin(['*.png'], 'dist', { plugins: [] }).then((results: imagemin.Result[]) => { /* ... */ }); -imagemin.buffer(Buffer.from[/* ... */]).then((result: Buffer) => { /* ... */ }); -imagemin.buffer(Buffer.from[/* ... */], { plugins: [] }).then((result: Buffer) => { /* ... */ }); +imagemin.buffer(Buffer.from([/* ... */])).then((result: Buffer) => { /* ... */ }); +imagemin.buffer(Buffer.from([/* ... */]), { plugins: [] }).then((result: Buffer) => { /* ... */ });