Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/gulp-imagemin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.0.3
Choose a base ref
...
head repository: sindresorhus/gulp-imagemin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.0
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on May 28, 2019

  1. Create funding.yml

    sindresorhus authored May 28, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    jordemort Jordan Webb
    Copy the full SHA
    c1c3346 View commit details

Commits on May 30, 2019

  1. Require Node.js 8

    sindresorhus committed May 30, 2019
    Copy the full SHA
    6e091ed View commit details
  2. 6.0.0

    sindresorhus committed May 30, 2019
    Copy the full SHA
    97cd1c3 View commit details
Showing with 45 additions and 52 deletions.
  1. +3 −0 .github/funding.yml
  2. +1 −1 .travis.yml
  3. +20 −18 index.js
  4. +8 −9 package.json
  5. +2 −13 readme.md
  6. +11 −11 test.js
3 changes: 3 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github: sindresorhus
open_collective: sindresorhus
custom: https://sindresorhus.com/donate
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
38 changes: 20 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -37,43 +37,45 @@ module.exports = (plugins, options) => {
plugins = null;
}

options = Object.assign({
options = {
// TODO: Remove this when Gulp gets a real logger with levels
verbose: process.argv.includes('--verbose')
}, options);
verbose: process.argv.includes('--verbose'),
...options
};

const validExts = ['.jpg', '.jpeg', '.png', '.gif', '.svg'];
const validExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.svg'];

let totalBytes = 0;
let totalSavedBytes = 0;
let totalFiles = 0;

return through.obj({
maxConcurrency: 8
}, (file, enc, cb) => {
}, (file, encoding, callback) => {
if (file.isNull()) {
cb(null, file);
callback(null, file);
return;
}

if (file.isStream()) {
cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
return;
}

if (!validExts.includes(path.extname(file.path).toLowerCase())) {
if (!validExtensions.includes(path.extname(file.path).toLowerCase())) {
if (options.verbose) {
log(`${PLUGIN_NAME}: Skipping unsupported image ${chalk.blue(file.relative)}`);
}

cb(null, file);
callback(null, file);
return;
}

const use = plugins || getDefaultPlugins();

imagemin.buffer(file.contents, {use})
.then(data => {
(async () => {
try {
const data = await imagemin.buffer(file.contents, {use});
const originalSize = file.contents.length;
const optimizedSize = data.length;
const saved = originalSize - optimizedSize;
@@ -92,12 +94,12 @@ module.exports = (plugins, options) => {
}

file.contents = data;
cb(null, file);
})
.catch(error => {
cb(new PluginError(PLUGIN_NAME, error, {fileName: file.path}));
});
}, cb => {
callback(null, file);
} catch (error) {
callback(new PluginError(PLUGIN_NAME, error, {fileName: file.path}));
}
})();
}, callback => {
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
let msg = `Minified ${totalFiles} ${plur('image', totalFiles)}`;

@@ -106,7 +108,7 @@ module.exports = (plugins, options) => {
}

log(`${PLUGIN_NAME}:`, msg);
cb();
callback();
});
};

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-imagemin",
"version": "5.0.3",
"version": "6.0.0",
"description": "Minify PNG, JPEG, GIF and SVG images",
"license": "MIT",
"repository": "sindresorhus/gulp-imagemin",
@@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
@@ -38,18 +38,17 @@
"chalk": "^2.4.1",
"fancy-log": "^1.3.2",
"plugin-error": "^1.0.1",
"imagemin": "^6.0.0",
"imagemin": "^6.1.0",
"plur": "^3.0.1",
"pretty-bytes": "^5.1.0",
"through2-concurrent": "^2.0.0"
},
"devDependencies": {
"ava": "^0.25.0",
"get-stream": "^4.1.0",
"imagemin-pngquant": "^6.0.0",
"pify": "^4.0.1",
"xo": "^0.23.0",
"vinyl": "^2.2.0"
"ava": "^1.4.1",
"get-stream": "^5.1.0",
"imagemin-pngquant": "^7.0.0",
"vinyl": "^2.2.0",
"xo": "^0.24.0"
},
"optionalDependencies": {
"imagemin-gifsicle": "^6.0.1",
15 changes: 2 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
@@ -4,12 +4,6 @@
*Issues with the output should be reported on the [`imagemin` issue tracker](https://github.com/imagemin/imagemin/issues).*

---

<p align="center"><sup>🦄 Support <a href="https://github.com/sindresorhus">my open-source work</a> by buying this awesome video course:</sup><br><b><a href="https://learnnode.com/friend/AWESOME">Learn to build apps and APIs with Node.js</a> by Wes Bos</b><br><sub>Try his free <a href="https://javascript30.com/friend/AWESOME">JavaScript 30</a> course for a taste of what to expect & check out his <a href="https://ES6.io/friend/AWESOME">ES6</a>, <a href="https://ReactForBeginners.com/friend/AWESOME">React</a>, <a href="https://SublimeTextBook.com/friend/AWESOME">Sublime</a> courses.</sub></p>

---


## Install

@@ -98,7 +92,7 @@ Comes bundled with the following **lossless** optimizers:

These are bundled for convenience and most users will not need anything else.

### imagemin([plugins], [options])
### imagemin(plugins?, options?)

Unsupported files are ignored.

@@ -111,7 +105,7 @@ Default: `[imagemin.gifsicle(), imagemin.jpegtran(), imagemin.optipng(), imagemi

#### options

Type: `Object`
Type: `object`

##### verbose

@@ -124,8 +118,3 @@ Enabling this will log info on every image passed to `gulp-imagemin`:
gulp-imagemin: ✔ image1.png (already optimized)
gulp-imagemin: ✔ image2.png (saved 91 B - 0.4%)
```


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
22 changes: 11 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import {promisify} from 'util';
import fs from 'fs';
import path from 'path';
import imageminPngquant from 'imagemin-pngquant';
import pify from 'pify';
import Vinyl from 'vinyl';
import getStream from 'get-stream';
import test from 'ava';
import m from '.';
import gulpImagemin from '.';

const fsP = pify(fs);
const readFile = promisify(fs.readFile);

const createFixture = async (plugins, file = 'fixture.png') => {
const buf = await fsP.readFile(path.join(__dirname, file));
const stream = m(plugins);
const buffer = await readFile(path.join(__dirname, file));
const stream = gulpImagemin(plugins);

stream.end(new Vinyl({
path: path.join(__dirname, file),
contents: buf
contents: buffer
}));

return {buf, stream};
return {buffer, stream};
};

test('minify images', async t => {
const {buf, stream} = await createFixture();
const {buffer, stream} = await createFixture();
const file = await getStream.array(stream);

t.true(file[0].contents.length < buf.length);
t.true(file[0].contents.length < buffer.length);
});

test('use custom plugins', async t => {
@@ -44,7 +44,7 @@ test('use custom svgo settings', async t => {
pretty: true
}
};
const {stream} = await createFixture([m.svgo(svgoOpts)], 'fixture-svg-logo.svg');
const {stream} = await createFixture([gulpImagemin.svgo(svgoOpts)], 'fixture-svg-logo.svg');
const compareStream = (await createFixture(null, 'fixture-svg-logo.svg')).stream;
const file = await getStream.array(stream);
const compareFile = await getStream.array(compareStream);
@@ -53,7 +53,7 @@ test('use custom svgo settings', async t => {
});

test('skip unsupported images', async t => {
const stream = m();
const stream = gulpImagemin();
stream.end(new Vinyl({path: path.join(__dirname, 'fixture.bmp')}));
const file = await getStream.array(stream);