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 1.0.0 to 2.0.0

lib/dest/writeContents/writeSymbolicLink.js

3

index.js

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

dest: require('./lib/dest'),
symlink: require('./lib/symlink'),
watch: require('glob-watcher')
symlink: require('./lib/symlink')
};
'use strict';
var through2 = require('through2');
var sourcemaps = require('gulp-sourcemaps');
var duplexify = require('duplexify');
var prepareWrite = require('../prepareWrite');

@@ -8,2 +10,6 @@ var writeContents = require('./writeContents');

function dest(outFolder, opt) {
if (!opt) {
opt = {};
}
function saveFile(file, enc, cb) {

@@ -18,8 +24,10 @@ prepareWrite(outFolder, file, opt, function(err, writePath) {

var stream = through2.obj(saveFile);
// TODO: option for either backpressure or lossy
stream.resume();
return stream;
var mapStream = sourcemaps.write(opt.sourcemaps);
var saveStream = through2.obj(saveFile);
var outputStream = duplexify.obj(mapStream, saveStream);
mapStream.pipe(saveStream);
return outputStream;
}
module.exports = dest;

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

var writeBuffer = require('./writeBuffer');
var writeSymbolicLink = require('./writeSymbolicLink');

@@ -20,2 +21,7 @@ function writeContents(writePath, file, cb) {

// write it as a symlink
if (file.symlink) {
return writeSymbolicLink(writePath, file, written);
}
// write it like normal

@@ -41,3 +47,3 @@ if (file.isBuffer()) {

if (!file.stat || typeof file.stat.mode !== 'number') {
if (!file.stat || typeof file.stat.mode !== 'number' || file.symlink) {
return complete();

@@ -50,8 +56,8 @@ }

}
// octal 7777 = decimal 4095
var currentMode = (st.mode & 4095);
if (currentMode === file.stat.mode) {
var currentMode = (st.mode & parseInt('0777', 8));
var expectedMode = (file.stat.mode & parseInt('0777', 8));
if (currentMode === expectedMode) {
return complete();
}
fs.chmod(writePath, file.stat.mode, complete);
fs.chmod(writePath, expectedMode, complete);
});

@@ -58,0 +64,0 @@ }

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

function success() {
streamFile(file, complete);
streamFile(file, {}, complete);
}

@@ -24,0 +24,0 @@

@@ -8,2 +8,10 @@ 'use strict';

function stringOrFunc(v, file) {
if (typeof v !== 'string' && typeof v !== 'function') {
return null;
}
return typeof v === 'string' ? v : v(file);
}
function prepareWrite(outFolder, file, opt, cb) {

@@ -19,11 +27,12 @@ var options = assign({

var cwd = path.resolve(options.cwd);
if (typeof outFolder !== 'string' && typeof outFolder !== 'function') {
var outFolderPath = stringOrFunc(outFolder, file);
if (!outFolderPath) {
throw new Error('Invalid output folder');
}
var basePath = options.base ?
stringOrFunc(options.base, file) : path.resolve(cwd, outFolderPath);
if (!basePath) {
throw new Error('Invalid base option');
}
var outFolderPath = (
typeof outFolder === 'string' ? outFolder : outFolder(file)
);
var basePath = path.resolve(cwd, outFolderPath);
var writePath = path.resolve(basePath, file.relative);

@@ -30,0 +39,0 @@ var writeFolder = path.dirname(writePath);

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

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

@@ -9,0 +9,0 @@ if (err) {

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

var readDir = require('./readDir');
var readSymbolicLink = require('./readSymbolicLink');
var bufferFile = require('./bufferFile');

@@ -13,12 +14,17 @@ var streamFile = require('./streamFile');

if (file.isDirectory()) {
return readDir(file, cb);
return readDir(file, opt, cb);
}
// process symbolic links included with `followSymlinks` option
if (file.stat && file.stat.isSymbolicLink()) {
return readSymbolicLink(file, opt, cb);
}
// read and pass full contents
if (opt.buffer !== false) {
return bufferFile(file, cb);
return bufferFile(file, opt, cb);
}
// dont buffer anything - just pass streams
return streamFile(file, cb);
return streamFile(file, opt, cb);
});

@@ -25,0 +31,0 @@ }

'use strict';
function readDir(file, cb) {
function readDir(file, opt, cb) {
// do nothing for now

@@ -5,0 +5,0 @@ cb(null, file);

'use strict';
var fs = require('graceful-fs');
var stripBom = require('strip-bom');
var stripBom = require('strip-bom-stream');
function streamFile(file, cb) {
function streamFile(file, opt, cb) {
file.contents = fs.createReadStream(file.path)
.pipe(stripBom.stream());
.pipe(stripBom());
cb(null, file);

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

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

var merge = require('merge-stream');
var sourcemaps = require('gulp-sourcemaps');
var filterSince = require('../filterSince');
var isValidGlob = require('is-valid-glob');
var filterSince = require('./filterSince');
var getContents = require('./getContents');

@@ -22,17 +24,13 @@ var resolveSymlinks = require('./resolveSymlinks');

read: true,
buffer: true
buffer: true,
sourcemaps: false,
passthrough: false,
followSymlinks: true
}, opt);
var pass, inputPass;
var inputPass;
if (!isValidGlob(glob)) {
throw new Error('Invalid glob argument: ' + glob);
}
// return dead stream if empty array
if (Array.isArray(glob) && glob.length === 0) {
pass = through.obj();
if (!options.passthrough) {
process.nextTick(pass.end.bind(pass));
}
return pass;
}

@@ -42,6 +40,6 @@ var globStream = gs.create(glob, options);

var outputStream = globStream
.pipe(resolveSymlinks())
.pipe(resolveSymlinks(options))
.pipe(through.obj(createFile));
if (options.since) {
if (options.since != null) {
outputStream = outputStream

@@ -56,23 +54,14 @@ .pipe(filterSince(options.since));

if (options.passthrough) {
if (options.passthrough === true) {
inputPass = through.obj();
outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass));
}
if (options.sourcemaps === true) {
outputStream = outputStream
.pipe(sourcemaps.init({loadMaps: true}));
}
globStream.on('error', outputStream.emit.bind(outputStream, 'error'));
return outputStream;
}
function isValidGlob(glob) {
if (typeof glob === 'string') {
return true;
}
if (!Array.isArray(glob)) {
return false;
}
if (glob.length !== 0) {
return glob.every(isValidGlob);
}
return true;
}
module.exports = src;

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

function resolveSymlinks() {
return through2.obj(resolveFile);
}
function resolveSymlinks(options) {
// a stat property is exposed on file objects as a (wanted) side effect
function resolveFile(globFile, enc, cb) {
fs.lstat(globFile.path, function (err, stat) {
if (err) {
return cb(err);
}
globFile.stat = stat;
if (!stat.isSymbolicLink()) {
return cb(null, globFile);
}
fs.realpath(globFile.path, function (err, filePath) {
// a stat property is exposed on file objects as a (wanted) side effect
function resolveFile(globFile, enc, cb) {
fs.lstat(globFile.path, function (err, stat) {
if (err) {

@@ -30,11 +17,25 @@ return cb(err);

globFile.base = path.dirname(filePath);
globFile.path = filePath;
globFile.stat = stat;
// recurse to get real file stat
resolveFile(globFile, enc, cb);
if (!stat.isSymbolicLink() || !options.followSymlinks) {
return cb(null, globFile);
}
fs.realpath(globFile.path, function (err, filePath) {
if (err) {
return cb(err);
}
globFile.base = path.dirname(filePath);
globFile.path = filePath;
// recurse to get real file stat
resolveFile(globFile, enc, cb);
});
});
});
}
return through2.obj(resolveFile);
}
module.exports = resolveSymlinks;

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

var srcPath = file.path;
var symType = (file.isDirectory() ? 'dir' : 'file');
prepareWrite(outFolder, file, opt, function(err, writePath) {

@@ -16,3 +16,3 @@ if (err) {

}
fs.symlink(srcPath, writePath, function(err) {
fs.symlink(srcPath, writePath, symType, function(err) {
if (err && err.code !== 'EEXIST') {

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

{
"name": "vinyl-fs",
"description": "Vinyl adapter for the file system",
"version": "1.0.0",
"version": "2.0.0",
"homepage": "http://github.com/wearefractal/vinyl-fs",

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

"duplexify": "^3.2.0",
"glob-stream": "^4.0.1",
"glob-watcher": "^0.0.8",
"graceful-fs": "^3.0.0",
"merge-stream": "^0.1.7",
"glob-stream": "^5.0.0",
"graceful-fs": "^4.0.0",
"gulp-sourcemaps": "^1.5.2",
"is-valid-glob": "^0.3.0",
"merge-stream": "^1.0.0",
"mkdirp": "^0.5.0",
"object-assign": "^2.0.0",
"strip-bom": "^1.0.0",
"through2": "^0.6.1",
"vinyl": "^0.4.0"
"object-assign": "^4.0.0",
"strip-bom": "^2.0.0",
"strip-bom-stream": "^1.0.0",
"through2": "^2.0.0",
"through2-filter": "^2.0.0",
"vinyl": "^1.0.0"
},

@@ -32,5 +35,5 @@ "devDependencies": {

"mocha": "^2.0.0",
"mocha-lcov-reporter": "^0.0.2",
"mocha-lcov-reporter": "^1.0.0",
"rimraf": "^2.2.5",
"should": "^5.0.0",
"should": "^7.0.0",
"sinon": "^1.10.3"

@@ -43,10 +46,5 @@ },

"engines": {
"node": ">= 0.10"
"node": ">=0.10"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/wearefractal/vinyl-fs/raw/master/LICENSE"
}
]
"license": "MIT"
}
# 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]
## Information
<table>

@@ -36,5 +34,3 @@ <tr>

## API
### src(globs[, opt])
- Takes a glob string or an array of glob strings as the first argument.

@@ -54,51 +50,79 @@ - Globs are executed in order, so negations should follow positive globs. For example:

- Possible options for the second argument:
- cwd - Specify the working directory the folder is relative to. Default is `process.cwd()`
- base - Specify the folder relative to the cwd. Default is where the glob begins. This is used to determine the file names when saving in `.dest()`
- cwd - Specify the working directory the folder is relative to.
- Default is `process.cwd()`.
- base - Specify the folder relative to the cwd. This is used to determine the file names when saving in `.dest()`.
- Default is where the glob begins if any.
- Default is `process.cwd()` if there is no glob.
- buffer - `true` or `false` if you want to buffer the file.
- Default value is `true`
- `false` will make file.contents a paused Stream
- Default value is `true`.
- `false` will make `file.contents` a paused Stream.
- read - `true` or `false` if you want the file to be read or not. Useful for stuff like `rm`ing files.
- Default value is `true`
- `false` will disable writing the file to disk via `.dest()`
- Default value is `true`.
- `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 stream by default, or a Duplex stream if the `passthrough` option is set to `true`.
- This stream emits matching [vinyl] File objects
- Default is `false`.
### watch(globs[, opt, cb])
- sourcemaps - `true` or `false` if you want files to have sourcemaps enabled.
- Default is `false`.
This is just [glob-watcher]
- followSymlinks - `true` if you want to recursively resolve symlinks to their targets; set to `false` to preserve them as symlinks.
- Default is `true`.
- `false` will make `file.symlink` equal the original symlink's target path.
- Takes a glob string or an array of glob strings as the first argument.
- Possible options for the second argument:
- Any options are passed to [gaze]
- Returns an EventEmitter
- 'changed' event is emitted on each file change
- Optionally calls the callback on each change event
- Any glob-related options are documented in [glob-stream] and [node-glob].
- 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.
_Note:_ UTF-8 BOM will be stripped from all UTF-8 files read with `.src`.
### dest(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()`
- 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
- cwd - Specify the working directory the folder is relative to.
- Default is `process.cwd()`.
- base - Specify the folder relative to the cwd. This is used to determine the file names when saving in `.dest()`.
- Default is the `cwd` resolves to the folder path.
- Can also be a function that takes in a file and returns a folder path.
- mode - Specify the mode the files should be created with.
- Default is the mode of the input file (file.stat.mode) if any.
- Default is 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.
- If the file has a `symlink` attribute specifying a target path, then a symlink will be created.
- The file will be modified after being written to this stream:
- `cwd`, `base`, and `path` will be overwritten to match the folder
- `stat.mode` will be overwritten if you used a mode parameter
- `contents` will have it's position reset to the beginning if it is a stream
- `cwd`, `base`, and `path` will be overwritten to match the folder.
- `stat.mode` will be overwritten if you used a mode parameter.
- `contents` will have it's position reset to the beginning if it is a stream.
### 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.
- cwd - Specify the working directory the folder is relative to.
- Default is `process.cwd()`.
- base - Specify the folder relative to the cwd. This is used to determine the file names when saving in `.dest()`.
- Default is the `cwd` resolves to the folder path.
- Can also be a function that takes in a file and returns a folder path.
- dirMode - Specify the mode the directory should be created with.
- Default is the process mode.
- Returns a Readable/Writable stream.

@@ -108,3 +132,3 @@ - On write the stream will create a symbolic link (i.e. symlink) on disk at the folder/cwd specified.

- The file will be modified after being written to this stream:
- `cwd`, `base`, and `path` will be overwritten to match the folder
- `cwd`, `base`, and `path` will be overwritten to match the folder.

@@ -116,3 +140,2 @@ [glob-stream]: https://github.com/wearefractal/glob-stream

[vinyl]: https://github.com/wearefractal/vinyl
[npm-url]: https://www.npmjs.com/package/vinyl-fs

@@ -119,0 +142,0 @@ [npm-image]: https://badge.fury.io/js/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