I'm writing plugin for Gulp, and in order to process file i need to get it's full path. I used through2 package, then prepared processFile(file) function, but as an argument from through2 it receives file in strange XML-like format instead of object like file.path, file.encoding and so on.
How can I receive file.path when through2 is returning each file in following format:
<File "relative/path/to/file/aaa.js" ...
Full code:
var through = require('through2');
module.exports = function() {
return through.obj(function(file, encoding, callback) {
function processFile(file){
console.log(file); // returns <File "relative/path/to/file/aaa.js" ...
}
callback(null, processFile(file));
});
};
What you get on the console is just how
Fileobjects are turned into strings byconsole.log, which is what happens when you executeconsole.log(file). Ultimately, theinspectmethod is called and you get the results you see (which is not XML, by the way).If I use your code and dump to the console
file.path, I get the correct values. Same withfile.baseandfile.relative.