Skip to content

Commit

Permalink
fix: scanDirs when nested modules in dirs update (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddosakura committed Feb 17, 2023
1 parent 6114023 commit 0e3e3d7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"@rollup/pluginutils": "^5.0.2",
"local-pkg": "^0.4.3",
"magic-string": "^0.27.0",
"minimatch": "^6.2.0",
"unimport": "^2.2.4",
"unplugin": "^1.0.1"
},
Expand Down
2 changes: 2 additions & 0 deletions playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import HelloWorld from './HelloWorld.vue'
ElMessage.warning('Test')
const foo = useFoo()
const bar = useBar()
</script>

<script lang="ts">
Expand All @@ -18,6 +19,7 @@ export default defineComponent({
<template>
<HelloWorld msg="hi" />
<pre>{{ foo }}</pre>
<pre>{{ bar }}</pre>
<pre>{{ FOOBAR }}</pre>
<div v-loading="false">
<ElButton>Hello</ElButton>
Expand Down
3 changes: 3 additions & 0 deletions playground/composables/nested/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function useBar() {
return 'bar from ./composables/nested/'
}
2 changes: 1 addition & 1 deletion playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
ElementPlusResolver(),
],
dirs: [
'./composables',
'./composables/**',
],
vueTemplate: true,
cache: true,
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/core/unplugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import minimatch from 'minimatch'
import { slash } from '@antfu/utils'
import { createUnplugin } from 'unplugin'
import type { Options } from '../types'
import { createContext } from './ctx'
Expand Down Expand Up @@ -25,7 +27,7 @@ export default createUnplugin<Options>((options) => {
},
vite: {
async handleHotUpdate({ file }) {
if (ctx.dirs?.some(dir => file.startsWith(dir)))
if (ctx.dirs?.some(glob => minimatch(slash(file), glob)))
await ctx.scanDirs()
},
async configResolved(config) {
Expand Down

0 comments on commit 0e3e3d7

Please sign in to comment.