@@ -14,7 +14,6 @@ const debug = {
1414
1515export class Context {
1616 readonly options : ResolvedOptions
17- readonly globs : string [ ]
1817
1918 private _componentPaths = new Set < string > ( )
2019 private _componentNameMap : Record < string , ComponentInfo > = { }
@@ -26,38 +25,19 @@ export class Context {
2625 public readonly viteConfig : ResolvedConfig ,
2726 ) {
2827 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
4929
5030 if ( viteConfig . command === 'serve' ) {
5131 // TODO: use vite's watcher instead
52- chokidar . watch ( watchDirs , { ignoreInitial : true } )
32+ chokidar . watch ( dirs , { ignoreInitial : true } )
5333 . on ( 'unlink' , ( path ) => {
54- if ( matchGlobs ( path , watchGlobs ) ) {
34+ if ( matchGlobs ( path , globs ) ) {
5535 this . removeComponents ( path )
5636 this . onUpdate ( path )
5737 }
5838 } )
5939 . on ( 'add' , ( path ) => {
60- if ( matchGlobs ( path , watchGlobs ) ) {
40+ if ( matchGlobs ( path , globs ) ) {
6141 this . addComponents ( path )
6242 this . onUpdate ( path )
6343 }
0 commit comments