Skip to content

Commit

Permalink
Drop dependency on deprecated gulp-util (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
grig0ry authored and sindresorhus committed Dec 30, 2017
1 parent 4d1ed1c commit 128205c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
13 changes: 7 additions & 6 deletions index.js
@@ -1,7 +1,8 @@
'use strict';
const fs = require('fs');
const path = require('path');
const gutil = require('gulp-util');
const replaceExt = require('replace-ext');
const PluginError = require('plugin-error');
const through = require('through2');
const pify = require('pify');

Expand All @@ -11,7 +12,7 @@ const stat = pify(fs.stat);
// Ignore missing file error
function fsOperationFailed(stream, sourceFile, err) {
if (err.code !== 'ENOENT') {
stream.emit('error', new gutil.PluginError('gulp-changed', err, {
stream.emit('error', new PluginError('gulp-changed', err, {
fileName: sourceFile.path
}));
}
Expand Down Expand Up @@ -46,26 +47,26 @@ module.exports = (dest, opts) => {
}, opts);

if (!dest) {
throw new gutil.PluginError('gulp-changed', '`dest` required');
throw new PluginError('gulp-changed', '`dest` required');
}

if (opts.transformPath !== undefined && typeof opts.transformPath !== 'function') {
throw new gutil.PluginError('gulp-changed', '`opts.transformPath` needs to be a function');
throw new PluginError('gulp-changed', '`opts.transformPath` needs to be a function');
}

return through.obj(function (file, enc, cb) {
const dest2 = typeof dest === 'function' ? dest(file) : dest;
let newPath = path.resolve(opts.cwd, dest2, file.relative);

if (opts.extension) {
newPath = gutil.replaceExtension(newPath, opts.extension);
newPath = replaceExt(newPath, opts.extension);
}

if (opts.transformPath) {
newPath = opts.transformPath(newPath);

if (typeof newPath !== 'string') {
throw new gutil.PluginError('gulp-changed', '`opts.transformPath` needs to return a string');
throw new PluginError('gulp-changed', '`opts.transformPath` needs to return a string');
}
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -49,9 +49,10 @@
"passthrough"
],
"dependencies": {
"gulp-util": "^3.0.0",
"make-dir": "^1.1.0",
"pify": "^3.0.0",
"plugin-error": "^0.1.2",
"replace-ext": "^1.0.0",
"through2": "^2.0.0",
"touch": "^3.1.0"
},
Expand All @@ -62,6 +63,7 @@
"figures": "^2.0.0",
"get-stream": "^3.0.0",
"gulp": "^3.0.0",
"vinyl": "^2.1.0",
"xo": "*"
}
}
6 changes: 3 additions & 3 deletions test.js
Expand Up @@ -4,7 +4,7 @@ import touch from 'touch';
import makeDir from 'make-dir';
import test from 'ava';
import gulp from 'gulp';
import gutil from 'gulp-util';
import Vinyl from 'vinyl';
import del from 'del';
import getStream from 'get-stream';
import figures from 'figures';
Expand Down Expand Up @@ -39,7 +39,7 @@ const macro = (t, opts) => {
return resolve();
});

stream.write(new gutil.File({
stream.write(new Vinyl({
cwd: __dirname,
base: __dirname,
path: 'foo.js',
Expand All @@ -49,7 +49,7 @@ const macro = (t, opts) => {
}
}));

stream.write(new gutil.File({
stream.write(new Vinyl({
base: __dirname,
path: 'bar.js',
contents: Buffer.from(''),
Expand Down

0 comments on commit 128205c

Please sign in to comment.