From 2b0045e084956e6eee9e6b2b0c5c6c3be93b3794 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 31 May 2022 14:53:31 +0200 Subject: [PATCH] fix: correct auto-imports (#359) --- src/auto-imports.ts | 12 ------------ src/auto-imports/presets.ts | 10 ++-------- src/meta.ts | 4 +++- src/runtime/composables.ts | 2 +- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/auto-imports.ts b/src/auto-imports.ts index a1c02b74..1df4ad9d 100644 --- a/src/auto-imports.ts +++ b/src/auto-imports.ts @@ -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 () { @@ -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 })) diff --git a/src/auto-imports/presets.ts b/src/auto-imports/presets.ts index cf2fd30d..14235932 100644 --- a/src/auto-imports/presets.ts +++ b/src/auto-imports/presets.ts @@ -11,7 +11,7 @@ export const commonPresets: Preset[] = [ }), // vue-demi (mocked) defineUnimportPreset({ - from: 'vue-demi', + from: '#app', imports: [ 'isVue2', 'isVue3' @@ -22,7 +22,6 @@ export const commonPresets: Preset[] = [ export const appPreset = defineUnimportPreset({ from: '#app', imports: [ - 'useAsyncData', 'useLazyAsyncData', 'refreshNuxtData', 'defineNuxtComponent', @@ -30,22 +29,17 @@ export const appPreset = defineUnimportPreset({ 'defineNuxtPlugin', 'useRuntimeConfig', 'useState', - 'useFetch', 'useLazyFetch', 'useCookie', 'useRequestHeaders', 'useRequestEvent', 'useRouter', 'useRoute', - 'useActiveRoute', 'defineNuxtRouteMiddleware', 'navigateTo', 'abortNavigation', 'addRouteMiddleware', - 'throwError', - 'clearError', - 'useError', - 'defineNuxtLink' + 'useNuxt2Meta' ] }) diff --git a/src/meta.ts b/src/meta.ts index c8523c25..29d51e1c 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -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 diff --git a/src/runtime/composables.ts b/src/runtime/composables.ts index b8633727..69b6987e 100644 --- a/src/runtime/composables.ts +++ b/src/runtime/composables.ts @@ -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'