vinyl
Advanced tools
Comparing version 0.3.2 to 0.3.3
19
index.js
@@ -16,2 +16,5 @@ var path = require('path'); | ||
// record path change | ||
this.history = file.path ? [file.path] : []; | ||
// TODO: should this be moved to vinyl-fs? | ||
@@ -21,4 +24,2 @@ this.cwd = file.cwd || process.cwd(); | ||
this.path = file.path || null; | ||
// stat = fs stats object | ||
@@ -132,2 +133,16 @@ // TODO: should this be moved to vinyl-fs? | ||
Object.defineProperty(File.prototype, 'path', { | ||
get: function() { | ||
return this.history[this.history.length - 1]; | ||
}, | ||
set: function(path) { | ||
if (typeof path !== 'string') throw new Error('path should be string'); | ||
// record history only when path changed | ||
if (path && path !== this.path) { | ||
this.history.push(path); | ||
} | ||
} | ||
}); | ||
module.exports = File; |
{ | ||
"name": "vinyl", | ||
"description": "A virtual file format", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"homepage": "http://github.com/wearefractal/vinyl", | ||
@@ -10,19 +10,19 @@ "repository": "git://github.com/wearefractal/vinyl.git", | ||
"dependencies": { | ||
"clone-stats": "~0.0.1", | ||
"clone-stats": "^0.0.1", | ||
"lodash": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.17.0", | ||
"should": "~2.1.1", | ||
"mocha-lcov-reporter": "0.0.1", | ||
"coveralls": "~2.6.1", | ||
"istanbul": "~0.2.3", | ||
"rimraf": "~2.2.5", | ||
"jshint": "~2.4.1", | ||
"buffer-equal": "0.0.0", | ||
"lodash.templatesettings": "~2.4.1", | ||
"event-stream": "~3.1.0" | ||
"mocha": "^1.17.0", | ||
"should": "^4.0.4", | ||
"mocha-lcov-reporter": "^0.0.1", | ||
"coveralls": "^2.6.1", | ||
"istanbul": "^0.3.0", | ||
"rimraf": "^2.2.5", | ||
"jshint": "^2.4.1", | ||
"buffer-equal": "0.0.1", | ||
"lodash.templatesettings": "^2.4.1", | ||
"event-stream": "^3.1.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha --reporter spec && jshint", | ||
"test": "mocha --reporter spec && jshint . --exclude node_modules", | ||
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" | ||
@@ -29,0 +29,0 @@ }, |
@@ -20,2 +20,6 @@ # vinyl [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status](https://david-dm.org/wearefractal/vinyl.png?theme=shields.io)](https://david-dm.org/wearefractal/vinyl) | ||
## What is this? | ||
Read this for more info about how this plays into the grand scheme of things https://medium.com/@eschoff/3828e8126466 | ||
## File | ||
@@ -22,0 +26,0 @@ |
@@ -84,3 +84,3 @@ var File = require('../'); | ||
}); | ||
describe('isBuffer()', function() { | ||
@@ -248,6 +248,6 @@ it('should return true when the contents are a Buffer', function(done) { | ||
copy.stat.isFile().should.be.true; | ||
copy.stat.isDirectory().should.be.false; | ||
should(file.stat instanceof fs.Stats).be.true; | ||
should(copy.stat instanceof fs.Stats).be.true; | ||
copy.stat.isFile().should.equal(true); | ||
copy.stat.isDirectory().should.equal(false); | ||
should(file.stat instanceof fs.Stats).equal(true); | ||
should(copy.stat instanceof fs.Stats).equal(true); | ||
@@ -411,3 +411,3 @@ done(); | ||
}); | ||
describe('inspect()', function() { | ||
@@ -475,3 +475,3 @@ it('should return correct format when no contents and no path', function(done) { | ||
}); | ||
describe('contents get/set', function() { | ||
@@ -568,2 +568,61 @@ it('should work with Buffer', function(done) { | ||
describe('path get/set', function() { | ||
it('should record history when instantiation', function() { | ||
var file = new File({ | ||
cwd: '/', | ||
path: '/test/test.coffee' | ||
}); | ||
file.path.should.eql('/test/test.coffee'); | ||
file.history.should.eql(['/test/test.coffee']); | ||
}); | ||
it('should record history when path change', function() { | ||
var file = new File({ | ||
cwd: '/', | ||
path: '/test/test.coffee' | ||
}); | ||
file.path = '/test/test.js'; | ||
file.path.should.eql('/test/test.js'); | ||
file.history.should.eql(['/test/test.coffee', '/test/test.js']); | ||
file.path = '/test/test.coffee'; | ||
file.path.should.eql('/test/test.coffee'); | ||
file.history.should.eql(['/test/test.coffee', '/test/test.js', '/test/test.coffee']); | ||
}); | ||
it('should not record history when set the same path', function() { | ||
var file = new File({ | ||
cwd: '/', | ||
path: '/test/test.coffee' | ||
}); | ||
file.path = '/test/test.coffee'; | ||
file.path = '/test/test.coffee'; | ||
file.path.should.eql('/test/test.coffee'); | ||
file.history.should.eql(['/test/test.coffee']); | ||
// ignore when set empty string | ||
file.path = ''; | ||
file.path.should.eql('/test/test.coffee'); | ||
file.history.should.eql(['/test/test.coffee']); | ||
}); | ||
it('should throw when set path null', function() { | ||
var file = new File({ | ||
cwd: '/', | ||
path: null | ||
}); | ||
should.not.exist(file.path); | ||
file.history.should.eql([]); | ||
(function() { | ||
file.path = null; | ||
}).should.throw('path should be string'); | ||
}); | ||
}); | ||
}); |
31801
819
128
Updatedclone-stats@^0.0.1