micromatch: pattern broken from 3.x to 4.x

(Thanks for reporting an issue to micromatch! If you haven’t already read the contributor guidelines, Please do that now, then proceed to fill out the details below.)

Please describe the minimum necessary steps to reproduce this issue:

const mm = require('micromatch');
const files = ['yoooo.js','foo/baz/something.js', 'bar/baz/something.js', 'anything-else/foo.js', 'anything/__tests__/else.js'];
mm(files, '!(bar/baz|foo|**/__tests_)/**/*.js')

What is happening that shouldn’t be?

[ 'foo/baz/something.js',
  'bar/baz/something.js',
  'anything-else/foo.js',
  'anything/__tests__/else.js' ]

all the files match. this is with 4.0.2

What should be happening instead?

[ 'anything-else/foo.js' ]

this worked correctly in 3.x

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@Ignigena thanks for confirming. I’ll look into this.

This is also a blocker for us, so stopping by to show my support ❤️

@jonschlinkert were you able the look into this? It seemingly is a cause of a horrible performance regression in jest (see https://github.com/facebook/jest/issues/9457)

This will be fixed once picomatch gets updated here. Leaving open for now.

@jonschlinkert I can confirm this as well. Prettier has an extensive test suite that I ran it against. https://github.com/prettier/prettier/pull/7726

The case was:

Pattern: **/__best-tests__/*.js File Path: __best-tests__/file.js Marked as not a match

https://github.com/prettier/prettier/blob/61d3936b6e13238e0eb16fab3ca53d75fc942030/tests_integration/__tests__/config-resolution.js#L70

All tests pass with v3.1.10 4 tests fail with v4.0.2

Hi @kibertoad, micromatch depends on picomatch.

Seeing similar things here with a negative matching glob and was able to reproduce on RunKit https://npm.runkit.com/micromatch

const micromatch = require("micromatch@3.1.10")
micromatch([
  'tests/fixtures/sns/notification/delete.js'
], [
  '**/*.js',
  '!(coverage|config|scripts|tests)/**'
])

Returns [] as expected since the file path is excluded by the second glob pattern. However, in version 4, this exact same code is broken and returns the file path as a match:

const micromatch = require("micromatch@4.0.2")
micromatch([
  'tests/fixtures/sns/notification/delete.js'
], [
  '**/*.js',
  '!(coverage|config|scripts|tests)/**'
])

If I update the second glob pattern to !**/(coverage|config|scripts|tests)/** the path is excluded in version 4 but it feels like a bit of a workaround since the pattern was written that way to only exclude when the root directory matches.