Socket
Socket
Sign inDemoInstall

vinyl-fs

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vinyl-fs - npm Package Compare versions

Comparing version 0.3.6 to 0.3.7

test/spy.js

34

lib/dest/writeContents/index.js
'use strict';
var fs = require('fs');
var writeDir = require('./writeDir');

@@ -8,4 +9,25 @@ var writeStream = require('./writeStream');

function writeContents(writePath, file, cb) {
var done = function(err){
cb(err, file);
var written = function(err) {
var done = function(err) {
cb(err, file);
};
if (err) {
return done(err);
}
if (!file.stat || typeof file.stat.mode !== 'number') {
return done();
}
fs.stat(writePath, function(err, st) {
if (err) {
return done(err);
}
// octal 7777 = decimal 4095
var currentMode = (st.mode & 4095);
if (currentMode === file.stat.mode) {
return done();
}
fs.chmod(writePath, file.stat.mode, done);
});
};

@@ -15,3 +37,3 @@

if (file.isDirectory()) {
writeDir(writePath, file, done);
writeDir(writePath, file, written);
return;

@@ -22,3 +44,3 @@ }

if (file.isStream()) {
writeStream(writePath, file, done);
writeStream(writePath, file, written);
return;

@@ -29,3 +51,3 @@ }

if (file.isBuffer()) {
writeBuffer(writePath, file, done);
writeBuffer(writePath, file, written);
return;

@@ -36,3 +58,3 @@ }

if (file.isNull()) {
done();
cb(null, file);
return;

@@ -39,0 +61,0 @@ }

13

package.json
{
"name": "vinyl-fs",
"description": "Vinyl adapter for the file system",
"version": "0.3.6",
"version": "0.3.7",
"homepage": "http://github.com/wearefractal/vinyl-fs",

@@ -15,5 +15,5 @@ "repository": "git://github.com/wearefractal/vinyl-fs.git",

"mkdirp": "^0.5.0",
"strip-bom": "^0.3.0",
"through2": "^0.5.1",
"vinyl": "^0.3.2"
"strip-bom": "^1.0.0",
"through2": "^0.6.1",
"vinyl": "^0.4.0"
},

@@ -23,3 +23,3 @@ "devDependencies": {

"coveralls": "^2.6.1",
"istanbul": "^0.2.3",
"istanbul": "^0.3.0",
"jshint": "^2.4.1",

@@ -29,3 +29,4 @@ "mocha": "^1.17.0",

"rimraf": "^2.2.5",
"should": "^4.0.0"
"should": "^4.0.0",
"sinon": "^1.10.3"
},

@@ -32,0 +33,0 @@ "scripts": {

@@ -0,1 +1,5 @@

var spies = require('./spy');
var chmodSpy = spies.chmodSpy;
var statSpy = spies.statSpy;
var vfs = require('../');

@@ -16,2 +20,5 @@

rimraf(path.join(__dirname, './out-fixtures/'), cb);
spies.setError('false');
statSpy.reset();
chmodSpy.reset();
};

@@ -367,2 +374,241 @@

it('should update file mode to match the vinyl mode', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var startMode = 0655;
var expectedMode = 0722;
var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mode: expectedMode
}
});
var onEnd = function(){
should(chmodSpy.called).be.ok;
buffered.length.should.equal(1);
buffered[0].should.equal(expectedFile);
fs.existsSync(expectedPath).should.equal(true);
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();
};
fs.mkdirSync(expectedBase);
fs.closeSync(fs.openSync(expectedPath, 'w'));
fs.chmodSync(expectedPath, startMode);
chmodSpy.reset();
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});
var buffered = [];
bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);
stream.pipe(bufferStream);
stream.write(expectedFile);
stream.end();
});
it('should update directory mode to match the vinyl mode', function(done) {
var inputBase = path.join(__dirname, './fixtures/');
var inputPath = path.join(__dirname, './fixtures/wow');
var expectedPath = path.join(__dirname, './out-fixtures/wow');
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var firstFile = new File({
base: inputBase,
cwd: __dirname,
path: expectedPath,
stat: fs.statSync(inputPath)
});
var startMode = firstFile.stat.mode;
var expectedMode = 0727;
var expectedFile = new File(firstFile);
expectedFile.stat.mode = (startMode & ~07777) | expectedMode;
var onEnd = function(){
buffered.length.should.equal(2);
buffered[0].should.equal(firstFile);
buffered[1].should.equal(expectedFile);
buffered[0].cwd.should.equal(expectedCwd, 'cwd should have changed');
buffered[0].base.should.equal(expectedBase, 'base should have changed');
buffered[0].path.should.equal(expectedPath, 'path should have changed');
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();
};
fs.mkdirSync(expectedBase);
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});
var buffered = [];
bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);
stream.pipe(bufferStream);
stream.write(firstFile);
stream.write(expectedFile);
stream.end();
});
it('should report IO errors', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedMode = 0722;
var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mode: expectedMode
}
});
fs.mkdirSync(expectedBase);
fs.closeSync(fs.openSync(expectedPath, 'w'));
fs.chmodSync(expectedPath, 0);
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});
stream.on('error', function(err) {
err.code.should.equal('EACCES');
done();
});
stream.write(expectedFile);
});
it('should report stat errors', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedMode = 0722;
var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mode: expectedMode
}
});
fs.mkdirSync(expectedBase);
fs.closeSync(fs.openSync(expectedPath, 'w'));
spies.setError(function(mod, fn) {
if (fn === 'stat' && arguments[2] === expectedPath) {
return new Error('stat error');
}
});
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});
stream.on('error', function(err) {
err.message.should.equal('stat error');
done();
});
stream.write(expectedFile);
});
it('should report chmod errors', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedMode = 0722;
var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mode: expectedMode
}
});
fs.mkdirSync(expectedBase);
fs.closeSync(fs.openSync(expectedPath, 'w'));
spies.setError(function(mod, fn) {
if (fn === 'chmod' && arguments[2] === expectedPath) {
return new Error('chmod error');
}
});
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});
stream.on('error', function(err) {
err.message.should.equal('chmod error');
done();
});
stream.write(expectedFile);
});
it('should not chmod a matching file', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedMode = 0722;
var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mode: expectedMode
}
});
var expectedCount = 0;
spies.setError(function(mod, fn) {
if (fn === 'stat' && arguments[2] === expectedPath) {
expectedCount++;
}
});
var onEnd = function(){
expectedCount.should.equal(1);
should(chmodSpy.called).be.not.ok;
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();
};
fs.mkdirSync(expectedBase);
fs.closeSync(fs.openSync(expectedPath, 'w'));
fs.chmodSync(expectedPath, expectedMode);
statSpy.reset();
chmodSpy.reset();
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});
var buffered = [];
bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);
stream.pipe(bufferStream);
stream.write(expectedFile);
stream.end();
});
['end', 'finish'].forEach(function(eventName) {

@@ -369,0 +615,0 @@ it('should emit ' + eventName + ' event', function(done) {

@@ -0,1 +1,5 @@

var spies = require('./spy');
var chmodSpy = spies.chmodSpy;
var statSpy = spies.statSpy;
var vfs = require('../');

@@ -2,0 +6,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc