robrich / gulp-match

Does a vinyl file match a condition?
MIT License
23 stars 9 forks source link

Gulp Match operates on file.relative, not file.path (as stated in README) #10

Closed edj-boston closed 8 years ago

edj-boston commented 8 years ago

gulp-match passes file.relative to minimatch rather than file.path. That means minimatch is only looking at file names like 'custom.js' rather than full paths.

So let's say I have some local JS and some 3rd party deps for my project. The local JS files are written in ES6 so I want to selectively transpile them. I use gulp-if (which uses gulp-match under the hood) and pass it a glob. But gulp-if can't tell the files apart becuase it only has the file names coming from file.relative.

gulp.task('foo', function() {
    return gulp.src([
        'node_modules/some-module/js/plugin.js',
        'src/js/*'
    ])
    .pipe(gulpif(glob, babel()))
    .pipe(concat('all.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('build'));
});

In fact, if two JS libraries use the name file name, we can't tell them apart. If I have 'plugin.js' in src/js I can't tell it apart from 'node_modules/some-module/js/plugin.js'.

robrich commented 8 years ago

Good catch. The readme is out of date. You can set cwd to an unambiguous parent directory to get path.relative to be descriptive enough. On Jan 11, 2016 9:19 AM, "Eric Johnson" notifications@github.com wrote:

gulp-match passes file.relative to minimatch rather than file.path. That means minimatch is only looking at file names like 'custom.js' rather than full paths.

So let's say I have some local JS and some 3rd party deps for my project. The local JS files are written in ES6 so I want to selectively transpile them. I use gulp-if (which uses gulp-match under the hood) and pass it a glob. But gulp-if can't tell the files apart becuase it only has the file names coming from file.relative.

gulp.task('foo', function() { return gulp.src([ 'node_modules/some-module/js/plugin.js', 'src/js/*' ]) .pipe(gulpif(glob, babel())) .pipe(concat('all.min.js')) .pipe(uglify()) .pipe(gulp.dest('build')); });

In fact, if two JS libraries use the name file name, we can't tell them apart. If I have 'plugin.js' in src/js I can't tell it apart from 'node_modules/some-module/js/plugin.js'.

— Reply to this email directly or view it on GitHub https://github.com/robrich/gulp-match/issues/10.

edj-boston commented 8 years ago

So I pass a cwd option to gulp.src() that gets passed to node-glob?

robrich commented 8 years ago

Yes