|
1 | | -import { promisify } from 'util' |
2 | | - |
3 | | -import globFunction from 'glob' |
4 | | -import { minimatch as minimatchFunction, MinimatchOptions } from 'minimatch' |
| 1 | +import { glob as originalGlob, type GlobOptions } from 'glob' |
| 2 | +import { minimatch as minimatchFunction, type MinimatchOptions } from 'minimatch' |
5 | 3 | import normalizePath from 'normalize-path' |
6 | 4 |
|
7 | | -const pGlob = promisify(globFunction) |
| 5 | +// We don't use this. Specifying that we don't makes typing easier, since otherwise `glob` returns |
| 6 | +// either `string[]` or `Path[]` depending on this passed option. |
| 7 | +type Options = Omit<GlobOptions, 'withFileTypes'> |
8 | 8 |
|
9 | 9 | /** |
10 | 10 | * Both glob and minimatch only support unix style slashes in patterns |
11 | | - * For this reason we wrap them and ensure all patters are always unixified |
| 11 | + * For this reason we wrap them and ensure all patterns are always unixified |
12 | 12 | * We use `normalize-path` here instead of `unixify` because we do not want to remove drive letters |
13 | 13 | */ |
14 | | - |
15 | | -export const glob = function (pattern: string, options: globFunction.IOptions): Promise<string[]> { |
16 | | - let normalizedIgnore |
| 14 | +export const glob = function (pattern: string, options: Options): Promise<string[]> { |
| 15 | + let normalizedIgnore: string | undefined |
17 | 16 |
|
18 | 17 | if (options.ignore) { |
19 | | - normalizedIgnore = |
20 | | - typeof options.ignore === 'string' |
21 | | - ? normalizePath(options.ignore) |
22 | | - : options.ignore.map((expression) => normalizePath(expression)) |
| 18 | + if (typeof options.ignore === 'string') { |
| 19 | + normalizedIgnore = normalizePath(options.ignore) |
| 20 | + } else if (Array.isArray(options.ignore)) { |
| 21 | + options.ignore.map((expression) => normalizePath(expression)) |
| 22 | + } else { |
| 23 | + throw new Error('Custom glob ignore is not supported') |
| 24 | + } |
23 | 25 | } |
24 | 26 |
|
25 | | - return pGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore }) |
| 27 | + return originalGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore }) |
26 | 28 | } |
27 | 29 |
|
28 | 30 | export const minimatch = function (target: string, pattern: string, options?: MinimatchOptions): boolean { |
|
0 commit comments