Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vinyl-fs

Package Overview
Dependencies
Maintainers
2
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.13 to 1.0.0

lib/prepareWrite.js

1

index.js

@@ -6,3 +6,4 @@ 'use strict';

dest: require('./lib/dest'),
symlink: require('./lib/symlink'),
watch: require('glob-watcher')
};

44

lib/dest/index.js
'use strict';
var defaults = require('defaults');
var path = require('path');
var through2 = require('through2');
var mkdirp = require('mkdirp');
var fs = require('graceful-fs');
var prepareWrite = require('../prepareWrite');
var writeContents = require('./writeContents');
function dest(outFolder, opt) {
opt = opt || {};
if (typeof outFolder !== 'string' && typeof outFolder !== 'function') {
throw new Error('Invalid output folder');
}
var options = defaults(opt, {
cwd: process.cwd()
});
if (typeof options.mode === 'string') {
options.mode = parseInt(options.mode, 8);
}
var cwd = path.resolve(options.cwd);
function saveFile (file, enc, cb) {
var basePath;
if (typeof outFolder === 'string') {
basePath = path.resolve(cwd, outFolder);
}
if (typeof outFolder === 'function') {
basePath = path.resolve(cwd, outFolder(file));
}
var writePath = path.resolve(basePath, file.relative);
var writeFolder = path.dirname(writePath);
// wire up new properties
file.stat = file.stat ? file.stat : new fs.Stats();
file.stat.mode = (options.mode || file.stat.mode);
file.cwd = cwd;
file.base = basePath;
file.path = writePath;
// mkdirp the folder the file is going in
mkdirp(writeFolder, function(err){
function saveFile(file, enc, cb) {
prepareWrite(outFolder, file, opt, function(err, writePath) {
if (err) {

@@ -49,0 +11,0 @@ return cb(err);

@@ -9,12 +9,34 @@ 'use strict';

function writeContents(writePath, file, cb) {
var written = function(err) {
var done = function(err) {
cb(err, file);
};
if (err) {
return done(err);
// if directory then mkdirp it
if (file.isDirectory()) {
return writeDir(writePath, file, written);
}
// stream it to disk yo
if (file.isStream()) {
return writeStream(writePath, file, written);
}
// write it like normal
if (file.isBuffer()) {
return writeBuffer(writePath, file, written);
}
// if no contents then do nothing
if (file.isNull()) {
return complete();
}
function complete(err) {
cb(err, file);
}
function written(err) {
if (isErrorFatal(err)) {
return complete(err);
}
if (!file.stat || typeof file.stat.mode !== 'number') {
return done();
return complete();
}

@@ -24,3 +46,3 @@

if (err) {
return done(err);
return complete(err);
}

@@ -30,30 +52,20 @@ // octal 7777 = decimal 4095

if (currentMode === file.stat.mode) {
return done();
return complete();
}
fs.chmod(writePath, file.stat.mode, done);
fs.chmod(writePath, file.stat.mode, complete);
});
};
// if directory then mkdirp it
if (file.isDirectory()) {
writeDir(writePath, file, written);
return;
}
// stream it to disk yo
if (file.isStream()) {
writeStream(writePath, file, written);
return;
}
function isErrorFatal(err) {
if (!err) {
return false;
}
// write it like normal
if (file.isBuffer()) {
writeBuffer(writePath, file, written);
return;
}
// Handle scenario for file overwrite failures.
else if (err.code === 'EEXIST' && file.flag === 'wx') {
return false; // "These aren't the droids you're looking for"
}
// if no contents then do nothing
if (file.isNull()) {
cb(null, file);
return;
// Otherwise, this is a fatal error
return true;
}

@@ -60,0 +72,0 @@ }

@@ -7,3 +7,4 @@ 'use strict';

var opt = {
mode: file.stat.mode
mode: file.stat.mode,
flag: file.flag
};

@@ -10,0 +11,0 @@

@@ -5,3 +5,3 @@ 'use strict';

function writeDir (writePath, file, cb) {
function writeDir(writePath, file, cb) {
mkdirp(writePath, file.stat.mode, cb);

@@ -8,0 +8,0 @@ }

@@ -6,5 +6,6 @@ 'use strict';

function writeStream (writePath, file, cb) {
function writeStream(writePath, file, cb) {
var opt = {
mode: file.stat.mode
mode: file.stat.mode,
flag: file.flag
};

@@ -14,11 +15,21 @@

file.contents.once('error', cb);
outStream.once('error', cb);
outStream.once('finish', function() {
streamFile(file, cb);
});
file.contents.once('error', complete);
outStream.once('error', complete);
outStream.once('finish', success);
file.contents.pipe(outStream);
function success() {
streamFile(file, complete);
}
// cleanup
function complete(err) {
file.contents.removeListener('error', cb);
outStream.removeListener('error', cb);
outStream.removeListener('finish', success);
cb(err);
}
}
module.exports = writeStream;

@@ -7,3 +7,3 @@ 'use strict';

function bufferFile(file, cb) {
fs.readFile(file.path, function (err, data) {
fs.readFile(file.path, function(err, data) {
if (err) {

@@ -10,0 +10,0 @@ return cb(err);

'use strict';
var through2 = require('through2');
var readDir = require('./readDir');

@@ -10,3 +9,3 @@ var bufferFile = require('./bufferFile');

function getContents(opt) {
return through2.obj(function (file, enc, cb) {
return through2.obj(function(file, enc, cb) {
// don't fail to read a directory

@@ -13,0 +12,0 @@ if (file.isDirectory()) {

'use strict';
var defaults = require('defaults');
var assign = require('object-assign');
var through = require('through2');
var gs = require('glob-stream');
var File = require('vinyl');
var duplexify = require('duplexify');
var merge = require('merge-stream');
var filterSince = require('./filterSince');
var getContents = require('./getContents');
var getStats = require('./getStats');
var resolveSymlinks = require('./resolveSymlinks');
function createFile (globFile, enc, cb) {
function createFile(globFile, enc, cb) {
cb(null, new File(globFile));

@@ -16,4 +19,7 @@ }

function src(glob, opt) {
opt = opt || {};
var pass = through.obj();
var options = assign({
read: true,
buffer: true
}, opt);
var pass, inputPass;

@@ -25,18 +31,20 @@ if (!isValidGlob(glob)) {

if (Array.isArray(glob) && glob.length === 0) {
process.nextTick(pass.end.bind(pass));
pass = through.obj();
if (!options.passthrough) {
process.nextTick(pass.end.bind(pass));
}
return pass;
}
var options = defaults(opt, {
read: true,
buffer: true
});
var globStream = gs.create(glob, options);
// when people write to use just pass it through
var outputStream = globStream
.pipe(through.obj(createFile))
.pipe(getStats(options));
.pipe(resolveSymlinks())
.pipe(through.obj(createFile));
if (options.since) {
outputStream = outputStream
.pipe(filterSince(options.since));
}
if (options.read !== false) {

@@ -47,3 +55,8 @@ outputStream = outputStream

return outputStream.pipe(pass);
if (options.passthrough) {
inputPass = through.obj();
outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass));
}
return outputStream;
}

@@ -55,11 +68,11 @@

}
if (Array.isArray(glob) && glob.length !== 0) {
if (!Array.isArray(glob)) {
return false;
}
if (glob.length !== 0) {
return glob.every(isValidGlob);
}
if (Array.isArray(glob) && glob.length === 0) {
return true;
}
return false;
return true;
}
module.exports = src;
{
"name": "vinyl-fs",
"description": "Vinyl adapter for the file system",
"version": "0.3.13",
"version": "1.0.0",
"homepage": "http://github.com/wearefractal/vinyl-fs",

@@ -14,7 +14,9 @@ "repository": "git://github.com/wearefractal/vinyl-fs.git",

"dependencies": {
"defaults": "^1.0.0",
"glob-stream": "^3.1.5",
"glob-watcher": "^0.0.6",
"duplexify": "^3.2.0",
"glob-stream": "^4.0.1",
"glob-watcher": "^0.0.8",
"graceful-fs": "^3.0.0",
"merge-stream": "^0.1.7",
"mkdirp": "^0.5.0",
"object-assign": "^2.0.0",
"strip-bom": "^1.0.0",

@@ -26,14 +28,14 @@ "through2": "^0.6.1",

"buffer-equal": "^0.0.1",
"coveralls": "^2.6.1",
"istanbul": "^0.3.0",
"istanbul-coveralls": "^1.0.1",
"jshint": "^2.4.1",
"mocha": "^2.0.0",
"mocha-lcov-reporter": "^0.0.1",
"mocha-lcov-reporter": "^0.0.2",
"rimraf": "^2.2.5",
"should": "^4.0.0",
"should": "^5.0.0",
"sinon": "^1.10.3"
},
"scripts": {
"test": "mocha --reporter spec && jshint lib",
"coveralls": "istanbul cover _mocha -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
"test": "jshint lib && mocha",
"coveralls": "istanbul cover _mocha && istanbul-coveralls"
},

@@ -43,3 +45,2 @@ "engines": {

},
"engineStrict": true,
"licenses": [

@@ -46,0 +47,0 @@ {

@@ -1,2 +0,2 @@

# vinyl-fs [![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-fs)
# vinyl-fs [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url]

@@ -40,2 +40,14 @@ ## Information

- Takes a glob string or an array of glob strings as the first argument.
- Globs are executed in order, so negations should follow positive globs. For example:
```js
fs.src(['!b*.js', '*.js'])
```
would not exclude any files, but this would
```js
fs.src(['*.js', '!b*.js'])
```
- Possible options for the second argument:

@@ -50,5 +62,6 @@ - cwd - Specify the working directory the folder is relative to. Default is `process.cwd()`

- `false` will disable writing the file to disk via `.dest()`
- since - `Date` or `number` if you only want files that have been modified since the time specified.
- passthrough - `true` or `false` if you want a duplex stream which passes items through and emits globbed files.
- Any glob-related options are documented in [glob-stream] and [node-glob]
- Returns a Readable/Writable stream.
- On write the stream will simply pass items through.
- Returns a Readable stream by default, or a Duplex stream if the `passthrough` option is set to `true`.
- This stream emits matching [vinyl] File objects

@@ -73,7 +86,9 @@

- cwd - Specify the working directory the folder is relative to. Default is `process.cwd()`
- mode - Specify the mode the files should be created with. Default is the mode of the input file (file.stat.mode)
- mode - Specify the mode the files should be created with. Default is the mode of the input file (file.stat.mode) or the process mode if the input file has no mode property.
- dirMode - Specify the mode the directory should be created with. Default is the process mode.
- overwrite - Specify if existing files with the same path should be overwritten or not. Default is `true`, to always overwrite existing files
- Returns a Readable/Writable stream.
- On write the stream will save the [vinyl] File to disk at the folder/cwd specified.
- After writing the file to disk, it will be emitted from the stream so you can keep piping these around
- The file will be modified after being written to this stream
- After writing the file to disk, it will be emitted from the stream so you can keep piping these around.
- The file will be modified after being written to this stream:
- `cwd`, `base`, and `path` will be overwritten to match the folder

@@ -83,2 +98,15 @@ - `stat.mode` will be overwritten if you used a mode parameter

### symlink(folder[, opt])
- Takes a folder path as the first argument.
- First argument can also be a function that takes in a file and returns a folder path.
- Possible options for the second argument:
- cwd - Specify the working directory the folder is relative to. Default is `process.cwd()`
- dirMode - Specify the mode the directory should be created with. Default is the process mode.
- Returns a Readable/Writable stream.
- On write the stream will create a symbolic link (i.e. symlink) on disk at the folder/cwd specified.
- After creating the symbolic link, it will be emitted from the stream so you can keep piping these around.
- The file will be modified after being written to this stream:
- `cwd`, `base`, and `path` will be overwritten to match the folder
[glob-stream]: https://github.com/wearefractal/glob-stream

@@ -90,9 +118,9 @@ [node-glob]: https://github.com/isaacs/node-glob

[npm-url]: https://npmjs.org/package/vinyl-fs
[npm-image]: https://badge.fury.io/js/vinyl-fs.png
[npm-url]: https://www.npmjs.com/package/vinyl-fs
[npm-image]: https://badge.fury.io/js/vinyl-fs.svg
[travis-url]: https://travis-ci.org/wearefractal/vinyl-fs
[travis-image]: https://travis-ci.org/wearefractal/vinyl-fs.png?branch=master
[travis-image]: https://travis-ci.org/wearefractal/vinyl-fs.svg?branch=master
[coveralls-url]: https://coveralls.io/r/wearefractal/vinyl-fs
[coveralls-image]: https://coveralls.io/repos/wearefractal/vinyl-fs/badge.png
[coveralls-image]: https://img.shields.io/coveralls/wearefractal/vinyl-fs.svg?style=flat
[depstat-url]: https://david-dm.org/wearefractal/vinyl-fs
[depstat-image]: https://david-dm.org/wearefractal/vinyl-fs.png
[depstat-image]: https://david-dm.org/wearefractal/vinyl-fs.svg
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