Skip to content

Commit

Permalink
fix: correct auto-imports (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 31, 2022
1 parent 75e046f commit 2b0045e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
12 changes: 0 additions & 12 deletions src/auto-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as CompositionApi from '@vue/composition-api'
import type { Preset } from 'unimport'
import autoImports from './auto-imports/module'

const UnsupportedImports = new Set(['useAsyncData', 'useFetch', 'useError', 'throwError', 'clearError', 'defineNuxtLink', 'useActiveRoute'])
const CapiHelpers = new Set(Object.keys(CompositionApi))

export function setupAutoImports () {
Expand All @@ -17,17 +16,6 @@ export function setupAutoImports () {
nuxt.hook('autoImports:sources', (presets) => {
const vuePreset = presets.find(p => p.from === 'vue')
if (vuePreset) { vuePreset.disabled = true }

const appPreset = presets.find(p => p.from === '#app')
if (!appPreset) { return }

for (const [index, i] of Object.entries(appPreset.imports).reverse()) {
if (typeof i === 'string' && UnsupportedImports.has(i)) {
appPreset.imports.splice(Number(index), 1)
}
}

appPreset.imports.push('useNuxt2Meta')
})

nuxt.hook('modules:done', () => installModule(autoImports, { presets: bridgePresets }))
Expand Down
10 changes: 2 additions & 8 deletions src/auto-imports/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const commonPresets: Preset[] = [
}),
// vue-demi (mocked)
defineUnimportPreset({
from: 'vue-demi',
from: '#app',
imports: [
'isVue2',
'isVue3'
Expand All @@ -22,30 +22,24 @@ export const commonPresets: Preset[] = [
export const appPreset = defineUnimportPreset({
from: '#app',
imports: [
'useAsyncData',
'useLazyAsyncData',
'refreshNuxtData',
'defineNuxtComponent',
'useNuxtApp',
'defineNuxtPlugin',
'useRuntimeConfig',
'useState',
'useFetch',
'useLazyFetch',
'useCookie',
'useRequestHeaders',
'useRequestEvent',
'useRouter',
'useRoute',
'useActiveRoute',
'defineNuxtRouteMiddleware',
'navigateTo',
'abortNavigation',
'addRouteMiddleware',
'throwError',
'clearError',
'useError',
'defineNuxtLink'
'useNuxt2Meta'
]
})

Expand Down
4 changes: 3 additions & 1 deletion src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const setupMeta = async (opts: SetupMetaOptions) => {
if (opts.needsExplicitEnable) {
const metaPath = addTemplate({
filename: 'meta.mjs',
getContents: () => `export const useHead = () => console.warn('${msgPrefix} To enable experimental \`useHead\` support, set \`bridge.meta\` to \`true\` in your \`nuxt.config\`. ${checkDocsMsg}')`
getContents: () => ['useHead', 'useMeta'].map(fnName =>
`export const ${fnName} = () => console.warn('${msgPrefix} To enable experimental \`useHead\` support, set \`bridge.meta\` to \`true\` in your \`nuxt.config\`. ${checkDocsMsg}')`)
.join('\n')
})
nuxt.options.alias['#head'] = metaPath.dst
return
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useNuxtApp } from './app'
export { useLazyAsyncData, refreshNuxtData } from './asyncData'
export { useLazyFetch } from './fetch'
export { useCookie } from './cookie'
export { useRequestHeaders } from './ssr'
export { useRequestHeaders, useRequestEvent } from './ssr'

export * from '@vue/composition-api'

Expand Down

0 comments on commit 2b0045e

Please sign in to comment.