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

Patch #56

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {Buffer} from 'node:buffer';
import {execa} from 'execa';
import gifsicle from 'gifsicle';
import isGif from 'is-gif';
import gifsicle from 'gifsicle';

const main = (options = {}) => async input => {
if (!Buffer.isBuffer(input)) {
throw new TypeError(`Expected \`input\` to be of type \`Buffer\` but received type \`${typeof input}\``);
const imageminGifsicle = (options = {}) => async buffer => {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError(`Expected \`buffer\` to be of type \`Buffer\` but received type \`${typeof buffer}\``);
}

if (!isGif(input)) {
return input;
if (!isGif(buffer)) {
return buffer;
}

const args = ['--no-warnings', '--no-app-extensions'];
Expand All @@ -28,11 +28,11 @@ const main = (options = {}) => async input => {

const {stdout} = await execa(gifsicle, args, {
encoding: null,
input: buffer,
maxBuffer: Number.POSITIVE_INFINITY,
input,
});

return stdout;
};

export default main;
export default imageminGifsicle;
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagemin-gifsicle",
"version": "7.0.0",
"version": "7.0.1",
"description": "Imagemin plugin for Gifsicle",
"license": "MIT",
"repository": "imagemin/imagemin-gifsicle",
Expand Down Expand Up @@ -28,12 +28,17 @@
"optimize"
],
"dependencies": {
"execa": "^6.0.0",
"gifsicle": "^6.1.0",
"execa": "^6.1.0",
"gifsicle": "^7.0.1",
"is-gif": "^4.0.1"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.46.4"
"ava": "^5.1.1",
"xo": "^0.53.1"
},
"overrides": {
"got": "^12.5.3",
"semver-regex": "^4.0.5",
"uuid": "^7.0.0"
}
}
10 changes: 5 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import test from 'ava';
import imageminGifsicle from './index.js';

test('Buffer', async t => {
const buf = await fs.readFile(new URL('fixture.gif', import.meta.url));
const data = await imageminGifsicle()(buf);
const buffer = await fs.readFile(new URL('fixture.gif', import.meta.url));
const data = await imageminGifsicle()(buffer);

t.true(data.length < buf.length);
t.true(data.length < buffer.length);
t.true(isGif(data));
});

test('Buffer - non-binary', async t => {
const buf = Buffer.from('string');
const data = await imageminGifsicle()(buf);
const buffer = Buffer.from('string');
const data = await imageminGifsicle()(buffer);

t.is(data.toString(), 'string');
});