Skip to content

Commit b33ce0d

Browse files
committed
chore: upgrade to micromatch v4 (#8852)
* chore: upgrade to micromatch v4 * fix anymatch namespace issue * use match instead of some * add explicit check for length 0 * more length boolean checks
1 parent d6ff72a commit b33ce0d

File tree

14 files changed

+43
-32
lines changed

14 files changed

+43
-32
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- `[*]` [**BREAKING**] Drop support for Node 6 ([#8455](https://github.com/facebook/jest/pull/8455))
1515
- `[*]` Add Node 12 to CI ([#8411](https://github.com/facebook/jest/pull/8411))
16+
- `[*]` [**BREAKING**] Upgrade to Micromatch v4 ([#8852](https://github.com/facebook/jest/pull/8852))
1617
- `[docs]` Fix broken link pointing to legacy JS file in "Snapshot Testing".
1718
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM from v11 to v15 ([#8851](https://github.com/facebook/jest/pull/8851))
1819

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"karma-webpack": "4.0.0-rc.5",
5656
"left-pad": "^1.1.1",
5757
"lerna": "3.15.0",
58-
"micromatch": "^3.1.10",
58+
"micromatch": "^4.0.2",
5959
"mkdirp": "^0.5.1",
6060
"mocha": "^6.0.2",
6161
"mock-fs": "^4.4.1",

packages/jest-config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"jest-resolve": "^24.9.0",
2525
"jest-util": "^24.9.0",
2626
"jest-validate": "^24.9.0",
27-
"micromatch": "^3.1.10",
27+
"micromatch": "^4.0.2",
2828
"pretty-format": "^24.9.0",
2929
"realpath-native": "^1.1.0"
3030
},

packages/jest-config/src/normalize.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {Config} from '@jest/types';
1212
import {ValidationError, validate} from 'jest-validate';
1313
import {clearLine, replacePathSepForGlob} from 'jest-util';
1414
import chalk from 'chalk';
15-
import {some as micromatchSome} from 'micromatch';
15+
import micromatch from 'micromatch';
1616
import {sync as realpath} from 'realpath-native';
1717
import Resolver from 'jest-resolve';
1818
import {replacePathSepForRegex} from 'jest-regex-util';
@@ -982,10 +982,10 @@ export default function normalize(
982982
if (newOptions.collectCoverageFrom) {
983983
collectCoverageFrom = collectCoverageFrom.reduce((patterns, filename) => {
984984
if (
985-
!micromatchSome(
986-
replacePathSepForGlob(path.relative(options.rootDir, filename)),
985+
micromatch(
986+
[replacePathSepForGlob(path.relative(options.rootDir, filename))],
987987
newOptions.collectCoverageFrom!,
988-
)
988+
).length === 0
989989
) {
990990
return patterns;
991991
}

packages/jest-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"jest-util": "^24.9.0",
2828
"jest-validate": "^24.9.0",
2929
"jest-watcher": "^24.9.0",
30-
"micromatch": "^3.1.10",
30+
"micromatch": "^4.0.2",
3131
"p-each-series": "^1.0.0",
3232
"realpath-native": "^1.1.0",
3333
"rimraf": "^2.5.4",

packages/jest-core/src/SearchSource.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as path from 'path';
9-
import {some as micromatchSome} from 'micromatch';
9+
import micromatch from 'micromatch';
1010
import {Context} from 'jest-runtime';
1111
import {Config} from '@jest/types';
1212
import {Test} from 'jest-runner';
@@ -37,7 +37,7 @@ export type TestSelectionConfig = {
3737
};
3838

3939
const globsToMatcher = (globs: Array<Config.Glob>) => (path: Config.Path) =>
40-
micromatchSome(replacePathSepForGlob(path), globs, {dot: true});
40+
micromatch([replacePathSepForGlob(path)], globs, {dot: true}).length > 0;
4141

4242
const regexToMatcher = (testRegex: Array<string>) => (path: Config.Path) =>
4343
testRegex.some(testRegex => new RegExp(testRegex).test(path));

packages/jest-haste-map/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"types": "build/index.d.ts",
1212
"dependencies": {
1313
"@jest/types": "^24.9.0",
14-
"anymatch": "^2.0.0",
14+
"anymatch": "^3.0.3",
1515
"fb-watchman": "^2.0.0",
1616
"graceful-fs": "^4.1.15",
1717
"invariant": "^2.2.4",
1818
"jest-serializer": "^24.9.0",
1919
"jest-util": "^24.9.0",
2020
"jest-worker": "^24.9.0",
21-
"micromatch": "^3.1.10",
21+
"micromatch": "^4.0.2",
2222
"sane": "^4.0.3",
2323
"walker": "^1.0.7"
2424
},

packages/jest-haste-map/src/HasteFS.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {some as micromatchSome} from 'micromatch';
8+
import micromatch from 'micromatch';
99
import {replacePathSepForGlob} from 'jest-util';
1010
import {Config} from '@jest/types';
1111
import {FileData} from './types';
@@ -86,7 +86,7 @@ export default class HasteFS {
8686
const files = new Set<string>();
8787
for (const file of this.getAbsoluteFileIterator()) {
8888
const filePath = root ? fastPath.relative(root, file) : file;
89-
if (micromatchSome(replacePathSepForGlob(filePath), globs)) {
89+
if (micromatch([replacePathSepForGlob(filePath)], globs).length > 0) {
9090
files.add(file);
9191
}
9292
}

packages/jest-haste-map/src/lib/FSEventsWatcher.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import * as fs from 'fs';
1010
import * as path from 'path';
1111
import {EventEmitter} from 'events';
12-
import anymatch from 'anymatch';
13-
import {some as micromatchSome} from 'micromatch';
12+
import anymatch, {Matcher} from 'anymatch';
13+
import micromatch from 'micromatch';
1414
// eslint-disable-next-line
1515
import {Watcher} from 'fsevents';
1616
// @ts-ignore no types
@@ -40,7 +40,7 @@ type FsEventsWatcherEvent =
4040
*/
4141
class FSEventsWatcher extends EventEmitter {
4242
public readonly root: string;
43-
public readonly ignored?: anymatch.Matcher;
43+
public readonly ignored?: Matcher;
4444
public readonly glob: Array<string>;
4545
public readonly dot: boolean;
4646
public readonly hasIgnore: boolean;
@@ -65,7 +65,7 @@ class FSEventsWatcher extends EventEmitter {
6565
fileCallback: (normalizedPath: string, stats: fs.Stats) => void,
6666
endCallback: Function,
6767
errorCallback: Function,
68-
ignored?: anymatch.Matcher,
68+
ignored?: Matcher,
6969
) {
7070
walker(dir)
7171
.filterDir(
@@ -83,7 +83,7 @@ class FSEventsWatcher extends EventEmitter {
8383
dir: string,
8484
opts: {
8585
root: string;
86-
ignored?: anymatch.Matcher;
86+
ignored?: Matcher;
8787
glob: string | Array<string>;
8888
dot: boolean;
8989
},
@@ -139,8 +139,8 @@ class FSEventsWatcher extends EventEmitter {
139139
return false;
140140
}
141141
return this.glob.length
142-
? micromatchSome(relativePath, this.glob, {dot: this.dot})
143-
: this.dot || micromatchSome(relativePath, '**/*');
142+
? micromatch([relativePath], this.glob, {dot: this.dot}).length > 0
143+
: this.dot || micromatch([relativePath], '**/*').length > 0;
144144
}
145145

146146
private handleEvent(filepath: string) {

packages/jest-message-util/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@jest/types": "^24.9.0",
1919
"@types/stack-utils": "^1.0.1",
2020
"chalk": "^2.0.1",
21-
"micromatch": "^3.1.10",
21+
"micromatch": "^4.0.2",
2222
"slash": "^2.0.0",
2323
"stack-utils": "^1.0.1"
2424
},

packages/jest-message-util/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from 'path';
1010
import {Config} from '@jest/types';
1111
import {AssertionResult, SerializableError} from '@jest/test-result';
1212
import chalk from 'chalk';
13-
import {some as micromatchSome} from 'micromatch';
13+
import micromatch from 'micromatch';
1414
import slash from 'slash';
1515
import {codeFrameColumns} from '@babel/code-frame';
1616
import StackUtils from 'stack-utils';
@@ -216,7 +216,7 @@ const formatPaths = (
216216
if (
217217
(config.testMatch &&
218218
config.testMatch.length &&
219-
micromatchSome(filePath, config.testMatch)) ||
219+
micromatch([filePath], config.testMatch).length > 0) ||
220220
filePath === relativeTestPath
221221
) {
222222
filePath = chalk.reset.cyan(filePath);

packages/jest-transform/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"jest-haste-map": "^24.9.0",
2020
"jest-regex-util": "^24.9.0",
2121
"jest-util": "^24.9.0",
22-
"micromatch": "^3.1.10",
22+
"micromatch": "^4.0.2",
2323
"pirates": "^4.0.1",
2424
"realpath-native": "^1.1.0",
2525
"slash": "^2.0.0",

packages/jest-transform/src/shouldInstrument.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as path from 'path';
99
import {Config} from '@jest/types';
1010
import {escapePathForRegex} from 'jest-regex-util';
1111
import {replacePathSepForGlob} from 'jest-util';
12-
import {any as micromatchAny, some as micromatchSome} from 'micromatch';
12+
import micromatch, {any as micromatchAny} from 'micromatch';
1313
import {ShouldInstrumentOptions} from './types';
1414

1515
const MOCKS_PATTERN = new RegExp(
@@ -39,7 +39,9 @@ export default function shouldInstrument(
3939
return false;
4040
}
4141

42-
if (micromatchSome(replacePathSepForGlob(filename), config.testMatch)) {
42+
if (
43+
micromatch([replacePathSepForGlob(filename)], config.testMatch).length
44+
) {
4345
return false;
4446
}
4547
}
@@ -57,10 +59,10 @@ export default function shouldInstrument(
5759
// still cover if `only` is specified
5860
!options.collectCoverageOnlyFrom &&
5961
options.collectCoverageFrom &&
60-
!micromatchSome(
61-
replacePathSepForGlob(path.relative(config.rootDir, filename)),
62+
micromatch(
63+
[replacePathSepForGlob(path.relative(config.rootDir, filename))],
6264
options.collectCoverageFrom,
63-
)
65+
).length === 0
6466
) {
6567
return false;
6668
}

yarn.lock

+11-3
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ anymatch@^2.0.0:
30093009
micromatch "^3.1.4"
30103010
normalize-path "^2.1.1"
30113011

3012-
anymatch@^3.0.1:
3012+
anymatch@^3.0.1, anymatch@^3.0.3:
30133013
version "3.0.3"
30143014
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.0.3.tgz#2fb624fe0e84bccab00afee3d0006ed310f22f09"
30153015
integrity sha512-c6IvoeBECQlMVuYUjSwimnhmztImpErfxJzWZhIQinIvQWoGOnB0dLIgifbPHQt5heS6mNlaZG16f06H3C8t1g==
@@ -3728,7 +3728,7 @@ braces@^2.3.1, braces@^2.3.2:
37283728
split-string "^3.0.2"
37293729
to-regex "^3.0.1"
37303730

3731-
braces@^3.0.2:
3731+
braces@^3.0.1, braces@^3.0.2:
37323732
version "3.0.2"
37333733
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
37343734
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
@@ -9614,6 +9614,14 @@ micromatch@^3.1.10, micromatch@^3.1.4, micromatch@^3.1.8:
96149614
snapdragon "^0.8.1"
96159615
to-regex "^3.0.2"
96169616

9617+
micromatch@^4.0.2:
9618+
version "4.0.2"
9619+
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.2.tgz#4fcb0999bf9fbc2fcbdd212f6d629b9a56c39259"
9620+
integrity sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==
9621+
dependencies:
9622+
braces "^3.0.1"
9623+
picomatch "^2.0.5"
9624+
96179625
miller-rabin@^4.0.0:
96189626
version "4.0.1"
96199627
resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.1.tgz#f080351c865b0dc562a8462966daa53543c78a4d"
@@ -10864,7 +10872,7 @@ performance-now@^2.1.0:
1086410872
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
1086510873
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
1086610874

10867-
picomatch@^2.0.4:
10875+
picomatch@^2.0.4, picomatch@^2.0.5:
1086810876
version "2.0.7"
1086910877
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.0.7.tgz#514169d8c7cd0bdbeecc8a2609e34a7163de69f6"
1087010878
integrity sha512-oLHIdio3tZ0qH76NybpeneBhYVj0QFTfXEFTc/B3zKQspYfYYkWYgFsmzo+4kvId/bQRcNkVeguI3y+CD22BtA==

0 commit comments

Comments
 (0)