Skip to content

Commit c8af395

Browse files
fix: separate glob for watching (#22)
1 parent 01a0413 commit c8af395

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ export class Context {
2525
public readonly viteConfig: ResolvedConfig,
2626
) {
2727
this.options = resolveOptions(options, viteConfig)
28-
const { globs, dirs } = this.options
28+
const { watchGlobs, dirs } = this.options
2929

3030
if (viteConfig.command === 'serve') {
3131
// TODO: use vite's watcher instead
3232
chokidar.watch(dirs, { ignoreInitial: true })
3333
.on('unlink', (path) => {
34-
if (matchGlobs(path, globs)) {
34+
if (matchGlobs(path, watchGlobs)) {
3535
this.removeComponents(path)
3636
this.onUpdate(path)
3737
}
3838
})
3939
.on('add', (path) => {
40-
if (matchGlobs(path, globs)) {
40+
if (matchGlobs(path, watchGlobs)) {
4141
this.addComponents(path)
4242
this.onUpdate(path)
4343
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Required<Options>,
7676
extensions: string[]
7777
dirs: string[]
7878
globs: string[]
79+
watchGlobs: string[]
7980
}
8081

8182
export interface ComponentInfo {

src/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,18 @@ export function resolveOptions(options: Options, viteConfig: ResolvedConfig): Re
8484

8585
resolved.globs = toArray(resolved.dirs).map(i =>
8686
resolved.deep
87-
? join(i, `/**/*.${extsGlob}`)
88-
: join(i, `/*.${extsGlob}`),
87+
? `${i}/**/*.${extsGlob}`
88+
: `${i}/*.${extsGlob}`,
8989
)
9090

9191
resolved.dirs = toArray(resolved.dirs).map(i => resolve(viteConfig.root, i))
9292

93+
resolved.watchGlobs = toArray(resolved.dirs).map(i =>
94+
resolved.deep
95+
? join(i, `/**/*.${extsGlob}`)
96+
: join(i, `/*.${extsGlob}`),
97+
)
98+
9399
if (!resolved.extensions.length)
94100
throw new Error('[vite-plugin-components] extensions are required to search for components')
95101

0 commit comments

Comments
 (0)