Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable match on a per-directory basis #53

Closed
notpeelz opened this issue Oct 2, 2015 · 5 comments
Closed

Unable match on a per-directory basis #53

notpeelz opened this issue Oct 2, 2015 · 5 comments

Comments

@notpeelz
Copy link

notpeelz commented Oct 2, 2015

Sample gulpfile:

var gulp = require('gulp'),
    debug = require('gulp-debug'),
    filter = require('gulp-filter');

gulp.src('./build/css/**/*.css')
    .pipe(debug({ title: 'base-pre' }))
    .pipe(filter('build/css/**/*.css'))
    .pipe(debug({ title: 'base-post' }));

gulp.src('./build/css/**/*.css')
    .pipe(debug({ title: 'glob-pre' }))
    .pipe(filter('**/*.css'))
    .pipe(debug({ title: 'glob-post' }));

Output:

[14:29:32] base-pre ~/path/to/project/build/css/site.css
[14:29:32] base-pre ~/path/to/project/build/css/dummy.css
[14:29:32] base-pre 2 items
[14:29:32] base-post 0 items
[14:29:32] glob-pre ~/path/to/project/build/css/site.css
[14:29:32] glob-pre ~/path/to/project/build/css/dummy.css
[14:29:32] glob-post ~/path/to/project/build/css/site.css
[14:29:32] glob-post ~/path/to/project/build/css/dummy.css
[14:29:32] glob-pre 2 items
[14:29:32] glob-post 2 items

I'm not quite sure as to what's causing this issue; whether it has to do with streamfilter, multimatch or minimatch, non-glob patterns are clearly not being applied correctly.

Related issue: #52


Upon further analysis, I have come to the conclusion that this really only has to do with the way Gulp handles streams works (as opposed to actually being a bug; see gulpjs/gulp#699).

All things considered, I ended up setting the base directory to ./ to keep it from interpreting the build directory as the base: gulp.src('./build/css/**/*.css', { base: './' })

It could be a good idea to include a similar example in the README.md so to help out other users facing this issue.

@kewwwa
Copy link

kewwwa commented Jan 5, 2016

I also came up with a strange combo with main-bower-files 2.11.0.

main-bower-files + gulp-filter = not working

gulp.src(mainBowerFiles())
    .pipe(gulpFilter('**/fonts/*'))
    .pipe(gulp.dest('./demo/assets/fonts'));

main-bower-files + basedir + gulp-filter = working

gulp.src(mainBowerFiles(), {base: './'})
    .pipe(gulpFilter('**/fonts/*'))
    .pipe(gulp.dest('./demo/assets/fonts'));

main-bower-files with filter = working

gulp.src(mainBowerFiles('**/fonts/*'))
    .pipe(gulp.dest('./demo/assets/fonts'));

simple gulp.src + gulp-filter = working

gulp.src('bower_components/**')
    .pipe(gulpFilter('**/fonts/*'))
    .pipe(gulp.dest('./demo/assets/fonts'));

@notpeelz
Copy link
Author

notpeelz commented Jan 6, 2016

@kewwwa That's definitely odd; I remember encountering the same issues while toying around with my gulpfile, but I couldn't quite figure out where the inconsistency stemmed from.

My hypothesis as to what's causing the issue at hand is that, when sourcing mainBowerFiles() directly (i.e. gulp.src(mainBowerFiles())), the base directory remains unchanged, so any further glob patterns will be matched against the (wrong) root directory.

In your case, it seems that main-bower-files is to blame... but it doesn't quite relate to the original issue. Could this be the intended behavior after all—however unintuitive it is?

@nweldev
Copy link

nweldev commented Jan 13, 2016

+1 ... Here is my code :

gulp.src(modJsFiles)
                .pipe(debug({title : 'modJsFiles'}))
                .pipe(filter(['app/**/*.js']))
                .pipe(debug({title : 'app js filtered'}))

and its output :

[16:29:51] modJsFiles app\layout\layout-footer_component.js
[16:29:51] modJsFiles gulp-eslintrc.json
[16:29:51] modJsFiles gulpfile.babel.js
[16:29:51] modJsFiles package.json
[16:29:51] modJsFiles scripts\gulp-utils\gitUtil.js
[16:29:51] modJsFiles 5 items
[16:29:51] app js filtered 0 items

@notpeelz
Copy link
Author

@noelmace Where does modJsFiles come from? You would have to set the base directory on that stream so that gulp-filter can match the pattern correctly.

@mix3d
Copy link

mix3d commented Mar 15, 2016

Another thing that i noticed, was the filter has forward slashes, while the output of modJsFiles has backward slashes. Depending on your operating system this could cause a mismatch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants