diff --git a/.travis.yml b/.travis.yml index 985b15c..a18175d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,6 @@ os: - windows language: node_js node_js: + - '14' - '12' - '10' - - '8' diff --git a/fixture-no-compress.png b/fixture-no-compress.png deleted file mode 100644 index 1310ac2..0000000 Binary files a/fixture-no-compress.png and /dev/null differ diff --git a/index.d.ts b/index.d.ts index 18d5599..89c3e55 100644 --- a/index.d.ts +++ b/index.d.ts @@ -55,7 +55,7 @@ export interface Options { /** Buffer or stream to optimize. */ -export type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise +export type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise; /** Imagemin plugin for pngquant. diff --git a/index.test-d.ts b/index.test-d.ts index 3f62d83..28ea434 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -3,10 +3,12 @@ import * as path from 'path'; import {expectType} from 'tsd'; import imageminPngquant from '.'; -const buffer = await fs.readFileSync(path.join(__dirname, 'fixture.png')); +const buffer = fs.readFileSync(path.join(__dirname, 'fixture.png')); -expectType(await imageminPngquant()(buffer)); -expectType(await imageminPngquant({ - speed: 10, - quality: [0.8, 1] -})(buffer)); +(async () => { + expectType(await imageminPngquant()(buffer)); + expectType(await imageminPngquant({ + speed: 10, + quality: [0.8, 1] + })(buffer)); +})(); diff --git a/package.json b/package.json index edd8d08..a9518ab 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "MIT", "repository": "imagemin/imagemin-pngquant", "engines": { - "node": ">=8" + "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" @@ -24,17 +24,17 @@ "pngquant" ], "dependencies": { - "execa": "^1.0.0", + "execa": "^4.0.0", "is-png": "^2.0.0", "is-stream": "^2.0.0", - "ow": "^0.13.2", - "pngquant-bin": "^5.0.0" + "ow": "^0.17.0", + "pngquant-bin": "^6.0.0" }, "devDependencies": { "@types/node": "^12.0.3", - "ava": "^1.0.1", + "ava": "^3.8.0", "get-stream": "^5.1.0", - "tsd": "^0.7.3", - "xo": "^0.24.0" + "tsd": "^0.11.0", + "xo": "^0.30.0" } } diff --git a/readme.md b/readme.md index ef63bf5..e56cc55 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,8 @@ const imagemin = require('imagemin'); const imageminPngquant = require('imagemin-pngquant'); (async () => { - await imagemin(['images/*.png'], 'build/images', { + await imagemin(['images/*.png'], { + destination: 'build/images', plugins: [ imageminPngquant() ] diff --git a/test.js b/test.js index 9117929..7945384 100644 --- a/test.js +++ b/test.js @@ -1,19 +1,22 @@ -import fs from 'fs'; -import path from 'path'; -import test from 'ava'; -import getStream from 'get-stream'; -import isPng from 'is-png'; -import imageminPngquant from '.'; +const {promisify} = require('util'); +const fs = require('fs'); +const path = require('path'); +const test = require('ava'); +const getStream = require('get-stream'); +const isPng = require('is-png'); +const imageminPngquant = require('.'); + +const readFile = promisify(fs.readFile); test('optimize a PNG', async t => { - const buffer = await fs.readFileSync(path.join(__dirname, 'fixture.png')); + const buffer = await readFile(path.join(__dirname, 'fixture.png')); const data = await imageminPngquant()(buffer); t.true(data.length < buffer.length); t.true(isPng(data)); }); test('support pngquant options', async t => { - const buffer = await fs.readFileSync(path.join(__dirname, 'fixture.png')); + const buffer = await readFile(path.join(__dirname, 'fixture.png')); const data = await imageminPngquant({ speed: 10, quality: [0.8, 1] @@ -23,7 +26,7 @@ test('support pngquant options', async t => { }); test('support streams', async t => { - const buffer = await fs.readFileSync(path.join(__dirname, 'fixture.png')); + const buffer = await readFile(path.join(__dirname, 'fixture.png')); const stream = fs.createReadStream(path.join(__dirname, 'fixture.png')); const data = await getStream.buffer(imageminPngquant()(stream)); t.true(data.length < buffer.length); @@ -31,14 +34,7 @@ test('support streams', async t => { }); test('skip optimizing a non-PNG file', async t => { - const buffer = await fs.readFileSync(__filename); + const buffer = await readFile(__filename); const data = await imageminPngquant()(buffer); t.is(data.length, buffer.length); }); - -test('skip optimizing a fully optimized PNG', async t => { - const buffer = await fs.readFileSync(path.join(__dirname, 'fixture-no-compress.png')); - const data = await imageminPngquant({quality: [0.8, 1]})(buffer); - t.is(data.length, buffer.length); - t.true(isPng(data)); -});