-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Created matchAll function wrapper for minimatch so dir globs are…
… properly ignored (#432)
- Loading branch information
1 parent
964fa6e
commit dda6f13
Showing
5 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as assert from "assert"; | ||
import { matchAll, match } from "../util/globMatch"; | ||
|
||
suite("Glob match testing", () => { | ||
test("Test single match", () => { | ||
const matcher = match("**/*.js"); | ||
|
||
assert.ok(matcher.match("test/tester.js")); | ||
assert.ok(matcher.match("tester/testing/test/tester.js")); | ||
}); | ||
|
||
test("Test Multiple Matches", () => { | ||
const patterns = ["**/.git", "**/.hg", "**/vendor", "**/node_modules"]; | ||
|
||
assert.strictEqual(matchAll(".git/test", patterns), false); | ||
assert.strictEqual(matchAll(".hg/test", patterns), false); | ||
assert.strictEqual(matchAll("vendor/test", patterns), false); | ||
assert.strictEqual( | ||
matchAll("project/test/node_modules/test/index.js", patterns), | ||
false | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as minimatch from "minimatch"; | ||
|
||
export function matchAll( | ||
path: string, | ||
patterns: string[], | ||
opts: minimatch.IOptions = {} | ||
): boolean { | ||
let match = false; | ||
|
||
patterns.forEach(pattern => { | ||
const isExclusion = pattern[0] === "!"; | ||
|
||
// If we've got a match, only re-test for exclusions. | ||
// if we don't have a match, only re-test for inclusions. | ||
if (match !== isExclusion) { | ||
return; | ||
} | ||
|
||
match = minimatch(path, pattern, opts); | ||
}); | ||
|
||
return match; | ||
} | ||
|
||
export function match(pattern: string) { | ||
return new minimatch.Minimatch(pattern); | ||
} |