Skip to content

Commit

Permalink
Require Node.js 10 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
1000ch committed Jun 1, 2020
1 parent 61997a2 commit d285e92
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ os:
- windows
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
Binary file removed fixture-no-compress.png
Binary file not shown.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface Options {
/**
Buffer or stream to optimize.
*/
export type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise<Buffer>
export type Plugin = (input: Buffer | NodeJS.ReadableStream) => Promise<Buffer>;

/**
Imagemin plugin for pngquant.
Expand Down
14 changes: 8 additions & 6 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Buffer>(await imageminPngquant()(buffer));
expectType<Buffer>(await imageminPngquant({
speed: 10,
quality: [0.8, 1]
})(buffer));
(async () => {
expectType<Buffer>(await imageminPngquant()(buffer));
expectType<Buffer>(await imageminPngquant({
speed: 10,
quality: [0.8, 1]
})(buffer));
})();
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"repository": "imagemin/imagemin-pngquant",
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -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"
}
}
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]
Expand Down
30 changes: 13 additions & 17 deletions test.js
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -23,22 +26,15 @@ 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);
t.true(isPng(data));
});

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));
});

0 comments on commit d285e92

Please sign in to comment.