Closed UltCombo closed 9 years ago
(improved a comment & squashed)
Changed commit message.
Nice catch - thanks!
No problem, though, I believe it lost a bit of readability, seeing as negatives' glob
property now holds either a RegExp or Minimatch instance, which is a little counterintuitive. Perhaps it would be cleaner if this patch was more similar to the one I submitted to globby (https://github.com/sindresorhus/globby/commit/e402d9fbb6d16f2c4f1464d8323fefd16116af04), that is, iterating over the negatives and creating a matcher
property.
This optimizes use cases such as
['a', 'b', '!b']
, where a new Minimatch instance for'!b'
would be created for each previous positive glob.Now the Minimatch instances for negative globs are created beforehand, thus positive globs can use the same negative matcher instances. That is, for
['a', 'b', '!b']
both'a'
and'b'
globs will use the same Minimatch instance for'!b'
instead of instantiating their own.Also, as far as I can see,
gs.createStream
is internal (no docs or tests), so I took the liberty of adapting it a bit as I needed the completeopt
object to pass to the Minimatch constructor ings.create
.Should also note that this change, technically, would instantiate Minimatch instances that would never be used when considering leading negative globs (e.g.
['!b', 'b']
), but that is a complete misuse and IIRC Minimatch produces their underlying regex lazily, so this shouldn't be a problem.