Skip to content

Commit

Permalink
Fix: Avoid file.isDirectory in useJunctions default (fixes #247) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Nov 28, 2017
1 parent 658af12 commit 9be4bec
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
5 changes: 1 addition & 4 deletions lib/dest/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ var config = {
// Symlink options
useJunctions: {
type: 'boolean',
default: function(file) {
var isDirectory = file.isDirectory();
return (isWindows && isDirectory);
},
default: isWindows,
},
relative: {
type: 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion lib/dest/write-contents/write-symbolic-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function writeSymbolicLink(file, optResolver, onWritten) {
var isRelative = optResolver.resolve('relative', file);

// This is done inside prepareWrite to use the adjusted file.base property
if (isRelative && !useJunctions) {
if (isRelative && symType !== 'junction') {
srcPath = path.relative(file.base, srcPath);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/symlink/link-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function linkStream(optResolver) {
var isRelative = optResolver.resolve('relative', file);

// This is done inside prepareWrite to use the adjusted file.base property
if (isRelative && !useJunctions) {
if (isRelative && symType !== 'junction') {
srcPath = path.relative(file.base, srcPath);
}

Expand Down
5 changes: 1 addition & 4 deletions lib/symlink/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ var isWindows = (os.platform() === 'win32');
var config = {
useJunctions: {
type: 'boolean',
default: function(file) {
var isDirectory = file.isDirectory();
return (isWindows && isDirectory);
},
default: isWindows,
},
relative: {
type: 'boolean',
Expand Down
30 changes: 30 additions & 0 deletions test/dest-symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,36 @@ describe('.dest() with symlinks', function() {
], done);
});

it('(windows) supports relative option when link is not for a directory', function(done) {
if (!isWindows) {
this.skip();
return;
}

var file = new File({
base: inputBase,
path: inputPath,
contents: null,
});

// `src()` adds this side-effect with `resolveSymlinks` option set to false
file.symlink = inputPath;

function assert(files) {
var outputLink = fs.readlinkSync(outputPath);

expect(files.length).toEqual(1);
expect(outputLink).toEqual(path.normalize('../fixtures/test.txt'));
}

pipe([
from.obj([file]),
// The useJunctions option is ignored when file is not a directory
vfs.dest(outputBase, { useJunctions: true, relative: true }),
concat(assert),
], done);
});

it('(windows) can create relative links for directories when junctions are disabled', function(done) {
if (!isWindows) {
this.skip();
Expand Down
30 changes: 30 additions & 0 deletions test/symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,36 @@ describe('symlink stream', function() {
], done);
});

it('(windows) supports relative option when link is not for a directory', function(done) {
if (!isWindows) {
this.skip();
return;
}

var file = new File({
base: inputBase,
path: inputPath,
contents: null,
});

function assert(files) {
var outputLink = fs.readlinkSync(outputPath);

expect(files.length).toEqual(1);
expect(files).toInclude(file);
expect(files[0].base).toEqual(outputBase, 'base should have changed');
expect(files[0].path).toEqual(outputPath, 'path should have changed');
expect(outputLink).toEqual(path.normalize('../fixtures/test.txt'));
}

pipe([
from.obj([file]),
// The useJunctions option is ignored when file is not a directory
vfs.symlink(outputBase, { useJunctions: true, relative: true }),
concat(assert),
], done);
});

it('(windows) can create relative links for directories when junctions are disabled', function(done) {
if (!isWindows) {
this.skip();
Expand Down

0 comments on commit 9be4bec

Please sign in to comment.