Skip to content

Commit bbfb50c

Browse files
authored
Fix: Temporarily marshall old Vinyl objects to latest version in dest/symlink (#291)
1 parent 3b4ab64 commit bbfb50c

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

lib/dest/prepare.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ function prepareWrite(folderResolver, optResolver) {
1616
return cb(new Error('Received a non-Vinyl object in `dest()`'));
1717
}
1818

19+
// TODO: Remove this after people upgrade vinyl/transition from gulp-util
20+
if (typeof file.isSymbolic !== 'function') {
21+
file = new Vinyl(file);
22+
}
23+
1924
var outFolderPath = folderResolver.resolve('outFolder', file);
2025
if (!outFolderPath) {
2126
return cb(new Error('Invalid output folder'));

lib/symlink/prepare.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ function prepareSymlink(folderResolver, optResolver) {
1616
return cb(new Error('Received a non-Vinyl object in `symlink()`'));
1717
}
1818

19+
// TODO: Remove this after people upgrade vinyl/transition from gulp-util
20+
if (typeof file.isSymbolic !== 'function') {
21+
file = new Vinyl(file);
22+
}
23+
1924
var cwd = path.resolve(optResolver.resolve('cwd', file));
2025

2126
var outFolderPath = folderResolver.resolve('outFolder', file);

test/dest.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var applyUmask = require('./utils/apply-umask');
1616
var testStreams = require('./utils/test-streams');
1717
var always = require('./utils/always');
1818
var testConstants = require('./utils/test-constants');
19+
var breakPrototype = require('./utils/break-prototype');
1920

2021
var from = miss.from;
2122
var pipe = miss.pipe;
@@ -1018,4 +1019,48 @@ describe('.dest()', function() {
10181019
concat(assert),
10191020
], done);
10201021
});
1022+
1023+
it('does not marshall a Vinyl object with isSymbolic method', function(done) {
1024+
var file = new File({
1025+
base: outputBase,
1026+
path: outputPath,
1027+
});
1028+
1029+
function assert(files) {
1030+
expect(files.length).toEqual(1);
1031+
// Avoid comparing stats because they get reflected
1032+
delete files[0].stat;
1033+
expect(files[0]).toMatch(file);
1034+
expect(files[0]).toBe(file);
1035+
}
1036+
1037+
pipe([
1038+
from.obj([file]),
1039+
vfs.dest(outputBase),
1040+
concat(assert),
1041+
], done);
1042+
});
1043+
1044+
it('marshalls a Vinyl object without isSymbolic to a newer Vinyl', function(done) {
1045+
var file = new File({
1046+
base: outputBase,
1047+
path: outputPath,
1048+
});
1049+
1050+
breakPrototype(file);
1051+
1052+
function assert(files) {
1053+
expect(files.length).toEqual(1);
1054+
// Avoid comparing stats because they get reflected
1055+
delete files[0].stat;
1056+
expect(files[0]).toMatch(file);
1057+
expect(files[0]).toNotBe(file);
1058+
}
1059+
1060+
pipe([
1061+
from.obj([file]),
1062+
vfs.dest(outputBase),
1063+
concat(assert),
1064+
], done);
1065+
});
10211066
});

test/symlink.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var isWindows = require('./utils/is-windows');
1414
var testStreams = require('./utils/test-streams');
1515
var always = require('./utils/always');
1616
var testConstants = require('./utils/test-constants');
17+
var breakPrototype = require('./utils/break-prototype');
1718

1819
var from = miss.from;
1920
var pipe = miss.pipe;
@@ -940,4 +941,50 @@ describe('symlink stream', function() {
940941
concat(assert),
941942
], done);
942943
});
944+
945+
it('does not marshall a Vinyl object with isSymbolic method', function(done) {
946+
var file = new File({
947+
base: outputBase,
948+
path: outputPath,
949+
});
950+
951+
function assert(files) {
952+
expect(files.length).toEqual(1);
953+
// Avoid comparing stats because they get reflected
954+
delete files[0].stat;
955+
expect(files[0]).toMatch(file);
956+
expect(files[0]).toBe(file);
957+
}
958+
959+
pipe([
960+
from.obj([file]),
961+
vfs.symlink(outputBase),
962+
concat(assert),
963+
], done);
964+
});
965+
966+
it('marshalls a Vinyl object without isSymbolic to a newer Vinyl', function(done) {
967+
var file = new File({
968+
base: outputBase,
969+
path: outputPath,
970+
// Pre-set this because it is set by symlink
971+
symlink: outputPath,
972+
});
973+
974+
breakPrototype(file);
975+
976+
function assert(files) {
977+
expect(files.length).toEqual(1);
978+
// Avoid comparing stats because they get reflected
979+
delete files[0].stat;
980+
expect(files[0]).toMatch(file);
981+
expect(files[0]).toNotBe(file);
982+
}
983+
984+
pipe([
985+
from.obj([file]),
986+
vfs.symlink(outputBase),
987+
concat(assert),
988+
], done);
989+
});
943990
});

test/utils/break-prototype.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
var File = require('vinyl');
4+
5+
function breakPrototype(file) {
6+
// Set up a broken prototype
7+
var oldProto = {};
8+
Object.getOwnPropertyNames(File.prototype).forEach(function(key) {
9+
if (key !== 'isSymbolic') {
10+
var desc = Object.getOwnPropertyDescriptor(File.prototype, key);
11+
Object.defineProperty(oldProto, key, desc);
12+
}
13+
});
14+
15+
// Assign the broken prototype to our instance
16+
if (typeof Object.setPrototypeOf === 'function') {
17+
Object.setPrototypeOf(file, oldProto);
18+
} else {
19+
file.__proto__ = oldProto;
20+
}
21+
}
22+
23+
module.exports = breakPrototype;

0 commit comments

Comments
 (0)