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 2.4.4 to 3.0.0

lib/constants.js

6

CHANGELOG.md
## Change Log
### v2.4.3 (2016/04/01 19:53 +00:00)
- [3033555](https://github.com/gulpjs/vinyl-fs/commit/3033555d4b094e115b274b9c611be55104538118) 2.4.3 (@phated)
- [aa18c60](https://github.com/gulpjs/vinyl-fs/commit/aa18c60a12a7866cd3abd8fec0c63f9bf7b8a9ce) move originalSymlinkPath assignment into realpath callback, fix comment linting (@phated)
- [6a97cdf](https://github.com/gulpjs/vinyl-fs/commit/6a97cdf57d4cdc687402ef4e9d1d1d45c88478d2) Fixes #132 The symlink following logic in src() was incorrect resulting in wrong file.base being generated. (@xunnanxu)
- [4a08c4e](https://github.com/gulpjs/vinyl-fs/commit/4a08c4e991d3b209b6f63140b7a7dde1d4970607) update changelog (@phated)
### v2.4.2 (2016/03/03 19:59 +00:00)

@@ -4,0 +10,0 @@ - [5edb75a](https://github.com/gulpjs/vinyl-fs/commit/5edb75a10935fdc89e29d5e2413694aca77a3e85) 2.4.2 (@phated)

69

lib/dest/index.js
'use strict';
var through2 = require('through2');
var sourcemaps = require('gulp-sourcemaps');
var duplexify = require('duplexify');
var sink = require('../sink');
var prepareWrite = require('../prepareWrite');
var writeContents = require('./writeContents');
var lead = require('lead');
var pumpify = require('pumpify');
var mkdirpStream = require('fs-mkdirp-stream');
var createResolver = require('resolve-options');
var config = require('./options');
var prepare = require('./prepare');
var sourcemap = require('./sourcemap');
var writeContents = require('./write-contents');
var folderConfig = {
outFolder: {
type: 'string',
},
};
function dest(outFolder, opt) {
if (!opt) {
opt = {};
if (!outFolder) {
throw new Error('Invalid dest() folder argument.' +
' Please specify a non-empty string or a function.');
}
function saveFile(file, enc, cb) {
prepareWrite(outFolder, file, opt, function(err, writePath) {
if (err) {
return cb(err);
}
writeContents(writePath, file, cb);
});
}
var optResolver = createResolver(config, opt);
var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
var saveStream = through2.obj(opt, saveFile);
if (!opt.sourcemaps) {
// Sink the save stream to start flowing
// Do this on nextTick, it will flow at slowest speed of piped streams
process.nextTick(sink(saveStream));
function dirpath(file, callback) {
var dirMode = optResolver.resolve('dirMode', file);
return saveStream;
callback(null, file.dirname, dirMode);
}
var sourcemapOpt = opt.sourcemaps;
if (typeof sourcemapOpt === 'boolean') {
sourcemapOpt = {};
}
if (typeof sourcemapOpt === 'string') {
sourcemapOpt = {
path: sourcemapOpt,
};
}
var saveStream = pumpify.obj(
prepare(folderResolver, optResolver),
sourcemap(optResolver),
mkdirpStream.obj(dirpath),
writeContents(optResolver)
);
var mapStream = sourcemaps.write(sourcemapOpt.path, sourcemapOpt);
var outputStream = duplexify.obj(mapStream, saveStream);
mapStream.pipe(saveStream);
// Sink the output stream to start flowing
// Do this on nextTick, it will flow at slowest speed of piped streams
process.nextTick(sink(outputStream));
return outputStream;
return lead(saveStream);
}
module.exports = dest;
'use strict';
var assign = require('object-assign');
var through2 = require('through2');
var gs = require('glob-stream');
var duplexify = require('duplexify');
var merge = require('merge-stream');
var sourcemaps = require('gulp-sourcemaps');
var filterSince = require('../filterSince');
var pumpify = require('pumpify');
var toThrough = require('to-through');
var isValidGlob = require('is-valid-glob');
var createResolver = require('resolve-options');
var getContents = require('./getContents');
var wrapWithVinylFile = require('./wrapWithVinylFile');
var config = require('./options');
var prepare = require('./prepare');
var wrapVinyl = require('./wrap-vinyl');
var sourcemap = require('./sourcemap');
var readContents = require('./read-contents');
var resolveSymlinks = require('./resolve-symlinks');
function src(glob, opt) {
var options = assign({
read: true,
buffer: true,
stripBOM: true,
sourcemaps: false,
passthrough: false,
followSymlinks: true,
}, opt);
var optResolver = createResolver(config, opt);
// Don't pass `read` option on to through2
var read = options.read !== false;
options.read = undefined;
var inputPass;
if (!isValidGlob(glob)) {

@@ -35,29 +23,17 @@ throw new Error('Invalid glob argument: ' + glob);

var globStream = gs.create(glob, options);
var streams = [
gs(glob, opt),
wrapVinyl(optResolver),
resolveSymlinks(optResolver),
prepare(optResolver),
readContents(optResolver),
sourcemap(optResolver),
];
var outputStream = globStream
.pipe(wrapWithVinylFile(options));
var outputStream = pumpify.obj(streams);
if (options.since != null) {
outputStream = outputStream
.pipe(filterSince(options.since));
}
return toThrough(outputStream);
}
if (read) {
outputStream = outputStream
.pipe(getContents(options));
}
if (options.passthrough === true) {
inputPass = through2.obj(options);
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;
}
module.exports = src;
'use strict';
var through2 = require('through2');
var fs = require('graceful-fs');
var prepareWrite = require('../prepareWrite');
var pumpify = require('pumpify');
var lead = require('lead');
var mkdirpStream = require('fs-mkdirp-stream');
var createResolver = require('resolve-options');
var config = require('./options');
var prepare = require('./prepare');
var linkFile = require('./link-file');
var folderConfig = {
outFolder: {
type: 'string',
},
};
function symlink(outFolder, opt) {
function linkFile(file, enc, cb) {
var srcPath = file.path;
var symType = (file.isDirectory() ? 'dir' : 'file');
prepareWrite(outFolder, file, opt, function(err, writePath) {
if (err) {
return cb(err);
}
fs.symlink(srcPath, writePath, symType, function(err) {
if (err && err.code !== 'EEXIST') {
return cb(err);
}
cb(null, file);
});
});
if (!outFolder) {
throw new Error('Invalid symlink() folder argument.' +
' Please specify a non-empty string or a function.');
}
var stream = through2.obj(opt, linkFile);
// TODO: option for either backpressure or lossy
stream.resume();
return stream;
var optResolver = createResolver(config, opt);
var folderResolver = createResolver(folderConfig, { outFolder: outFolder });
function dirpath(file, callback) {
var dirMode = optResolver.resolve('dirMode', file);
callback(null, file.dirname, dirMode);
}
var stream = pumpify.obj(
prepare(folderResolver, optResolver),
mkdirpStream.obj(dirpath),
linkFile(optResolver)
);
// Sink the stream to start flowing
return lead(stream);
}
module.exports = symlink;
{
"name": "vinyl-fs",
"description": "Vinyl adapter for the file system",
"version": "2.4.4",
"homepage": "http://github.com/wearefractal/vinyl-fs",
"repository": "git://github.com/wearefractal/vinyl-fs.git",
"author": "Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
"main": "./index.js",
"version": "3.0.0",
"description": "Vinyl adapter for the file system.",
"author": "Gulp Team <team@gulpjs.com> (http://gulpjs.com/)",
"contributors": [
"Eric Schoffstall <yo@contra.io>",
"Blaine Bublitz <blaine.bublitz@gmail.com>"
],
"repository": "gulpjs/vinyl-fs",
"license": "MIT",
"engines": {
"node": ">= 0.10"
},
"main": "index.js",
"files": [
"LICENSE",
"index.js",
"lib"
],
"scripts": {
"lint": "eslint . && jscs index.js lib/ test/",
"pretest": "npm run lint",
"test": "mocha --async-only",
"cover": "istanbul cover _mocha --report lcovonly",
"coveralls": "npm run cover && istanbul-coveralls"
},
"dependencies": {
"duplexify": "^3.2.0",
"glob-stream": "^5.3.2",
"flush-write-stream": "^1.0.0",
"fs-mkdirp-stream": "^1.0.0",
"glob-stream": "^6.1.0",
"graceful-fs": "^4.0.0",
"gulp-sourcemaps": "1.6.0",
"is-valid-glob": "^0.3.0",
"is-valid-glob": "^1.0.0",
"lazystream": "^1.0.0",
"lodash.isequal": "^4.0.0",
"merge-stream": "^1.0.0",
"mkdirp": "^0.5.0",
"object-assign": "^4.0.0",
"readable-stream": "^2.0.4",
"strip-bom": "^2.0.0",
"strip-bom-stream": "^1.0.0",
"lead": "^1.0.0",
"object.assign": "^4.0.4",
"pumpify": "^1.3.5",
"remove-bom-buffer": "^3.0.0",
"remove-bom-stream": "^1.2.0",
"resolve-options": "^1.1.0",
"through2": "^2.0.0",
"through2-filter": "^2.0.0",
"vali-date": "^1.0.0",
"vinyl": "^1.0.0"
"to-through": "^2.0.0",
"value-or-function": "^3.0.0",
"vinyl": "^2.0.0",
"vinyl-sourcemap": "^1.1.0"
},
"devDependencies": {
"buffer-equal": "^0.0.1",
"default-resolution": "^1.0.1",
"del": "^2.2.0",
"eslint": "^1.10.3",
"eslint-config-gulp": "^2.0.0",
"expect": "^1.14.0",
"github-changes": "^1.0.1",
"istanbul": "^0.3.0",
"istanbul-coveralls": "^1.0.1",
"expect": "^1.19.0",
"istanbul": "^0.4.3",
"istanbul-coveralls": "^1.0.3",
"jscs": "^2.4.0",
"jscs-preset-gulp": "^1.0.0",
"mocha": "^2.0.0",
"mocha-lcov-reporter": "^1.0.0",
"rimraf": "^2.2.5",
"should": "^7.0.0",
"sinon": "^1.10.3"
"mississippi": "^1.2.0",
"mocha": "^3.5.0",
"rimraf": "^2.6.1"
},
"scripts": {
"lint": "eslint . && jscs index.js lib/ test/",
"test": "npm run lint && mocha",
"cover": "istanbul cover _mocha",
"coveralls": "npm run cover && istanbul-coveralls",
"changelog": "github-changes -o gulpjs -r vinyl-fs -b master -f ./CHANGELOG.md --order-semver --use-commit-body"
},
"engines": {
"node": ">=0.10"
},
"license": "MIT"
"keywords": [
"gulp",
"vinyl-adapter",
"vinyl",
"file",
"file system",
"fs",
"streams"
]
}

@@ -19,3 +19,3 @@ <p align="center">

While Vinyl provides a clean way to describe a file, we now need a way to access these files. Each file source needs what I call a "Vinyl adapter". A Vinyl adapter simply exposes a `src(globs)` and a `dest(folder)` method. Each return a stream. The `src` stream produces Vinyl objects, and the `dest` stream consumes Vinyl objects. Vinyl adapters can expose extra methods that might be specific to their input/output medium, such as the `symlink` method `vinyl-fs` provides.
While Vinyl provides a clean way to describe a file, we now need a way to access these files. Each file source needs what we call a "Vinyl adapter". A Vinyl adapter simply exposes a `src(globs)` and a `dest(folder)` method. Each return a stream. The `src` stream produces Vinyl objects, and the `dest` stream consumes Vinyl objects. Vinyl adapters can expose extra methods that might be specific to their input/output medium, such as the `symlink` method `vinyl-fs` provides.

@@ -45,3 +45,3 @@ ## Usage

__Note: UTF-8 BOM will be stripped from all UTF-8 files read with `.src` unless disabled in the options.__
__Note: UTF-8 BOM will be removed from all UTF-8 files read with `.src` unless disabled in the options.__

@@ -55,9 +55,9 @@ #### Globs

```js
fs.src(['!b*.js', '*.js'])
fs.src(['!b*', '*'])
```
would not exclude any files, but the following would:
would not exclude any files, but the following would exclude all files starting with "b":
```js
fs.src(['*.js', '!b*.js'])
fs.src(['*', '!b*'])
```

@@ -67,18 +67,5 @@

##### `options.cwd`
- Values passed to the options must be of the expected type, otherwise they will be ignored.
- All options can be passed a function instead of a value. The function will be called with the [vinyl] `File` object as its only argument and must return a value of the expected type for that option.
The working directory the folder is relative to.
Type: `String`
Default: `process.cwd()`
##### `options.base`
The folder relative to the cwd. This is used to determine the file names when saving in `.dest()`.
Type: `String`
Default: The part of the path before the glob (if any) begins. For example, `path/to/**/*.js` would resolve to `path/to`. If there is no glob (i.e. a file path with no pattern), then the dirname of the path is used. For example, `path/to/some/file.js` would resolve to `path/to/some`.
##### `options.buffer`

@@ -94,3 +81,3 @@

Whether or not you want the file to be read at all. Useful for stuff like removing files. Setting to `false` will make `file.contents` `null` and will disable writing the file to disk via `.dest()`.
Whether or not you want the file to be read at all. Useful for stuff like removing files. Setting to `false` will make `file.contents = null` and will disable writing the file to disk via `.dest()`.

@@ -109,5 +96,5 @@ Type: `Boolean`

##### `options.stripBOM`
##### `options.removeBOM`
Causes the BOM to be stripped on UTF-8 encoded files. Set to `false` if you need the BOM for some reason.
Causes the BOM to be removed on UTF-8 encoded files. Set to `false` if you need the BOM for some reason.

@@ -118,5 +105,5 @@ Type: `Boolean`

##### `options.passthrough`
##### `options.sourcemaps`
Allows `.src` to be used in the middle of a pipeline (using a duplex stream) which passes through all objects received and adds all files globbed to the stream.
Enables sourcemap support on files passed through the stream. Will load inline sourcemaps and resolve sourcemap links from files.

@@ -127,22 +114,23 @@ Type: `Boolean`

##### `options.sourcemaps`
##### `options.resolveSymlinks`
Enables sourcemap support on files passed through the stream. Will load inline sourcemaps and resolve sourcemap links from files. Uses [gulp-sourcemaps] under the hood.
Whether or not to recursively resolve symlinks to their targets. Set to `false` to preserve them as symlinks and make `file.symlink` equal the original symlink's target path.
Type: `Boolean`
Default: `false`
Default: `true`
##### `options.followSymlinks` - `true` if you want
##### `options.dot`
Whether or not to recursively resolve symlinks to their targets. Setting to `false` to preserve them as symlinks and make `file.symlink` equal the original symlink's target path.
Whether or not you want globs to match on dot files (e.g. `.gitignore`).
__Note: This option is not resolved from a function because it is passed verbatim to node-glob.__
Type: `Boolean`
Default: `true`
Default: `false`
##### other
Any glob-related options are documented in [glob-stream] and [node-glob].
Any through2-related options are documented in [through2].
Any glob-related options are documented in [glob-stream] and [node-glob] and are forwarded verbatim.

@@ -159,2 +147,4 @@ ### `dest(folder[, options])`

__Note: The `fs.futimes()` method internally converts `stat.mtime` and `stat.atime` timestamps to seconds; this division by `1000` may cause some loss of precision in 32-bit Node.js.__
If the file has a `symlink` attribute specifying a target path, then a symlink will be created.

@@ -169,2 +159,5 @@

- Values passed to the options must be of the expected type, otherwise they will be ignored.
- All options can be passed a function instead of a value. The function will be called with the [vinyl] `File` object as its only argument and must return a value of the expected type for that option.
##### `options.cwd`

@@ -178,13 +171,5 @@

##### `options.base`
The folder relative to the cwd. This is used to determine the file names when saving in `.dest()`. Can also be a function that takes in a file and returns a folder path.
Type: `String` or `Function`
Default: The `cwd` resolved to the folder path.
##### `options.mode`
The mode the files should be created with.
The mode the files should be created with. This option is only resolved if the [vinyl] `File` is not symbolic.

@@ -197,3 +182,3 @@ Type: `Number`

The mode the directory should be created with.
The mode directories should be created with.

@@ -206,12 +191,20 @@ Type: `Number`

Whether or not existing files with the same path should be overwritten. Can also be a function that takes in a file and returns `true` or `false`.
Whether or not existing files with the same path should be overwritten.
Type: `Boolean` or `Function`
Type: `Boolean`
Default: `true` (always overwrite existing files)
##### `options.append`
Whether or not new data should be appended after existing file contents (if any).
Type: `Boolean`
Default: `false` (always replace existing contents, if any)
##### `options.sourcemaps`
Enables sourcemap support on files passed through the stream. Will write inline soucemaps if specified as `true`.
Specifying a `string` is shorthand for the path option. Uses [gulp-sourcemaps] under the hood.
Specifying a `String` path will write external sourcemaps at the given path.

@@ -222,39 +215,49 @@ Examples:

// Write as inline comments
vfs.dest('./', {
sourcemaps: true
});
vfs.dest('./', { sourcemaps: true });
// Write as files in the same folder
vfs.dest('./', {
sourcemaps: '.'
});
// Any other options are passed through to [gulp-sourcemaps]
vfs.dest('./', {
sourcemaps: {
path: '.',
addComment: false,
includeContent: false
}
});
vfs.dest('./', { sourcemaps: '.' });
```
Type: `Boolean`, `String` or `Object`
Type: `Boolean` or `String`
Default: `undefined` (do not write sourcemaps)
##### other
##### `options.relativeSymlinks`
Any through2-related options are documented in [through2].
When creating a symlink, whether or not the created symlink should be relative. If `false`, the symlink will be absolute.
__Note: This option will be ignored if a `junction` is being created, as they must be absolute.__
Type: `Boolean`
Default: `false`
##### `options.useJunctions`
When creating a symlink, whether or not a directory symlink should be created as a `junction`.
This option is only relevant on Windows and ignored elsewhere. Please refer to the [Symbolic Links on Windows][symbolic-caveats] section below.
Type: `Boolean`
Default: `true`
### `symlink(folder[, options])`
Takes a folder path string or a function as the first argument and an options object as the second. If given a function, it will be called with each [vinyl] `File` object and must return a folder path.
Returns a stream that accepts [vinyl] `File` objects, create a symbolic link (i.e. symlink) at the folder/cwd specified, and passes them downstream so you can keep piping these around.
Returns a stream that accepts [vinyl] `File` objects, creates a symbolic link (i.e. symlink) at the folder/cwd specified, and passes them downstream so you can keep piping these around.
__Note: The file will be modified after being written to this stream.__
- `cwd`, `base`, and `path` will be overwritten to match the folder.
- `stat` will be updated to match the symlink on the filesystem.
- `contents` will be set to `null`.
- `symlink` will be added or replaced to be the original path.
__Note: On Windows, directory links are created using Junctions by default. Use the `useJunctions` option to disable this behavior.__
#### Options
- Values passed to the options must be of the expected type, otherwise they will be ignored.
- All options can be passed a function instead of a value. The function will be called with the [vinyl] `File` object as its only argument and must return a value of the expected type for that option.
##### `options.cwd`

@@ -268,24 +271,67 @@

##### `options.base`
##### `options.dirMode`
The folder relative to the cwd. This is used to determine the file names when saving in `.symlink()`. Can also be a function that takes in a file and returns a folder path.
The mode directories should be created with.
Type: `String` or `Function`
Type: `Number`
Default: The `cwd` resolved to the folder path.
Default: The process mode.
##### `options.dirMode`
##### `options.overwrite`
The mode the directory should be created with.
Whether or not existing files with the same path should be overwritten.
Type: `Number`
Type: `Boolean`
Default: The process mode.
Default: `true` (always overwrite existing files)
##### other
##### `options.relativeSymlinks`
Any through2-related options are documented in [through2].
Whether or not the created symlinks should be relative. If `false`, the symlink will be absolute.
__Note: This option will be ignored if a `junction` is being created, as they must be absolute.__
Type: `Boolean`
Default: `false`
##### `options.useJunctions`
When creating a symlink, whether or not a directory symlink should be created as a `junction`.
This option is only relevant on Windows and ignored elsewhere. Please refer to the [Symbolic Links on Windows][symbolic-caveats] section below.
Type: `Boolean`
Default: `true`
#### Symbolic Links on Windows
When creating symbolic links on Windows, we pass a `type` argument to Node's
`fs` module which specifies the kind of target we link to (one of `'file'`,
`'dir'` or `'junction'`). Specifically, this will be `'file'` when the target
is a regular file, `'junction'` if the target is a directory, or `'dir'` if
the target is a directory and the user overrides the `useJunctions` option
default.
However, if the user tries to make a "dangling" link (pointing to a non-existent
target) we won't be able to determine automatically which type we should use.
In these cases, `vinyl-fs` will behave slightly differently depending on
whether the dangling link is being created via `symlink()` or via `dest()`.
For dangling links created via `symlink()`, the incoming vinyl represents the
target and so we will look to its stats to guess the desired type. In
particular, if `isDirectory()` returns false then we'll create a `'file'` type
link, otherwise we will create a `'junction'` or a `'dir'` type link depending
on the value of the `useJunctions` option.
For dangling links created via `dest()`, the incoming vinyl represents the link -
typically read off disk via `src()` with the `resolveSymlinks` option set to
false. In this case, we won't be able to make any reasonable guess as to the
type of link and we default to using `'file'`, which may cause unexpected behavior
if you are creating a "dangling" link to a directory. It is advised to avoid this
scenario.
[symbolic-caveats]: #symbolic-links-on-windows
[glob-stream]: https://github.com/gulpjs/glob-stream
[gulp-sourcemaps]: https://github.com/floridoo/gulp-sourcemaps
[node-glob]: https://github.com/isaacs/node-glob

@@ -295,3 +341,2 @@ [gaze]: https://github.com/shama/gaze

[vinyl]: https://github.com/wearefractal/vinyl
[through2]: https://github.com/rvagg/through2

@@ -298,0 +343,0 @@ [downloads-image]: http://img.shields.io/npm/dm/vinyl-fs.svg

Sorry, the diff of this file is not supported yet

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