From 604805d138609ac5ecfecaedb1c96e3dfed308ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 18 Aug 2016 17:39:47 +0300 Subject: [PATCH] Introduce Node.js 6+ compatibility mode for gulp@3 --- compat.js | 8 ++++++++ index.js | 5 ++++- package.json | 3 ++- vinyl-fs-wrap.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 compat.js create mode 100644 vinyl-fs-wrap.js 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;