Skip to content

Commit

Permalink
Require Node.js 6 and update dependencies (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored and sindresorhus committed Nov 6, 2018
1 parent 658ec66 commit b57f1d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sudo: false
language: node_js
node_js:
- '8'
- '6'
- '4'
- "10"
- "8"
- "6"
25 changes: 10 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const path = require('path');
const log = require('fancy-log');
const PluginError = require('plugin-error');
Expand All @@ -11,19 +10,15 @@ const plur = require('plur');
const PLUGIN_NAME = 'gulp-imagemin';
const defaultPlugins = ['gifsicle', 'jpegtran', 'optipng', 'svgo'];

const loadPlugin = (plugin, args) => {
const loadPlugin = (plugin, ...args) => {
try {
return require(`imagemin-${plugin}`).apply(null, args);
} catch (err) {
return require(`imagemin-${plugin}`)(args);
} catch (error) {
log(`${PLUGIN_NAME}: Couldn't load default plugin "${plugin}"`);
}
};

const exposePlugin = plugin =>
function () {
const args = [].slice.call(arguments);
return loadPlugin(plugin, args);
};
const exposePlugin = (plugin, ...args) => loadPlugin(plugin, args);

const getDefaultPlugins = () =>
defaultPlugins.reduce((plugins, plugin) => {
Expand All @@ -44,7 +39,7 @@ module.exports = (plugins, opts) => {

opts = Object.assign({
// TODO: remove this when gulp get's a real logger with levels
verbose: process.argv.indexOf('--verbose') !== -1
verbose: process.argv.includes('--verbose')
}, opts);

const validExts = ['.jpg', '.jpeg', '.png', '.gif', '.svg'];
Expand All @@ -66,7 +61,7 @@ module.exports = (plugins, opts) => {
return;
}

if (validExts.indexOf(path.extname(file.path).toLowerCase()) === -1) {
if (!validExts.includes(path.extname(file.path).toLowerCase())) {
if (opts.verbose) {
log(`${PLUGIN_NAME}: Skipping unsupported image ${chalk.blue(file.relative)}`);
}
Expand All @@ -93,15 +88,15 @@ module.exports = (plugins, opts) => {
}

if (opts.verbose) {
log(PLUGIN_NAME + ':', chalk.green('✔ ') + file.relative + chalk.gray(` (${msg})`));
log(`${PLUGIN_NAME}:`, chalk.green('✔ ') + file.relative + chalk.gray(` (${msg})`));
}

file.contents = data;
cb(null, file);
})
.catch(err => {
.catch(error => {
// TODO: remove this setImmediate when gulp 4 is targeted
setImmediate(cb, new PluginError(PLUGIN_NAME, err, {fileName: file.path}));
setImmediate(cb, new PluginError(PLUGIN_NAME, error, {fileName: file.path}));
});
}, cb => {
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
Expand All @@ -111,7 +106,7 @@ module.exports = (plugins, opts) => {
msg += chalk.gray(` (saved ${prettyBytes(totalSavedBytes)} - ${percent.toFixed(1).replace(/\.0$/, '')}%)`);
}

log(PLUGIN_NAME + ':', msg);
log(`${PLUGIN_NAME}:`, msg);
cb();
});
};
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -35,26 +35,26 @@
"svg"
],
"dependencies": {
"chalk": "^2.1.0",
"chalk": "^2.4.1",
"fancy-log": "^1.3.2",
"plugin-error": "^0.1.2",
"imagemin": "^5.3.1",
"plur": "^2.1.2",
"pretty-bytes": "^4.0.2",
"through2-concurrent": "^1.1.1"
"plugin-error": "^1.0.1",
"imagemin": "^6.0.0",
"plur": "^3.0.1",
"pretty-bytes": "^5.1.0",
"through2-concurrent": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"get-stream": "^3.0.0",
"imagemin-pngquant": "^5.0.1",
"pify": "^3.0.0",
"xo": "*",
"vinyl": "^2.1.0"
"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"
},
"optionalDependencies": {
"imagemin-gifsicle": "^5.2.0",
"imagemin-jpegtran": "^5.0.2",
"imagemin-optipng": "^5.2.1",
"imagemin-svgo": "^6.0.0"
"imagemin-gifsicle": "^6.0.1",
"imagemin-jpegtran": "^6.0.0",
"imagemin-optipng": "^6.0.0",
"imagemin-svgo": "^7.0.0"
}
}

0 comments on commit b57f1d6

Please sign in to comment.