@@ -3,26 +3,30 @@ import { Minimatch, IMinimatch } from 'minimatch';
33
44const unix = Path . sep === '/' ;
55
6+ function normalize ( pattern : string ) {
7+ if ( pattern . startsWith ( '!' ) || pattern . startsWith ( '#' ) ) {
8+ return pattern [ 0 ] + normalize ( pattern . substr ( 1 ) ) ;
9+ }
10+
11+ if ( unix ) { pattern = pattern . replace ( / [ \\ ] / g, '/' ) . replace ( / ^ \w : / , '' ) ; }
12+
13+ // pattern paths not starting with '**' are resolved even if it is an
14+ // absolute path, to ensure correct format for the current OS
15+ if ( pattern . substr ( 0 , 2 ) !== '**' ) {
16+ pattern = Path . resolve ( pattern ) ;
17+ }
18+
19+ // On Windows we transform `\` to `/` to unify the way paths are intepreted
20+ if ( ! unix ) { pattern = pattern . replace ( / [ \\ ] / g, '/' ) ; }
21+
22+ return pattern ;
23+ }
24+
625/**
726 * Convert array of glob patterns to array of minimatch instances.
827 *
928 * Handle a few Windows-Unix path gotchas.
1029 */
1130export function createMinimatch ( patterns : string [ ] ) : IMinimatch [ ] {
12- return patterns . map ( ( pattern : string ) : IMinimatch => {
13- // Ensure correct pathing on unix, by transforming `\` to `/` and removing any `X:/` from the path
14- if ( unix ) { pattern = pattern . replace ( / [ \\ ] / g, '/' ) . replace ( / ^ \w : / , '' ) ; }
15-
16- // pattern paths not starting with '**' are resolved even if it is an
17- // absolute path, to ensure correct format for the current OS
18- if ( pattern . substr ( 0 , 2 ) !== '**' ) {
19- pattern = Path . resolve ( pattern ) ;
20- }
21-
22- // On Windows we transform `\` to `/` to unify the way paths are intepreted
23- if ( ! unix ) { pattern = pattern . replace ( / [ \\ ] / g, '/' ) ; }
24-
25- // Unify the path slashes before creating the minimatch, for more reliable matching
26- return new Minimatch ( pattern , { dot : true } ) ;
27- } ) ;
31+ return patterns . map ( pattern => new Minimatch ( normalize ( pattern ) , { dot : true } ) ) ;
2832}
0 commit comments