Skip to content

Commit

Permalink
Move away from gutil, use Vinyl & PluginError
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandoorn committed Mar 7, 2018
1 parent 86bd6b3 commit 6235b49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var path = require('path');
var through = require('through');
var assign = require('object-assign');
var defaults = require('lodash.defaults');
var gutil = require('gulp-util');
var Vinyl = require('vinyl');
var PluginError = require('plugin-error');
var Promise = require('bluebird');
var DEFAULT_OPTIONS = {
fileName: 'busters.json',
Expand All @@ -26,7 +27,7 @@ var OPTION_TYPES = {
var hashesStore = {}; // options.fileName: { relativePath: hash }

function error(msg) {
return new gutil.PluginError('gulp-buster', msg);
return new PluginError('gulp-buster', msg);
}

function hash(file, options) {
Expand Down Expand Up @@ -90,13 +91,13 @@ module.exports = exports = function(options) {
}).then(function(formatted) {
if (typeof formatted !== 'string') throw error('Return/fulfill value of `options.formatter` must be a string');

this.emit('data', new gutil.File({
this.emit('data', new Vinyl.File({
path: path.join(process.cwd(), options.fileName),
contents: new Buffer(formatted),
}));
this.emit('end');
}).catch(function(err) {
this.emit('error', err instanceof gutil.PluginError ? err : error(err));
this.emit('error', err instanceof PluginError ? err : error(err));
});
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
},
"dependencies": {
"bluebird": "^3.3.5",
"gulp-util": "^3.0.7",
"lodash.defaults": "^4.0.1",
"object-assign": "^4.0.1",
"through": "^2.3.8"
"plugin-error": "^1.0",
"through": "^2.3.8",
"vinyl": "^2.0"
},
"engines": {
"node": ">= 0.10"
Expand Down
21 changes: 11 additions & 10 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

var bust = require('..');
var assign = require('object-assign');
var gutil = require('gulp-util');
var Vinyl = require('vinyl');
require('should');

var fileContentStr = 'foo';
var file2ContentStr = 'bar';
var file = new gutil.File({
var file = new Vinyl.File({
cwd: 'C:/users/ult/',
base: 'C:/users/ult/test',
path: 'C:/users/ult/test/file.js',
contents: new Buffer(fileContentStr),
});
var file2 = new gutil.File({
var file2 = new Vinyl.File({
cwd: 'C:/users/ult/',
base: 'C:/users/ult/test',
path: 'C:/users/ult/test/file2.js',
contents: new Buffer(file2ContentStr),
});
var fileBinary = new gutil.File({
var fileBinary = new Vinyl.File({
cwd: 'C:/users/ult/',
base: 'C:/users/ult/test',
path: 'C:/users/ult/test/file2.js',
contents: new Buffer([0x80]), // `Buffer.from` is not supported in Node 0.10
});
var PluginError = require('plugin-error');
var fileBustPath = bust._relativePath(file.cwd, '.', file.path);
var fileBustPathRelative = bust._relativePath(file.cwd, 'test/', file.path);
var file2BustPath = bust._relativePath(file2.cwd, '.', file2.path);
Expand All @@ -41,7 +42,7 @@ beforeEach(bust._reset);
describe('Configuration-independent internal methods', function() {
describe('_error()', function() {
it('should return an instance of PluginError', function() {
bust._error('err').should.be.an.instanceOf(gutil.PluginError);
bust._error('err').should.be.an.instanceOf(PluginError);
});
});

Expand Down Expand Up @@ -106,7 +107,7 @@ describe('Core', function() {
it('should bust two files into the same output file in the same stream', function(done) {
var stream = bust();
stream.on('data', function(newFile) {
newFile.should.be.an.instanceOf(gutil.File);
newFile.should.be.an.instanceOf(Vinyl.File);
newFile.should.have.property('path');
newFile.should.have.property('relative');
newFile.should.have.property('contents');
Expand Down Expand Up @@ -246,7 +247,7 @@ describe('Configuration options', function() {
it('should emit an error when function does not return a string or promise', function(done) {
var stream = bust({ algo: function() {} });
stream.on('error', function(err) {
err.should.be.an.instanceOf(gutil.PluginError);
err.should.be.an.instanceOf(PluginError);
done();
});
stream.end(file);
Expand All @@ -259,7 +260,7 @@ describe('Configuration options', function() {
},
});
stream.on('error', function(err) {
err.should.be.an.instanceOf(gutil.PluginError);
err.should.be.an.instanceOf(PluginError);
done();
});
stream.end(file);
Expand Down Expand Up @@ -370,7 +371,7 @@ describe('Configuration options', function() {
it('should emit an error when function does not return a string or promise', function(done) {
var stream = bust({ formatter: function() {} });
stream.on('error', function(err) {
err.should.be.an.instanceOf(gutil.PluginError);
err.should.be.an.instanceOf(PluginError);
done();
});
stream.end(file);
Expand All @@ -383,7 +384,7 @@ describe('Configuration options', function() {
},
});
stream.on('error', function(err) {
err.should.be.an.instanceOf(gutil.PluginError);
err.should.be.an.instanceOf(PluginError);
done();
});
stream.end(file);
Expand Down

0 comments on commit 6235b49

Please sign in to comment.