@@ -14,7 +14,6 @@ const debug = {
14
14
15
15
export class Context {
16
16
readonly options : ResolvedOptions
17
- readonly globs : string [ ]
18
17
19
18
private _componentPaths = new Set < string > ( )
20
19
private _componentNameMap : Record < string , ComponentInfo > = { }
@@ -26,38 +25,19 @@ export class Context {
26
25
public readonly viteConfig : ResolvedConfig ,
27
26
) {
28
27
this . options = resolveOptions ( options , viteConfig )
29
- const { extensions, dirs, deep } = this . options
30
- const exts = toArray ( extensions )
31
-
32
- if ( ! exts . length )
33
- throw new Error ( '[vite-plugin-components] extensions are required to search for components' )
34
-
35
- const extsGlob = exts . length === 1 ? exts [ 0 ] : `{${ exts . join ( ',' ) } }`
36
-
37
- this . globs = toArray ( dirs ) . map ( i =>
38
- deep
39
- ? `${ i } /**/*.${ extsGlob } `
40
- : `${ i } /*.${ extsGlob } ` ,
41
- )
42
-
43
- const watchDirs = toArray ( dirs ) . map ( i => resolve ( viteConfig . root , i ) )
44
- const watchGlobs = toArray ( watchDirs ) . map ( i =>
45
- deep
46
- ? join ( i , `/**/*.${ extsGlob } ` )
47
- : join ( i , `/*.${ extsGlob } ` ) ,
48
- )
28
+ const { globs, dirs } = this . options
49
29
50
30
if ( viteConfig . command === 'serve' ) {
51
31
// TODO: use vite's watcher instead
52
- chokidar . watch ( watchDirs , { ignoreInitial : true } )
32
+ chokidar . watch ( dirs , { ignoreInitial : true } )
53
33
. on ( 'unlink' , ( path ) => {
54
- if ( matchGlobs ( path , watchGlobs ) ) {
34
+ if ( matchGlobs ( path , globs ) ) {
55
35
this . removeComponents ( path )
56
36
this . onUpdate ( path )
57
37
}
58
38
} )
59
39
. on ( 'add' , ( path ) => {
60
- if ( matchGlobs ( path , watchGlobs ) ) {
40
+ if ( matchGlobs ( path , globs ) ) {
61
41
this . addComponents ( path )
62
42
this . onUpdate ( path )
63
43
}
0 commit comments