1
- import { Glob , GlobOptions } from './glob.js'
1
+ import { Minimatch } from 'minimatch'
2
+ import { GlobOptions } from './glob.js'
2
3
3
4
/**
4
- * Return true if the patterns provided contain any magic
5
- * glob characters, given the options provided.
5
+ * Return true if the patterns provided contain any magic glob characters,
6
+ * given the options provided.
6
7
*
7
8
* Brace expansion is not considered "magic" unless the `magicalBraces` option
8
9
* is set, as brace expansion just turns one string into an array of strings.
9
10
* So a pattern like `'x{a,b}y'` would return `false`, because `'xay'` and
10
11
* `'xby'` both do not contain any magic glob characters, and it's treated the
11
- * same as if you had called it on `['xay', 'xby']`. When
12
- * `magicalBraces:true` is in the options, brace expansion _is_ treated as a
13
- * pattern having magic.
12
+ * same as if you had called it on `['xay', 'xby']`. When `magicalBraces:true`
13
+ * is in the options, brace expansion _is_ treated as a pattern having magic.
14
14
*/
15
15
export const hasMagic = (
16
16
pattern : string | string [ ] ,
@@ -19,10 +19,8 @@ export const hasMagic = (
19
19
if ( ! Array . isArray ( pattern ) ) {
20
20
pattern = [ pattern ]
21
21
}
22
- const length = pattern . length
23
- const g = new Glob ( pattern , options )
24
- if ( g . magicalBraces && g . patterns . length !== length ) {
25
- return true
22
+ for ( const p of pattern ) {
23
+ if ( new Minimatch ( p , options ) . hasMagic ( ) ) return true
26
24
}
27
- return g . patterns . some ( p => p . hasMagic ( ) )
25
+ return false
28
26
}
0 commit comments