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

opts.ignore not applied to results emitted by match #194

Closed
jmm opened this issue May 6, 2015 · 9 comments
Closed

opts.ignore not applied to results emitted by match #194

jmm opened this issue May 6, 2015 · 9 comments

Comments

@jmm
Copy link

jmm commented May 6, 2015

Given glob@5.0.5, node v0.10.32, on linux, and the following test case:

var
  glob = require('glob'),
  paths = {basename: 'test.js'},
  opts = {};

paths.in = paths.basename;
opts.ignore = paths.in;
opts.cwd = __dirname;

(new glob.Glob(paths.in, opts))
  .on('match', function (match) {
    console.log('match', match === opts.ignore);
  })
  .on('end', function (matches) {
    console.log('end', matches.length);
  });

I expect the output to be:

end 0

Actual output:

match true
end 0
@mlmorg
Copy link

mlmorg commented Jun 6, 2015

+1

You can get around this today by doing something like:

var glob = require('glob');
var isIgnored = require('glob/common').isIgnored;

var globber = new glob.Glob('**/*.js', {ignore: ['foo.js']});
globber.on('match', function onMatch(match) {
  if (isIgnored(globber, match)) {
    return;
  }
  // Do something will paths that are not ignored...
});

@jmm
Copy link
Author

jmm commented Jun 8, 2015

@mlmorg Unfortunately that's no help for my situation: using gulp.src(), which uses this under the hood. With that all you can do is pass in pattern and options and it implements a match handler. However, they special-case negated patterns (!whatever), so I'm relying on that for now, although it feels pretty hokey since gulp.src() is documented as accepting the same pattern and options input as node-glob

@mik01aj
Copy link

mik01aj commented Jul 2, 2015

+1.

I do glob.sync('**/*-test.js', {cwd: '../api', ignore: ['*-integration-test.js']}) and get:

[ '__tests__/Mapper-test.js',
  '__tests__/authorization-integration-test.js', <--- WTF?
(...)
  'services/__tests__/s3service-test.js' ]

@isaacs
Copy link
Owner

isaacs commented Jul 2, 2015

@mik01aj You should use ignore: ['**/*-integration-test.js']. As you've written it, it'll only ignore *-integration-test.js files that are not in a sub-directory.

@isaacs
Copy link
Owner

isaacs commented Jul 2, 2015

Patch welcome for this. Probably just need to find the bits where match is emitted and call isIgnored like @mlmorg is doing in the workaround. I'll get to it soon-ish if no one else does. (Note that patches require a test!)

@isaacs isaacs closed this as completed in f5878af Jul 2, 2015
@jmm
Copy link
Author

jmm commented Jul 2, 2015

Awesome, thanks!

@isaacs
Copy link
Owner

isaacs commented Jul 2, 2015

I've noticed that with this module, and a few others, about half the time I say "patch welcome" I end up just writing it later that afternoon...

@jmm
Copy link
Author

jmm commented Jul 2, 2015

If only you could sense when you were going to say patch welcome a few weeks in advance...

@mlmorg
Copy link

mlmorg commented Jul 3, 2015

Thanks @isaacs. Sorry, I was going to take a look at it later tonight but glad you got to it first!

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

4 participants