From 20fc47c4e953fb37f8224b2e9cd40281ae286596 Mon Sep 17 00:00:00 2001 From: Erik Kemperman Date: Mon, 24 Apr 2017 17:27:13 +0200 Subject: [PATCH] Breaking: Rename option `followSymlinks` to `resolveSymlinks` (closes #205) --- README.md | 2 +- lib/src/read-contents/index.js | 2 +- lib/src/wrap-with-vinyl-file.js | 8 +++++++- test/dest.js | 2 +- test/src-symlinks.js | 12 ++++++------ 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 72aa5c37..0f618658 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Type: `Boolean` Default: `false` -##### `options.followSymlinks` +##### `options.resolveSymlinks` 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. diff --git a/lib/src/read-contents/index.js b/lib/src/read-contents/index.js index e52c57a3..07a29ec4 100644 --- a/lib/src/read-contents/index.js +++ b/lib/src/read-contents/index.js @@ -14,7 +14,7 @@ function readContents(opt) { return readDir(file, opt, onRead); } - // Process symbolic links included with `followSymlinks` option + // Process symbolic links included with `resolveSymlinks` option if (file.stat && file.stat.isSymbolicLink()) { return readSymbolicLink(file, opt, onRead); } diff --git a/lib/src/wrap-with-vinyl-file.js b/lib/src/wrap-with-vinyl-file.js index 313266e4..66e931e2 100644 --- a/lib/src/wrap-with-vinyl-file.js +++ b/lib/src/wrap-with-vinyl-file.js @@ -4,8 +4,14 @@ var through2 = require('through2'); var fs = require('graceful-fs'); var File = require('vinyl'); +var koalas = require('koalas'); +var valueOrFunction = require('value-or-function'); +var boolean = valueOrFunction.boolean; + function wrapWithVinylFile(options) { + var resolveSymlinks = koalas(boolean(options.resolveSymlinks), true); + // A stat property is exposed on file objects as a (wanted) side effect function resolveFile(globFile, enc, callback) { fs.lstat(globFile.path, onStat); @@ -17,7 +23,7 @@ function wrapWithVinylFile(options) { globFile.stat = stat; - if (!stat.isSymbolicLink() || !options.followSymlinks) { + if (!stat.isSymbolicLink() || !resolveSymlinks) { var vinylFile = new File(globFile); if (globFile.originalSymlinkPath) { // If we reach here, it means there is at least one diff --git a/test/dest.js b/test/dest.js index fc03aef1..e282106d 100644 --- a/test/dest.js +++ b/test/dest.js @@ -582,7 +582,7 @@ describe('.dest()', function() { contents: null, }); - // `src()` adds this side-effect with `followSymlinks` option set to false + // `src()` adds this side-effect with `resolveSymlinks` option set to false file.symlink = inputRelativeSymlinkPath; function assert(files) { diff --git a/test/src-symlinks.js b/test/src-symlinks.js index 01b005a6..3ff6895e 100644 --- a/test/src-symlinks.js +++ b/test/src-symlinks.js @@ -39,7 +39,7 @@ describe('.src() with symlinks', function() { done(); }); - it('follows symlinks correctly', function(done) { + it('resolves symlinks correctly', function(done) { function assert(files) { expect(files.length).toEqual(1); // The path should be the symlink itself @@ -57,7 +57,7 @@ describe('.src() with symlinks', function() { ], done); }); - it('follows directory symlinks correctly', function(done) { + it('resolves directory symlinks correctly', function(done) { function assert(files) { expect(files.length).toEqual(1); // The path should be the symlink itself @@ -75,7 +75,7 @@ describe('.src() with symlinks', function() { ], done); }); - it('preserves file symlinks with followSymlinks option set to false', function(done) { + it('preserves file symlinks with resolveSymlinks option set to false', function(done) { var expectedRelativeSymlinkPath = fs.readlinkSync(symlinkPath); function assert(files) { @@ -85,12 +85,12 @@ describe('.src() with symlinks', function() { } pipe([ - vfs.src(symlinkPath, { followSymlinks: false }), + vfs.src(symlinkPath, { resolveSymlinks: false }), concat(assert), ], done); }); - it('preserves directory symlinks with followSymlinks option set to false', function(done) { + it('preserves directory symlinks with resolveSymlinks option set to false', function(done) { var expectedRelativeSymlinkPath = fs.readlinkSync(symlinkDirpath); function assert(files) { @@ -100,7 +100,7 @@ describe('.src() with symlinks', function() { } pipe([ - vfs.src(symlinkDirpath, { followSymlinks: false }), + vfs.src(symlinkDirpath, { resolveSymlinks: false }), concat(assert), ], done); });