Skip to content

Commit

Permalink
Introduce Node.js 6+ compatibility mode for gulp@3
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Aug 18, 2016
1 parent 347ed5a commit 8340432
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
8 changes: 8 additions & 0 deletions compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

// Initialize vinyl-fs-wrap in Node.js 6+ compatibility mode
var vfsWrap = require('./vinyl-fs-wrap');
vfsWrap.initCompat();

// Export the origial Gulp
module.exports = require('./index');
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ var util = require('util');
var Orchestrator = require('orchestrator');
var gutil = require('gulp-util');
var deprecated = require('deprecated');
var vfs = require('vinyl-fs');

var vfsWrap = require('./vinyl-fs-wrap');
vfsWrap.init();
var vfs = vfsWrap.vfs;

function Gulp() {
Orchestrator.call(this);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"semver": "^4.1.0",
"tildify": "^1.0.0",
"v8flags": "^2.0.2",
"vinyl-fs": "^0.3.0"
"vinyl-fs": "^0.3.0",
"vinyl-fs-03-compat": "^0.3.15"
},
"devDependencies": {
"coveralls": "^2.7.0",
Expand Down
31 changes: 31 additions & 0 deletions vinyl-fs-wrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

var compat = false;

function init() {
if (exports.vfs) {
return;
}
exports.vfs = require('vinyl-fs');
}

function initCompat() {
if (exports.vfs) {
if (!compat) {
throw new Error(
'Gulp was already initialized in Node.js 6+ compatibility mode!\n' +
'Make sure that you require gulp/compat before other gulp plugins.\n' +
'If you do not, this error should not happen.\n' +
'\n' +
'Note that dependencies should not force this mode.\n' +
'The compatibility mode is intended only for the top-most gulpfile.js.\n'
);
}
return;
}
compat = true;
exports.vfs = require('vinyl-fs-03-compat');
}

exports.init = init;
exports.initCompat = initCompat;

0 comments on commit 8340432

Please sign in to comment.