|
2 | 2 | const path = require('path'); |
3 | 3 | const globby = require('globby'); |
4 | 4 | const ignoreByDefault = require('ignore-by-default'); |
5 | | -const micromatch = require('micromatch'); |
| 5 | +const picomatch = require('picomatch'); |
6 | 6 | const slash = require('slash'); |
7 | 7 |
|
8 | 8 | const defaultIgnorePatterns = [...ignoreByDefault.directories(), '**/node_modules']; |
9 | | -const defaultMicromatchIgnorePatterns = [ |
| 9 | +const defaultPicomatchIgnorePatterns = [ |
10 | 10 | ...defaultIgnorePatterns, |
11 | | - // Unlike globby(), micromatch needs a complete pattern when ignoring directories. |
| 11 | + // Unlike globby(), picomatch needs a complete pattern when ignoring directories. |
12 | 12 | ...defaultIgnorePatterns.map(pattern => `${pattern}/**/*`) |
13 | 13 | ]; |
14 | 14 |
|
| 15 | +const defaultMatchNoIgnore = picomatch(defaultPicomatchIgnorePatterns); |
| 16 | + |
15 | 17 | const defaultIgnoredByWatcherPatterns = [ |
16 | 18 | '**/*.snap.md', // No need to rerun tests when the Markdown files change. |
17 | 19 | 'ava.config.js', // Config is not reloaded so avoid rerunning tests when it changes. |
@@ -141,35 +143,37 @@ const matchingCache = new WeakMap(); |
141 | 143 | const processMatchingPatterns = input => { |
142 | 144 | let result = matchingCache.get(input); |
143 | 145 | if (!result) { |
144 | | - const ignore = [...defaultMicromatchIgnorePatterns]; |
| 146 | + const ignore = [...defaultPicomatchIgnorePatterns]; |
145 | 147 | const patterns = input.filter(pattern => { |
146 | 148 | if (pattern.startsWith('!')) { |
147 | | - // Unlike globby(), micromatch needs a complete pattern when ignoring directories. |
| 149 | + // Unlike globby(), picomatch needs a complete pattern when ignoring directories. |
148 | 150 | ignore.push(pattern.slice(1), `${pattern.slice(1)}/**/*`); |
149 | 151 | return false; |
150 | 152 | } |
151 | 153 |
|
152 | 154 | return true; |
153 | 155 | }); |
154 | 156 |
|
155 | | - result = {patterns, ignore}; |
| 157 | + result = { |
| 158 | + match: picomatch(patterns, {ignore}), |
| 159 | + matchNoIgnore: picomatch(patterns) |
| 160 | + }; |
156 | 161 | matchingCache.set(input, result); |
157 | 162 | } |
158 | 163 |
|
159 | 164 | return result; |
160 | 165 | }; |
161 | 166 |
|
162 | 167 | function matches(file, patterns) { |
163 | | - let ignore; |
164 | | - ({patterns, ignore} = processMatchingPatterns(patterns)); |
165 | | - return micromatch.some(file, patterns, {ignore}); |
| 168 | + const {match} = processMatchingPatterns(patterns); |
| 169 | + return match(file); |
166 | 170 | } |
167 | 171 |
|
168 | 172 | exports.matches = matches; |
169 | 173 |
|
170 | 174 | const matchesIgnorePatterns = (file, patterns) => { |
171 | | - ({patterns} = processMatchingPatterns(patterns)); |
172 | | - return micromatch.some(file, [...patterns, ...defaultMicromatchIgnorePatterns]); |
| 175 | + const {matchNoIgnore} = processMatchingPatterns(patterns); |
| 176 | + return matchNoIgnore(file) || defaultMatchNoIgnore(file); |
173 | 177 | }; |
174 | 178 |
|
175 | 179 | function normalizeFileForMatching(cwd, file) { |
|
0 commit comments