diff --git a/compat.js b/compat.js new file mode 100644 index 000000000..2cc7bb958 --- /dev/null +++ b/compat.js @@ -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'); diff --git a/index.js b/index.js index 42bc69b3d..03adeafb4 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/package.json b/package.json index b60ba7d52..ff1e35796 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/vinyl-fs-wrap.js b/vinyl-fs-wrap.js new file mode 100644 index 000000000..5c6351e68 --- /dev/null +++ b/vinyl-fs-wrap.js @@ -0,0 +1,30 @@ +'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 without Node.js 6+ compatibility mode!\n' + + 'Make sure that you require gulp/compat before other gulp plugins.\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;