Skip to content

Commit

Permalink
feat(nuxt): add metadata to auto import
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 20, 2023
1 parent e8aafe0 commit eee12d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
11 changes: 8 additions & 3 deletions packages/nuxt/index.ts
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from 'url'
import { isPackageExists } from 'local-pkg'
import { defineNuxtModule } from '@nuxt/kit'
import { metadata } from '@vueuse/metadata'
import type { Import } from 'unimport'
import type { Import, Preset } from 'unimport'

const _dirname = dirname(fileURLToPath(import.meta.url))

Expand Down Expand Up @@ -100,8 +100,8 @@ export default defineNuxtModule<VueUseNuxtOptions>({

if (options.autoImports) {
// auto import
nuxt.hook('imports:sources', (sources: any[]) => {
if (sources.find(i => fullPackages.includes(i.from)))
nuxt.hook('imports:sources', (sources: (Import | Preset)[]) => {
if (sources.find(i => fullPackages.includes((i as Import).from)))
return

metadata.functions.forEach((i) => {
Expand All @@ -126,6 +126,11 @@ export default defineNuxtModule<VueUseNuxtOptions>({
name: n,
as: n,
priority: -1,
meta: {
description: i.description,
docsUrl: i.docs,
category: i.category,
},
}))
})
.filter(i => i.name.length >= 4 && !disabledFunctions.includes(i.name))
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/package.json
Expand Up @@ -45,6 +45,6 @@
},
"devDependencies": {
"@nuxt/schema": "^3.0.0",
"unimport": "^1.1.0"
"unimport": "^1.3.0"
}
}
30 changes: 21 additions & 9 deletions pnpm-lock.yaml

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

0 comments on commit eee12d6

Please sign in to comment.