Skip to content

Commit 82de270

Browse files
authored
Fix: Avoid file.isDirectory in useJunctions default (fixes #247) (#252)
1 parent 17e5651 commit 82de270

File tree

6 files changed

+64
-10
lines changed

6 files changed

+64
-10
lines changed

lib/dest/options.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ var config = {
3636
// Symlink options
3737
useJunctions: {
3838
type: 'boolean',
39-
default: function(file) {
40-
var isDirectory = file.isDirectory();
41-
return (isWindows && isDirectory);
42-
},
39+
default: isWindows,
4340
},
4441
relative: {
4542
type: 'boolean',

lib/dest/write-contents/write-symbolic-link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function writeSymbolicLink(file, optResolver, onWritten) {
2727
var isRelative = optResolver.resolve('relative', file);
2828

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

lib/symlink/link-file.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function linkStream(optResolver) {
3232
var isRelative = optResolver.resolve('relative', file);
3333

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

lib/symlink/options.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ var isWindows = (os.platform() === 'win32');
77
var config = {
88
useJunctions: {
99
type: 'boolean',
10-
default: function(file) {
11-
var isDirectory = file.isDirectory();
12-
return (isWindows && isDirectory);
13-
},
10+
default: isWindows,
1411
},
1512
relative: {
1613
type: 'boolean',

test/dest-symlinks.js

+30
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,36 @@ describe('.dest() with symlinks', function() {
307307
], done);
308308
});
309309

310+
it('(windows) supports relative option when link is not for a directory', function(done) {
311+
if (!isWindows) {
312+
this.skip();
313+
return;
314+
}
315+
316+
var file = new File({
317+
base: inputBase,
318+
path: inputPath,
319+
contents: null,
320+
});
321+
322+
// `src()` adds this side-effect with `resolveSymlinks` option set to false
323+
file.symlink = inputPath;
324+
325+
function assert(files) {
326+
var outputLink = fs.readlinkSync(outputPath);
327+
328+
expect(files.length).toEqual(1);
329+
expect(outputLink).toEqual(path.normalize('../fixtures/test.txt'));
330+
}
331+
332+
pipe([
333+
from.obj([file]),
334+
// The useJunctions option is ignored when file is not a directory
335+
vfs.dest(outputBase, { useJunctions: true, relative: true }),
336+
concat(assert),
337+
], done);
338+
});
339+
310340
it('(windows) can create relative links for directories when junctions are disabled', function(done) {
311341
if (!isWindows) {
312342
this.skip();

test/symlink.js

+30
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,36 @@ describe('symlink stream', function() {
449449
], done);
450450
});
451451

452+
it('(windows) supports relative option when link is not for a directory', function(done) {
453+
if (!isWindows) {
454+
this.skip();
455+
return;
456+
}
457+
458+
var file = new File({
459+
base: inputBase,
460+
path: inputPath,
461+
contents: null,
462+
});
463+
464+
function assert(files) {
465+
var outputLink = fs.readlinkSync(outputPath);
466+
467+
expect(files.length).toEqual(1);
468+
expect(files).toInclude(file);
469+
expect(files[0].base).toEqual(outputBase, 'base should have changed');
470+
expect(files[0].path).toEqual(outputPath, 'path should have changed');
471+
expect(outputLink).toEqual(path.normalize('../fixtures/test.txt'));
472+
}
473+
474+
pipe([
475+
from.obj([file]),
476+
// The useJunctions option is ignored when file is not a directory
477+
vfs.symlink(outputBase, { useJunctions: true, relative: true }),
478+
concat(assert),
479+
], done);
480+
});
481+
452482
it('(windows) can create relative links for directories when junctions are disabled', function(done) {
453483
if (!isWindows) {
454484
this.skip();

0 commit comments

Comments
 (0)