diff --git a/package.json b/package.json index 2ce3d6be52db..6ad7df4a3a37 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "jest-watch-typeahead": "^0.6.0", "jquery": "^3.2.1", "lerna": "^4.0.0", - "micromatch": "^4.0.2", + "micromatch": "^4.0.4", "mlh-tsd": "^0.14.1", "mock-fs": "^4.4.1", "node-notifier": "^9.0.0", diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 052609eb9dde..e6a957989452 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -39,14 +39,14 @@ "jest-resolve": "^27.0.0-next.7", "jest-util": "^27.0.0-next.7", "jest-validate": "^27.0.0-next.7", - "micromatch": "^4.0.2", + "micromatch": "^4.0.4", "pretty-format": "^27.0.0-next.7" }, "devDependencies": { "@types/babel__core": "^7.0.4", "@types/glob": "^7.1.1", "@types/graceful-fs": "^4.1.3", - "@types/micromatch": "^4.0.0", + "@types/micromatch": "^4.0.1", "jest-snapshot-serializer-raw": "^1.1.0", "strip-ansi": "^6.0.0", "ts-node": "^9.0.0", diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index 02c5f481e282..49ce1c4e124b 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -33,7 +33,7 @@ "jest-util": "^27.0.0-next.7", "jest-validate": "^27.0.0-next.7", "jest-watcher": "^27.0.0-next.7", - "micromatch": "^4.0.2", + "micromatch": "^4.0.4", "p-each-series": "^2.1.0", "rimraf": "^3.0.0", "slash": "^3.0.0", @@ -44,7 +44,7 @@ "@jest/test-utils": "^27.0.0-next.7", "@types/exit": "^0.1.30", "@types/graceful-fs": "^4.1.2", - "@types/micromatch": "^4.0.0", + "@types/micromatch": "^4.0.1", "@types/rimraf": "^3.0.0", "jest-snapshot-serializer-raw": "^1.1.0" }, diff --git a/packages/jest-haste-map/package.json b/packages/jest-haste-map/package.json index e49b9007df11..51fe809fcbef 100644 --- a/packages/jest-haste-map/package.json +++ b/packages/jest-haste-map/package.json @@ -24,14 +24,14 @@ "jest-serializer": "^27.0.0-next.0", "jest-util": "^27.0.0-next.7", "jest-worker": "^27.0.0-next.7", - "micromatch": "^4.0.2", + "micromatch": "^4.0.4", "walker": "^1.0.7" }, "devDependencies": { "@jest/test-utils": "^27.0.0-next.7", "@types/anymatch": "^1.3.1", "@types/fb-watchman": "^2.0.0", - "@types/micromatch": "^4.0.0", + "@types/micromatch": "^4.0.1", "jest-snapshot-serializer-raw": "^1.1.0", "slash": "^3.0.0" }, diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index c63990882e3a..c6cfff81b59a 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -22,7 +22,7 @@ "@types/stack-utils": "^2.0.0", "chalk": "^4.0.0", "graceful-fs": "^4.2.4", - "micromatch": "^4.0.2", + "micromatch": "^4.0.4", "pretty-format": "^27.0.0-next.7", "slash": "^3.0.0", "stack-utils": "^2.0.3" @@ -30,7 +30,7 @@ "devDependencies": { "@types/babel__code-frame": "^7.0.0", "@types/graceful-fs": "^4.1.3", - "@types/micromatch": "^4.0.0" + "@types/micromatch": "^4.0.1" }, "publishConfig": { "access": "public" diff --git a/packages/jest-transform/package.json b/packages/jest-transform/package.json index 91812127fd10..85788e4ab580 100644 --- a/packages/jest-transform/package.json +++ b/packages/jest-transform/package.json @@ -24,7 +24,7 @@ "jest-haste-map": "^27.0.0-next.7", "jest-regex-util": "^27.0.0-next.0", "jest-util": "^27.0.0-next.7", - "micromatch": "^4.0.2", + "micromatch": "^4.0.4", "pirates": "^4.0.1", "slash": "^3.0.0", "source-map": "^0.6.1", @@ -36,7 +36,7 @@ "@types/convert-source-map": "^1.5.1", "@types/fast-json-stable-stringify": "^2.0.0", "@types/graceful-fs": "^4.1.2", - "@types/micromatch": "^4.0.0", + "@types/micromatch": "^4.0.1", "@types/write-file-atomic": "^3.0.0", "dedent": "^0.7.0", "jest-snapshot-serializer-raw": "^1.1.0" diff --git a/packages/jest-util/package.json b/packages/jest-util/package.json index f066cee9867f..3ce1a490e733 100644 --- a/packages/jest-util/package.json +++ b/packages/jest-util/package.json @@ -19,12 +19,13 @@ "chalk": "^4.0.0", "graceful-fs": "^4.2.4", "is-ci": "^3.0.0", - "micromatch": "^4.0.2" + "picomatch": "^2.2.3" }, "devDependencies": { "@types/graceful-fs": "^4.1.2", "@types/is-ci": "^2.0.0", - "@types/micromatch": "^4.0.0" + "@types/micromatch": "^4.0.1", + "@types/picomatch": "^2.2.2" }, "engines": { "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" diff --git a/packages/jest-util/src/__tests__/globsToMatcher.test.ts b/packages/jest-util/src/__tests__/globsToMatcher.test.ts index f676d7ae0360..272996da2d31 100644 --- a/packages/jest-util/src/__tests__/globsToMatcher.test.ts +++ b/packages/jest-util/src/__tests__/globsToMatcher.test.ts @@ -70,3 +70,29 @@ it('works like micromatch with empty globs', () => { micromatch(['some-module.test.js'], globs).length > 0, ); }); + +it('works like micromatch with pure negated extglobs', () => { + const globs = ['**/*.js', '!(some-module.test.js)']; + const matcher = globsToMatcher(globs); + + expect(matcher('some-module.js')).toBe( + micromatch(['some-module.js'], globs).length > 0, + ); + + expect(matcher('some-module.test.js')).toBe( + micromatch(['some-module.test.js'], globs).length > 0, + ); +}); + +it('works like micromatch with negated extglobs', () => { + const globs = ['**/*.js', '!(tests|coverage)/*.js']; + const matcher = globsToMatcher(globs); + + expect(matcher('some-module.js')).toBe( + micromatch(['some-module.js'], globs).length > 0, + ); + + expect(matcher('tests/some-module.test.js')).toBe( + micromatch(['tests/some-module.test.js'], globs).length > 0, + ); +}); diff --git a/packages/jest-util/src/globsToMatcher.ts b/packages/jest-util/src/globsToMatcher.ts index ad4285825efe..ceb8d62c3f07 100644 --- a/packages/jest-util/src/globsToMatcher.ts +++ b/packages/jest-util/src/globsToMatcher.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import micromatch = require('micromatch'); +import picomatch = require('picomatch'); import type {Config} from '@jest/types'; import replacePathSepForGlob from './replacePathSepForGlob'; @@ -16,15 +16,15 @@ const globsToMatchersMap = new Map< {isMatch: Matcher; negated: boolean} >(); -const micromatchOptions = {dot: true}; +const picomatchOptions = {dot: true}; /** * Converts a list of globs into a function that matches a path against the * globs. * - * Every time micromatch is called, it will parse the glob strings and turn - * them into regexp instances. Instead of calling micromatch repeatedly with - * the same globs, we can use this function which will build the micromatch + * Every time picomatch is called, it will parse the glob strings and turn + * them into regexp instances. Instead of calling picomatch repeatedly with + * the same globs, we can use this function which will build the picomatch * matchers ahead of time and then have an optimized path for determining * whether an individual path matches. * @@ -44,13 +44,13 @@ export default function globsToMatcher(globs: Array): Matcher { const matchers = globs.map(glob => { if (!globsToMatchersMap.has(glob)) { - // Matchers that are negated have different behavior than matchers that - // are not negated, so we need to store this information ahead of time. - const {negated} = micromatch.scan(glob, micromatchOptions); + const isMatch = picomatch(glob, picomatchOptions, true); const matcher = { - isMatch: micromatch.matcher(glob, micromatchOptions), - negated, + isMatch, + // Matchers that are negated have different behavior than matchers that + // are not negated, so we need to store this information ahead of time. + negated: isMatch.state.negated || !!isMatch.state.negatedExtglob, }; globsToMatchersMap.set(glob, matcher); diff --git a/yarn.lock b/yarn.lock index 7a76949be55b..0938f5bdd6f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2439,7 +2439,7 @@ __metadata: "@jest/types": ^27.0.0-next.7 "@types/exit": ^0.1.30 "@types/graceful-fs": ^4.1.2 - "@types/micromatch": ^4.0.0 + "@types/micromatch": ^4.0.1 "@types/node": "*" "@types/rimraf": ^3.0.0 ansi-escapes: ^4.2.1 @@ -2461,7 +2461,7 @@ __metadata: jest-util: ^27.0.0-next.7 jest-validate: ^27.0.0-next.7 jest-watcher: ^27.0.0-next.7 - micromatch: ^4.0.2 + micromatch: ^4.0.4 p-each-series: ^2.1.0 rimraf: ^3.0.0 slash: ^3.0.0 @@ -2581,7 +2581,7 @@ __metadata: jest-watch-typeahead: ^0.6.0 jquery: ^3.2.1 lerna: ^4.0.0 - micromatch: ^4.0.2 + micromatch: ^4.0.4 mlh-tsd: ^0.14.1 mock-fs: ^4.4.1 node-notifier: ^9.0.0 @@ -2727,7 +2727,7 @@ __metadata: "@types/convert-source-map": ^1.5.1 "@types/fast-json-stable-stringify": ^2.0.0 "@types/graceful-fs": ^4.1.2 - "@types/micromatch": ^4.0.0 + "@types/micromatch": ^4.0.1 "@types/write-file-atomic": ^3.0.0 babel-plugin-istanbul: ^6.0.0 chalk: ^4.0.0 @@ -2739,7 +2739,7 @@ __metadata: jest-regex-util: ^27.0.0-next.0 jest-snapshot-serializer-raw: ^1.1.0 jest-util: ^27.0.0-next.7 - micromatch: ^4.0.2 + micromatch: ^4.0.4 pirates: ^4.0.1 slash: ^3.0.0 source-map: ^0.6.1 @@ -4690,7 +4690,7 @@ __metadata: languageName: node linkType: hard -"@types/micromatch@npm:^4.0.0": +"@types/micromatch@npm:^4.0.1": version: 4.0.1 resolution: "@types/micromatch@npm:4.0.1" dependencies: @@ -4780,6 +4780,13 @@ __metadata: languageName: node linkType: hard +"@types/picomatch@npm:^2.2.2": + version: 2.2.2 + resolution: "@types/picomatch@npm:2.2.2" + checksum: f55b30a9c532bd701f502132127c905739acd53cd5c0e5b3ef4b6bdbe7387c028f44cd3e8dd5b6df584ff57d0ca0dea22c2433b2fe137265a87c4893aefa8a61 + languageName: node + linkType: hard + "@types/prettier@npm:*, @types/prettier@npm:^2.0.0, @types/prettier@npm:^2.1.5": version: 2.2.2 resolution: "@types/prettier@npm:2.2.2" @@ -13450,7 +13457,7 @@ fsevents@^1.2.7: "@types/babel__core": ^7.0.4 "@types/glob": ^7.1.1 "@types/graceful-fs": ^4.1.3 - "@types/micromatch": ^4.0.0 + "@types/micromatch": ^4.0.1 babel-jest: ^27.0.0-next.7 chalk: ^4.0.0 deepmerge: ^4.2.2 @@ -13466,7 +13473,7 @@ fsevents@^1.2.7: jest-snapshot-serializer-raw: ^1.1.0 jest-util: ^27.0.0-next.7 jest-validate: ^27.0.0-next.7 - micromatch: ^4.0.2 + micromatch: ^4.0.4 pretty-format: ^27.0.0-next.7 strip-ansi: ^6.0.0 ts-node: ^9.0.0 @@ -13593,7 +13600,7 @@ fsevents@^1.2.7: "@types/anymatch": ^1.3.1 "@types/fb-watchman": ^2.0.0 "@types/graceful-fs": ^4.1.2 - "@types/micromatch": ^4.0.0 + "@types/micromatch": ^4.0.1 "@types/node": "*" anymatch: ^3.0.3 fb-watchman: ^2.0.0 @@ -13604,7 +13611,7 @@ fsevents@^1.2.7: jest-snapshot-serializer-raw: ^1.1.0 jest-util: ^27.0.0-next.7 jest-worker: ^27.0.0-next.7 - micromatch: ^4.0.2 + micromatch: ^4.0.4 slash: ^3.0.0 walker: ^1.0.7 dependenciesMeta: @@ -13709,11 +13716,11 @@ fsevents@^1.2.7: "@jest/types": ^27.0.0-next.7 "@types/babel__code-frame": ^7.0.0 "@types/graceful-fs": ^4.1.3 - "@types/micromatch": ^4.0.0 + "@types/micromatch": ^4.0.1 "@types/stack-utils": ^2.0.0 chalk: ^4.0.0 graceful-fs: ^4.2.4 - micromatch: ^4.0.2 + micromatch: ^4.0.4 pretty-format: ^27.0.0-next.7 slash: ^3.0.0 stack-utils: ^2.0.3 @@ -14008,12 +14015,13 @@ fsevents@^1.2.7: "@jest/types": ^27.0.0-next.7 "@types/graceful-fs": ^4.1.2 "@types/is-ci": ^2.0.0 - "@types/micromatch": ^4.0.0 + "@types/micromatch": ^4.0.1 "@types/node": "*" + "@types/picomatch": ^2.2.2 chalk: ^4.0.0 graceful-fs: ^4.2.4 is-ci: ^3.0.0 - micromatch: ^4.0.2 + picomatch: ^2.2.3 languageName: unknown linkType: soft @@ -15862,13 +15870,13 @@ fsevents@^1.2.7: languageName: node linkType: hard -"micromatch@npm:^4.0.2": - version: 4.0.2 - resolution: "micromatch@npm:4.0.2" +"micromatch@npm:^4.0.2, micromatch@npm:^4.0.4": + version: 4.0.4 + resolution: "micromatch@npm:4.0.4" dependencies: braces: ^3.0.1 - picomatch: ^2.0.5 - checksum: 0cb0e11d647cbb65e398a0a8a1340a7fb751ae2722346219c435704cfac8b3275a94a6464236fe867f52ad46a24046d3bc4ac11b3d21ddb73bc44e27cf1e4904 + picomatch: ^2.2.3 + checksum: bc522ad93c086aa176f50fea2dc8060a8f7d7a621c811cf9ba02a1912577cc100190508166d721231465f10a575a40ec8a1bffc23bbc2c0108fcbf02e4be04ed languageName: node linkType: hard @@ -17859,10 +17867,10 @@ fsevents@^1.2.7: languageName: node linkType: hard -"picomatch@npm:^2.0.4, picomatch@npm:^2.0.5, picomatch@npm:^2.2.1, picomatch@npm:^2.2.2": - version: 2.2.2 - resolution: "picomatch@npm:2.2.2" - checksum: 20fa75e0a58b39d83425b3db68744d5f6f361fd4fd66ec7745d884036d502abba0d553a637703af79939b844164b13e60eea339ccb043d7fbd74c3da2592b864 +"picomatch@npm:^2.0.4, picomatch@npm:^2.2.1, picomatch@npm:^2.2.2, picomatch@npm:^2.2.3": + version: 2.2.3 + resolution: "picomatch@npm:2.2.3" + checksum: f8c9323bc3b21ff448e81dd32277135d781abae5d53a1415d69a4ce6317a2c11404d449c550110b8fa402c07d5e80ff0e2657f263a312517cc809e9010d25791 languageName: node linkType: hard