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

Drop dependency on deprecated gulp-util #72

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
const fs = require('fs');
const path = require('path');
const gutil = require('gulp-util');
const PluginError = require('plugin-error');
const replaceExtension = require('replace-ext');
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 = replaceExtension(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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
"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"
"touch": "^3.1.0",
"vinyl": "^2.1.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vinyl should be in the devDependencies. Could you update it please?

},
"devDependencies": {
"ava": "^0.23.0",
Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
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