Skip to content

Commit

Permalink
Fix: Temporarily marshall old Vinyl objects to latest version in dest…
Browse files Browse the repository at this point in the history
…/symlink (#291)
  • Loading branch information
phated committed Dec 28, 2017
1 parent 3b4ab64 commit bbfb50c
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/dest/prepare.js
Expand Up @@ -16,6 +16,11 @@ function prepareWrite(folderResolver, optResolver) {
return cb(new Error('Received a non-Vinyl object in `dest()`'));
}

// TODO: Remove this after people upgrade vinyl/transition from gulp-util
if (typeof file.isSymbolic !== 'function') {
file = new Vinyl(file);
}

var outFolderPath = folderResolver.resolve('outFolder', file);
if (!outFolderPath) {
return cb(new Error('Invalid output folder'));
Expand Down
5 changes: 5 additions & 0 deletions lib/symlink/prepare.js
Expand Up @@ -16,6 +16,11 @@ function prepareSymlink(folderResolver, optResolver) {
return cb(new Error('Received a non-Vinyl object in `symlink()`'));
}

// TODO: Remove this after people upgrade vinyl/transition from gulp-util
if (typeof file.isSymbolic !== 'function') {
file = new Vinyl(file);
}

var cwd = path.resolve(optResolver.resolve('cwd', file));

var outFolderPath = folderResolver.resolve('outFolder', file);
Expand Down
45 changes: 45 additions & 0 deletions test/dest.js
Expand Up @@ -16,6 +16,7 @@ var applyUmask = require('./utils/apply-umask');
var testStreams = require('./utils/test-streams');
var always = require('./utils/always');
var testConstants = require('./utils/test-constants');
var breakPrototype = require('./utils/break-prototype');

var from = miss.from;
var pipe = miss.pipe;
Expand Down Expand Up @@ -1018,4 +1019,48 @@ describe('.dest()', function() {
concat(assert),
], done);
});

it('does not marshall a Vinyl object with isSymbolic method', function(done) {
var file = new File({
base: outputBase,
path: outputPath,
});

function assert(files) {
expect(files.length).toEqual(1);
// Avoid comparing stats because they get reflected
delete files[0].stat;
expect(files[0]).toMatch(file);
expect(files[0]).toBe(file);
}

pipe([
from.obj([file]),
vfs.dest(outputBase),
concat(assert),
], done);
});

it('marshalls a Vinyl object without isSymbolic to a newer Vinyl', function(done) {
var file = new File({
base: outputBase,
path: outputPath,
});

breakPrototype(file);

function assert(files) {
expect(files.length).toEqual(1);
// Avoid comparing stats because they get reflected
delete files[0].stat;
expect(files[0]).toMatch(file);
expect(files[0]).toNotBe(file);
}

pipe([
from.obj([file]),
vfs.dest(outputBase),
concat(assert),
], done);
});
});
47 changes: 47 additions & 0 deletions test/symlink.js
Expand Up @@ -14,6 +14,7 @@ var isWindows = require('./utils/is-windows');
var testStreams = require('./utils/test-streams');
var always = require('./utils/always');
var testConstants = require('./utils/test-constants');
var breakPrototype = require('./utils/break-prototype');

var from = miss.from;
var pipe = miss.pipe;
Expand Down Expand Up @@ -940,4 +941,50 @@ describe('symlink stream', function() {
concat(assert),
], done);
});

it('does not marshall a Vinyl object with isSymbolic method', function(done) {
var file = new File({
base: outputBase,
path: outputPath,
});

function assert(files) {
expect(files.length).toEqual(1);
// Avoid comparing stats because they get reflected
delete files[0].stat;
expect(files[0]).toMatch(file);
expect(files[0]).toBe(file);
}

pipe([
from.obj([file]),
vfs.symlink(outputBase),
concat(assert),
], done);
});

it('marshalls a Vinyl object without isSymbolic to a newer Vinyl', function(done) {
var file = new File({
base: outputBase,
path: outputPath,
// Pre-set this because it is set by symlink
symlink: outputPath,
});

breakPrototype(file);

function assert(files) {
expect(files.length).toEqual(1);
// Avoid comparing stats because they get reflected
delete files[0].stat;
expect(files[0]).toMatch(file);
expect(files[0]).toNotBe(file);
}

pipe([
from.obj([file]),
vfs.symlink(outputBase),
concat(assert),
], done);
});
});
23 changes: 23 additions & 0 deletions test/utils/break-prototype.js
@@ -0,0 +1,23 @@
'use strict';

var File = require('vinyl');

function breakPrototype(file) {
// Set up a broken prototype
var oldProto = {};
Object.getOwnPropertyNames(File.prototype).forEach(function(key) {
if (key !== 'isSymbolic') {
var desc = Object.getOwnPropertyDescriptor(File.prototype, key);
Object.defineProperty(oldProto, key, desc);
}
});

// Assign the broken prototype to our instance
if (typeof Object.setPrototypeOf === 'function') {
Object.setPrototypeOf(file, oldProto);
} else {
file.__proto__ = oldProto;
}
}

module.exports = breakPrototype;

0 comments on commit bbfb50c

Please sign in to comment.