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 () { export function setupAutoImports () {
const nuxt = useNuxt() const nuxt = useNuxt()
const bridgePresets: Preset[] = [ const bridgePresets: Preset[] = [{
{ from: '@vue/composition-api',
from: '@vue/composition-api', imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string)) }]
},
{
from: '#app',
imports: ['useNuxt2Meta']
}
]
nuxt.hook('autoImports:sources', (presets) => { nuxt.hook('autoImports:sources', (presets) => {
const vuePreset = presets.find(p => p.from === 'vue') const vuePreset = presets.find(p => p.from === 'vue')
if (vuePreset) { vuePreset.disabled = true } if (vuePreset) { vuePreset.disabled = true }
})
nuxt.hook('autoImports:extend', (imports) => { const appPreset = presets.find(p => p.from === '#app')
for (const i of imports) { if (!appPreset) { return }
if (i.from === '#app' && UnsupportedImports.has(i.name)) {
i.disabled = true 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 })) nuxt.hook('modules:done', () => installModule(autoImports, { presets: bridgePresets }))