1
- import { join , parse , resolve } from 'path'
1
+ import { join , parse } from 'path'
2
2
import minimatch from 'minimatch'
3
3
import { ResolvedConfig } from 'vite'
4
4
import { ComponentInfo , ResolvedOptions , Options } from './types'
@@ -10,6 +10,10 @@ export interface ResolveComponent {
10
10
namespace ?: string
11
11
}
12
12
13
+ export function slash ( str : string ) {
14
+ return str . replace ( / \\ / g, '/' )
15
+ }
16
+
13
17
export function pascalCase ( str : string ) {
14
18
return capitalize ( camelCase ( str ) )
15
19
}
@@ -58,7 +62,7 @@ export function isEmpty(value: any) {
58
62
59
63
export function matchGlobs ( filepath : string , globs : string [ ] ) {
60
64
for ( const glob of globs ) {
61
- if ( minimatch ( filepath , glob ) )
65
+ if ( minimatch ( slash ( filepath ) , glob ) )
62
66
return true
63
67
}
64
68
return false
@@ -82,18 +86,12 @@ export function resolveOptions(options: Options, viteConfig: ResolvedConfig): Re
82
86
? resolved . extensions
83
87
: `{${ resolved . extensions . join ( ',' ) } }`
84
88
85
- resolved . globs = toArray ( resolved . dirs ) . map ( i =>
86
- resolved . deep
87
- ? `${ i } /**/*.${ extsGlob } `
88
- : `${ i } /*.${ extsGlob } ` ,
89
- )
90
-
91
- resolved . dirs = toArray ( resolved . dirs ) . map ( i => resolve ( viteConfig . root , i ) )
89
+ resolved . dirs = toArray ( resolved . dirs )
92
90
93
- resolved . watchGlobs = toArray ( resolved . dirs ) . map ( i =>
91
+ resolved . globs = resolved . dirs . map ( i =>
94
92
resolved . deep
95
- ? join ( i , `/ **/*.${ extsGlob } ` )
96
- : join ( i , `/ *.${ extsGlob } ` ) ,
93
+ ? slash ( join ( i , `**/*.${ extsGlob } ` ) )
94
+ : slash ( join ( i , `*.${ extsGlob } ` ) ) ,
97
95
)
98
96
99
97
if ( ! resolved . extensions . length )
@@ -110,7 +108,7 @@ export function getNameFromFilePath(filePath: string, options: ResolvedOptions):
110
108
let strippedPath = ''
111
109
112
110
// remove include directories from filepath
113
- for ( const dir of toArray ( dirs ) ) {
111
+ for ( const dir of dirs ) {
114
112
if ( parsedFilePath . dir . startsWith ( dir ) ) {
115
113
strippedPath = parsedFilePath . dir . slice ( dir . length )
116
114
break
0 commit comments