Skip to content

Commit

Permalink
Removed use of deprecated gutil (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbennett10 authored and sindresorhus committed Dec 30, 2017
1 parent d33fc30 commit adb1e87
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const path = require('path');
const gutil = require('gulp-util');
const log = require('fancy-log');
const PluginError = require('plugin-error');
const through = require('through2-concurrent');
const prettyBytes = require('pretty-bytes');
const chalk = require('chalk');
Expand All @@ -14,7 +15,7 @@ const loadPlugin = (plugin, args) => {
try {
return require(`imagemin-${plugin}`).apply(null, args);
} catch (err) {
gutil.log(`${PLUGIN_NAME}: Couldn't load default plugin "${plugin}"`);
log(`${PLUGIN_NAME}: Couldn't load default plugin "${plugin}"`);
}
};

Expand Down Expand Up @@ -61,13 +62,13 @@ module.exports = (plugins, opts) => {
}

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

if (validExts.indexOf(path.extname(file.path).toLowerCase()) === -1) {
if (opts.verbose) {
gutil.log(`${PLUGIN_NAME}: Skipping unsupported image ${chalk.blue(file.relative)}`);
log(`${PLUGIN_NAME}: Skipping unsupported image ${chalk.blue(file.relative)}`);
}

cb(null, file);
Expand All @@ -92,15 +93,15 @@ module.exports = (plugins, opts) => {
}

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

gutil.log(PLUGIN_NAME + ':', msg);
log(PLUGIN_NAME + ':', msg);
cb();
});
};
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
],
"dependencies": {
"chalk": "^2.1.0",
"gulp-util": "^3.0.8",
"fancy-log": "^1.3.2",
"plugin-error": "^0.1.2",
"imagemin": "^5.3.1",
"plur": "^2.1.2",
"pretty-bytes": "^4.0.2",
Expand All @@ -47,7 +48,8 @@
"get-stream": "^3.0.0",
"imagemin-pngquant": "^5.0.1",
"pify": "^3.0.0",
"xo": "*"
"xo": "*",
"vinyl": "^2.1.0"
},
"optionalDependencies": {
"imagemin-gifsicle": "^5.2.0",
Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';
import gutil from 'gulp-util';
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 '.';
Expand All @@ -13,7 +13,7 @@ const createFixture = async plugins => {
const buf = await fsP.readFile('fixture.png');
const stream = m(plugins);

stream.end(new gutil.File({
stream.end(new Vinyl({
path: path.join(__dirname, 'fixture.png'),
contents: buf
}));
Expand All @@ -39,7 +39,7 @@ test('use custom plugins', async t => {

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

t.is(file[0].contents, null);
Expand Down

0 comments on commit adb1e87

Please sign in to comment.