I am learning about the gulp source code and tried to write a gulp plugin.
Now I am confused about something.
This is my plugin code below:
module.exports = function(){
return through2.obj(function(file,encode,callback){
console.log(vinyl.isVinyl(file));//false
console.log(file._isVinyl) // undefined
// the reason ? file is not Object of vinyl ? file's property of '_isVinyl' is undefine ?
if(file.isNull()){
callback(null,file);
}
if(file.isStream()){
file.contents = file.contents.pipe(through2(function(chuck,encode,callback){
if(util.isNull(chuck)){
callback(null, chuck);
}
if(util.isBuffer(chuck)){
chuck = new Buffer(String(chuck)
.replace(commentReg, '')
.replace(blankSpaceReg,''))
}
callback(null,chuck);
}));
}
if(file.isBuffer()){
file.contents = new Buffer(String(file.contents)
.replace(commentReg, '')
.replace(blankSpaceReg,''));
}
callback(null,file);
})
}
This is the part of the gulp source code where vinyl
files are created:
https://github.com/gulpjs/vinyl-fs/blob/master/lib/src/wrap-with-vinyl-file.js
MY CONFUSION:
The transformFunction
registered with though2.obj()
receives a file
object that should be a vinyl
file.
Why does vinyl.isVinyl()
return false
?
Why doesn't the file
object have a _isVinyl
property?