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

Move away from gutil, use Vinyl & PluginError #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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({
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({
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({
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({
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);
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