Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native ESM and update dependencies #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 20 additions & 58 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,26 @@
name: test

on:
push:
branches:
- master
pull_request:
branches:
- master

- push
- pull_request
jobs:
linux:
runs-on: ubuntu-latest

test:
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x]

node-version:
- 12
- 14
- 16
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
CI: true

macos:
runs-on: macos-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
CI: true

windows:
runs-on: windows-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
CI: true
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';
const execBuffer = require('exec-buffer');
const isPng = require('is-png');
const optipng = require('optipng-bin');
import {Buffer} from 'node:buffer';
import execBuffer from 'exec-buffer';
import isPng from 'is-png';
import optipng from 'optipng-bin';

module.exports = options => async buffer => {
const main = options => async buffer => {
options = {
optimizationLevel: 3,
bitDepthReduction: true,
colorTypeReduction: true,
paletteReduction: true,
interlaced: false,
errorRecovery: true,
...options
...options,
};

if (!Buffer.isBuffer(buffer)) {
Expand All @@ -29,7 +29,7 @@ module.exports = options => async buffer => {
'-o',
options.optimizationLevel,
'-out',
execBuffer.output
execBuffer.output,
];

if (options.errorRecovery) {
Expand Down Expand Up @@ -57,6 +57,8 @@ module.exports = options => async buffer => {
return execBuffer({
input: buffer,
bin: optipng,
args: arguments_
args: arguments_,
});
};

export default main;
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"description": "Imagemin plugin for OptiPNG",
"license": "MIT",
"repository": "imagemin/imagemin-optipng",
"type": "module",
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -24,11 +25,11 @@
],
"dependencies": {
"exec-buffer": "^3.0.0",
"is-png": "^2.0.0",
"optipng-bin": "^7.0.0"
"is-png": "^3.0.1",
"optipng-bin": "^8.1.0"
},
"devDependencies": {
"ava": "^3.8.0",
"xo": "^0.30.0"
"ava": "^4.0.1",
"xo": "^0.47.0"
}
}
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# imagemin-optipng
# imagemin-optipng ![GitHub Actions Status](https://github.com/imagemin/imagemin-optipng/workflows/test/badge.svg?branch=main)

> Imagemin plugin for OptiPNG

Expand All @@ -11,8 +11,8 @@ $ npm install imagemin-optipng
## Usage

```js
const imagemin = require('imagemin');
const imageminOptipng = require('imagemin-optipng');
import imagemin from 'imagemin';
import imageminOptipng from 'imagemin-optipng';

(async () => {
await imagemin(['images/*.png'], {
Expand Down
17 changes: 8 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const fs = require('fs');
const path = require('path');
const isPng = require('is-png');
const test = require('ava');
const optipng = require('.');
import fs from 'node:fs';
import isPng from 'is-png';
import test from 'ava';
import optipng from './index.js';

const fixture = fs.readFileSync(path.join(__dirname, 'fixture.png'));
const fixtureBroken = fs.readFileSync(path.join(__dirname, 'fixture_broken.png'));
const fixture = fs.readFileSync(new URL('fixture.png', import.meta.url));
const fixtureBroken = fs.readFileSync(new URL('fixture_broken.png', import.meta.url));

test('optimize a PNG', async t => {
const data = await optipng()(fixture);
Expand Down Expand Up @@ -46,7 +45,7 @@ test('errorRecovery is set to false', async t => {
test('interlaced is set to true', async t => {
const [data1, data2] = await Promise.all([
optipng({interlaced: true})(fixture),
optipng()(fixture)
optipng()(fixture),
]);

t.true(isPng(data1));
Expand All @@ -57,7 +56,7 @@ test('interlaced is set to undefined and null', async t => {
const [data1, data2, data3] = await Promise.all([
optipng({interlaced: undefined})(fixture),
optipng({interlaced: null})(fixture),
optipng({interlaced: true})(fixture)
optipng({interlaced: true})(fixture),
]);

t.true(isPng(data1) && isPng(data2));
Expand Down