Skip to content

Commit

Permalink
Update: Remove node-v8-clone optionalDependency
Browse files Browse the repository at this point in the history
  • Loading branch information
yocontra authored and phated committed Sep 27, 2016
1 parent cb09ad0 commit cbe8d37
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 36 deletions.
14 changes: 3 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
var path = require('path');

var clone;
try {
clone = require('node-v8-clone').clone;
} catch(e) {
clone = require('lodash').clone;
}
var clone = require('lodash').clone;
var cloneStats = require('clone-stats');
var cloneBuffer = require('./lib/cloneBuffer');
var isBuffer = require('./lib/isBuffer');
Expand Down Expand Up @@ -76,10 +70,8 @@ File.prototype.clone = function(opt) {
if (this.isStream()) {
file.contents = this.contents.pipe(new Stream.PassThrough());
this.contents = this.contents.pipe(new Stream.PassThrough());
} else if (opt.contents && this.isBuffer()) {
file.contents = cloneBuffer(this.contents);
} else {
file.contents = this.contents;
} else if (this.isBuffer()) {
file.contents = opt.contents ? cloneBuffer(this.contents) : this.contents;
}

// clone our custom properties
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"lodash.templatesettings": "^2.4.1",
"event-stream": "^3.1.0"
},
"optionalDependencies": {
"node-v8-clone": "~0.6.2"
},
"scripts": {
"test": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec && jshint .",
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
Expand Down
59 changes: 59 additions & 0 deletions perf/clone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var File = require('../');

var contents = new Buffer('blah blah blah');

var originalFile = new File({
path: 'yo.coffee',
contents: contents
});

// simulate some history
originalFile.path = 'yo.js';
originalFile.path = 'yo.js';
originalFile.path = 'yo.js';
originalFile.path = 'yo.js';
originalFile.path = 'yo.js';

originalFile.ast = {
a: {
b: {
c: {
a: {
b: {
c: {
a: {
b: {
c: {
a: {
b: {
c: {
a: {
b: {
c: {
a: {
b: {
c: {

}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
};

for (var i = 0; i < 10000; i++) {
originalFile.clone(true).ast;
}
24 changes: 2 additions & 22 deletions test/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@ var Stream = require('stream');
var fs = require('fs');
var path = require('path');
var es = require('event-stream');
var File = require('../');

var should = require('should');
require('mocha');

describe('File', function() {

describe('using node-v8-clone', function() {
var File = require('../');
testFile(File);
});

describe('using lodash', function() {
delete require.cache[path.join(__dirname, '../index.js')];
var clonePath = path.join(__dirname, '../node_modules/node-v8-clone/lib/clone.js');
var exports = require.cache[clonePath].exports;
// test lodash when node-v8-clone is not found
require.cache[clonePath].exports = undefined;
after(function() {
require.cache[clonePath].exports = exports;
});
var File = require('../');
testFile(File);
});
});

function testFile(File) {
describe('constructor()', function() {
it('should default cwd to process.cwd', function(done) {
var file = new File();
Expand Down Expand Up @@ -755,4 +735,4 @@ function testFile(File) {
}).should.throw('path should be string');
});
});
}
});

0 comments on commit cbe8d37

Please sign in to comment.