Skip to content

Commit 604805d

Browse files
committed
Introduce Node.js 6+ compatibility mode for gulp@3
1 parent 347ed5a commit 604805d

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

compat.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
// Initialize vinyl-fs-wrap in Node.js 6+ compatibility mode
4+
var vfsWrap = require('./vinyl-fs-wrap');
5+
vfsWrap.initCompat();
6+
7+
// Export the origial Gulp
8+
module.exports = require('./index');

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ var util = require('util');
44
var Orchestrator = require('orchestrator');
55
var gutil = require('gulp-util');
66
var deprecated = require('deprecated');
7-
var vfs = require('vinyl-fs');
7+
8+
var vfsWrap = require('./vinyl-fs-wrap');
9+
vfsWrap.init();
10+
var vfs = vfsWrap.vfs;
811

912
function Gulp() {
1013
Orchestrator.call(this);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"semver": "^4.1.0",
3939
"tildify": "^1.0.0",
4040
"v8flags": "^2.0.2",
41-
"vinyl-fs": "^0.3.0"
41+
"vinyl-fs": "^0.3.0",
42+
"vinyl-fs-03-compat": "^0.3.15"
4243
},
4344
"devDependencies": {
4445
"coveralls": "^2.7.0",

vinyl-fs-wrap.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
var compat = false;
4+
5+
function init() {
6+
if (exports.vfs) {
7+
return;
8+
}
9+
exports.vfs = require('vinyl-fs');
10+
}
11+
12+
function initCompat() {
13+
if (exports.vfs) {
14+
if (!compat) {
15+
throw new Error(
16+
'Gulp was already initialized without Node.js 6+ compatibility mode!\n' +
17+
'Make sure that you require gulp/compat before other gulp plugins.\n' +
18+
'\n' +
19+
'Note that dependencies should not force this mode.\n' +
20+
'The compatibility mode is intended only for the top-most gulpfile.js.\n'
21+
);
22+
}
23+
return;
24+
}
25+
compat = true;
26+
exports.vfs = require('vinyl-fs-03-compat');
27+
}
28+
29+
exports.init = init;
30+
exports.initCompat = initCompat;

0 commit comments

Comments
 (0)