Skip to content

Commit

Permalink
Replace event-stream dependency by readable-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
generalov-epm authored and demurgos committed May 7, 2019
1 parent b096453 commit 09db435
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var es = require('event-stream');
var stream = require('readable-stream');
var log = require('fancy-log');
var tinyLr = require('tiny-lr');
var relative = require('path').relative;
Expand Down Expand Up @@ -39,10 +39,12 @@ var options = {
module.exports = exports = function(opts) {
options = _assign(options, opts);

var glr = es.map(function(file, done) {
var glr = new stream.PassThrough({
objectMode: true,
});
glr.on('data', function(file) {
var filePath = file.path;
exports.changed(filePath);
done(null, file);
});

if (options.start) exports.listen(options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"dependencies": {
"chalk": "^2.4.1",
"debug": "^3.1.0",
"event-stream": "3.3.4",
"fancy-log": "^1.3.2",
"lodash.assign": "^4.2.0",
"readable-stream": "^3.0.6",
"tiny-lr": "^1.1.1",
"vinyl": "^2.2.0"
},
Expand Down
38 changes: 21 additions & 17 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var assert = require('assert');
var es = require('event-stream');
var stream = require('readable-stream');
var path = require('path');
var sinon = require('sinon');
var tinyLr = require('tiny-lr');
Expand All @@ -14,6 +14,14 @@ var file = new Vinyl({ base: cwd, cwd: cwd, path: cwd + '/style.css' });
var keys = ['basePath', 'key', 'cert', 'start', 'quiet', 'reloadPage'];
var srv, log;

function readable(callback) {
var r = new stream.Readable({
objectMode: true
});
callback.apply(r)
return r;
}

describe('gulp-livereload', function() {
beforeEach(function() {
srv = sinon.stub(tinyLr, 'Server');
Expand All @@ -30,10 +38,9 @@ describe('gulp-livereload', function() {
it('does not work', function(done) {
var spy = sinon.spy();
srv.returns({ changed: spy , listen: function() {}});
es.readable(function(count, next) {
this.emit('data', file);
this.emit('end');
next();
readable(function() {
this.push(file);
this.push(null);
})
.pipe(glr({ basePath: cwd }))
.on('end', function() {
Expand All @@ -46,10 +53,9 @@ describe('gulp-livereload', function() {
srv.returns({ changed: spy , listen: function() {}});
var lr = glr();
glr.listen();
es.readable(function(count, next) {
this.emit('data', file);
this.emit('end');
next();
readable(function() {
this.push(file);
this.push(null);
})
.pipe(lr)
.on('end', function() {
Expand Down Expand Up @@ -115,10 +121,9 @@ describe('gulp-livereload', function() {
var spy = sinon.spy();
srv.returns({ changed: spy , listen: function() {}});
glr.listen();
es.readable(function(count, next) {
this.emit('data', file);
this.emit('end');
next();
readable(function() {
this.push(file);
this.push(null);
})
.pipe(glr({ basePath: process.cwd() }))
.on('end', function() {
Expand All @@ -129,10 +134,9 @@ describe('gulp-livereload', function() {
it('option: start', function(done) {
var spy = sinon.spy();
srv.returns({ changed: spy , listen: function() {}});
es.readable(function(count, next) {
this.emit('data', file);
this.emit('end');
next();
readable(function() {
this.push(file);
this.push(null);
})
.pipe(glr({ start: true }))
.on('end', function() {
Expand Down

0 comments on commit 09db435

Please sign in to comment.