Skip to content

Commit a39aeb8

Browse files
erikkempermanphated
authored andcommitted
Update: Attach symlink property when passed through dest or symlink (fixes #249)
1 parent 82de270 commit a39aeb8

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ var path = require('path');
55
var fo = require('../../file-operations');
66

77
function writeSymbolicLink(file, optResolver, onWritten) {
8-
var srcPath = file.symlink;
9-
108
var isDirectory = file.isDirectory();
119

1210
// This option provides a way to create a Junction instead of a
@@ -26,9 +24,9 @@ function writeSymbolicLink(file, optResolver, onWritten) {
2624
var symType = isDirectory ? symDirType : 'file';
2725
var isRelative = optResolver.resolve('relative', file);
2826

29-
// This is done inside prepareWrite to use the adjusted file.base property
27+
// This is done after prepare() to use the adjusted file.base property
3028
if (isRelative && symType !== 'junction') {
31-
srcPath = path.relative(file.base, srcPath);
29+
file.symlink = path.relative(file.base, file.symlink);
3230
}
3331

3432
var flag = optResolver.resolve('flag', file);
@@ -38,7 +36,7 @@ function writeSymbolicLink(file, optResolver, onWritten) {
3836
type: symType,
3937
};
4038

41-
fo.symlink(srcPath, file.path, opts, onWritten);
39+
fo.symlink(file.symlink, file.path, opts, onWritten);
4240
}
4341

4442
module.exports = writeSymbolicLink;

lib/symlink/link-file.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ var fo = require('../file-operations');
99
function linkStream(optResolver) {
1010

1111
function linkFile(file, enc, callback) {
12-
// Fetch the path as it was before prepare.dest()
13-
var srcPath = file.history[file.history.length - 2];
14-
1512
var isDirectory = file.isDirectory();
1613

1714
// This option provides a way to create a Junction instead of a
@@ -31,9 +28,9 @@ function linkStream(optResolver) {
3128
var symType = isDirectory ? symDirType : 'file';
3229
var isRelative = optResolver.resolve('relative', file);
3330

34-
// This is done inside prepareWrite to use the adjusted file.base property
31+
// This is done after prepare() to use the adjusted file.base property
3532
if (isRelative && symType !== 'junction') {
36-
srcPath = path.relative(file.base, srcPath);
33+
file.symlink = path.relative(file.base, file.symlink);
3734
}
3835

3936
var flag = optResolver.resolve('flag', file);
@@ -43,7 +40,7 @@ function linkStream(optResolver) {
4340
type: symType,
4441
};
4542

46-
fo.symlink(srcPath, file.path, opts, onSymlink);
43+
fo.symlink(file.symlink, file.path, opts, onSymlink);
4744

4845
function onSymlink(symlinkErr) {
4946
if (symlinkErr) {

lib/symlink/prepare.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function prepareSymlink(folderResolver, optResolver) {
2828
file.stat.mode = mode;
2929
file.cwd = cwd;
3030
file.base = basePath;
31+
file.symlink = file.path;
3132
file.path = writePath;
3233

3334
cb(null, file);

test/symlink.js

+12
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ describe('symlink stream', function() {
110110
expect(files).toInclude(file);
111111
expect(files[0].base).toEqual(outputBase, 'base should have changed');
112112
expect(files[0].path).toEqual(outputPath, 'path should have changed');
113+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
113114
expect(outputLink).toEqual(inputPath);
114115
}
115116

@@ -142,6 +143,7 @@ describe('symlink stream', function() {
142143
expect(files).toInclude(file);
143144
expect(files[0].base).toEqual(outputBase, 'base should have changed');
144145
expect(files[0].path).toEqual(outputPath, 'path should have changed');
146+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
145147
expect(outputLink).toEqual(inputPath);
146148
}
147149

@@ -167,6 +169,7 @@ describe('symlink stream', function() {
167169
expect(files).toInclude(file);
168170
expect(files[0].base).toEqual(outputBase, 'base should have changed');
169171
expect(files[0].path).toEqual(outputPath, 'path should have changed');
172+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
170173
expect(outputLink).toEqual(inputPath);
171174
}
172175

@@ -191,6 +194,7 @@ describe('symlink stream', function() {
191194
expect(files).toInclude(file);
192195
expect(files[0].base).toEqual(outputBase, 'base should have changed');
193196
expect(files[0].path).toEqual(outputPath, 'path should have changed');
197+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
194198
expect(outputLink).toEqual(path.normalize('../fixtures/test.txt'));
195199
}
196200

@@ -215,6 +219,7 @@ describe('symlink stream', function() {
215219
expect(files).toInclude(file);
216220
expect(files[0].base).toEqual(outputBase, 'base should have changed');
217221
expect(files[0].path).toEqual(outputPath, 'path should have changed');
222+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
218223
expect(outputLink).toEqual(inputPath);
219224
}
220225

@@ -249,6 +254,7 @@ describe('symlink stream', function() {
249254
expect(files).toInclude(file);
250255
expect(files[0].base).toEqual(outputBase, 'base should have changed');
251256
expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
257+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
252258
expect(outputLink).toEqual(inputDirpath);
253259
expect(stats.isDirectory()).toEqual(true);
254260
expect(lstats.isDirectory()).toEqual(false);
@@ -286,6 +292,7 @@ describe('symlink stream', function() {
286292
expect(files[0].base).toEqual(outputBase, 'base should have changed');
287293
expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
288294
// When creating a junction, it seems Windows appends a separator
295+
expect(files[0].symlink + path.sep).toEqual(outputLink, 'symlink should be set');
289296
expect(outputLink).toEqual(inputDirpath + path.sep);
290297
expect(stats.isDirectory()).toEqual(true);
291298
expect(lstats.isDirectory()).toEqual(false);
@@ -322,6 +329,7 @@ describe('symlink stream', function() {
322329
expect(files).toInclude(file);
323330
expect(files[0].base).toEqual(outputBase, 'base should have changed');
324331
expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
332+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
325333
expect(outputLink).toEqual(inputDirpath);
326334
expect(stats.isDirectory()).toEqual(true);
327335
expect(lstats.isDirectory()).toEqual(false);
@@ -364,6 +372,7 @@ describe('symlink stream', function() {
364372
expect(files).toInclude(file);
365373
expect(files[0].base).toEqual(outputBase, 'base should have changed');
366374
expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
375+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
367376
expect(outputLink).toEqual(inputDirpath);
368377
expect(stats.isDirectory()).toEqual(true);
369378
expect(lstats.isDirectory()).toEqual(false);
@@ -400,6 +409,7 @@ describe('symlink stream', function() {
400409
expect(files).toInclude(file);
401410
expect(files[0].base).toEqual(outputBase, 'base should have changed');
402411
expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
412+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
403413
expect(outputLink).toEqual(path.normalize('../fixtures/foo'));
404414
expect(stats.isDirectory()).toEqual(true);
405415
expect(lstats.isDirectory()).toEqual(false);
@@ -437,6 +447,7 @@ describe('symlink stream', function() {
437447
expect(files[0].base).toEqual(outputBase, 'base should have changed');
438448
expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
439449
// When creating a junction, it seems Windows appends a separator
450+
expect(files[0].symlink + path.sep).toEqual(outputLink, 'symlink should be set');
440451
expect(outputLink).toEqual(inputDirpath + path.sep);
441452
expect(stats.isDirectory()).toEqual(true);
442453
expect(lstats.isDirectory()).toEqual(false);
@@ -503,6 +514,7 @@ describe('symlink stream', function() {
503514
expect(files).toInclude(file);
504515
expect(files[0].base).toEqual(outputBase, 'base should have changed');
505516
expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
517+
expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
506518
expect(outputLink).toEqual(path.normalize('../fixtures/foo'));
507519
expect(stats.isDirectory()).toEqual(true);
508520
expect(lstats.isDirectory()).toEqual(false);

0 commit comments

Comments
 (0)