gulp icon indicating copy to clipboard operation
gulp copied to clipboard

File objects in stream aren't vinyl instances

Open christav opened this issue 10 years ago • 1 comments

I was trying to write a plugin that tweaks the filename (changes the extension) as it goes through the pipeline. Unfortunately, it wasn't working. I did some experimenting, and apparently the objects being piped out of gulp.src are not Vinyl wrapper instances, and are therefore missing the properties like relative, basename, stem, etc.

My repro environment:

OS: windows 10

> gulp -v
[22:42:26] CLI version 1.2.1
[22:42:26] Local version 3.9.1

> node -v
v6.2.2

And the gulpfile:

const File = require('vinyl');
const gulp = require('gulp');
const through2 = require('through2');

function dump() {
  return through2.obj((file, enc, done) => {
    console.log(file.path, ':', File.isVinyl(file));
    done();
  });
}

gulp.task('default', () => {
  return gulp.src('./*')
    .pipe(dump());
});

The output:

[22:55:46] Using gulpfile C:\dev\gulp-streams-bug\gulpfile.js
[22:55:46] Starting 'default'...
C:\dev\gulp-streams-bug\gulpfile.js : false
C:\dev\gulp-streams-bug\node_modules : false
[22:55:46] Finished 'default' after 21 ms

I would have expected that false to be true.

Am I reading the documentation incorrectly? Am I doing something wrong? Or is there a bug here?

Note: I've tried this with both the through2 module and straight node Transform stream. Same results.

christav avatar Jul 09 '16 05:07 christav

Old gulp is using old vinyl so that won't report correctly. Use gulp 4 or newer vinyl-fs directly. Support questions should be directed to StackOverflow.

phated avatar Jul 09 '16 06:07 phated