fix(bridge): exclude unsupported imports via autoImports:sources (#4127)

This commit is contained in:
Daniel Roe 2022-04-07 12:35:11 +01:00 committed by GitHub
parent f0714d78b0
commit 6276580aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,27 +10,25 @@ const CapiHelpers = new Set(Object.keys(CompositionApi))
export function setupAutoImports () {
const nuxt = useNuxt()
const bridgePresets: Preset[] = [
{
from: '@vue/composition-api',
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
},
{
from: '#app',
imports: ['useNuxt2Meta']
}
]
const bridgePresets: Preset[] = [{
from: '@vue/composition-api',
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
}]
nuxt.hook('autoImports:sources', (presets) => {
const vuePreset = presets.find(p => p.from === 'vue')
if (vuePreset) { vuePreset.disabled = true }
})
nuxt.hook('autoImports:extend', (imports) => {
for (const i of imports) {
if (i.from === '#app' && UnsupportedImports.has(i.name)) {
i.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 }))