From 6276580aa4198ac3e738e1f6053df443b0c52e0f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 7 Apr 2022 12:35:11 +0100 Subject: [PATCH] fix(bridge): exclude unsupported imports via `autoImports:sources` (#4127) --- packages/bridge/src/auto-imports.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/bridge/src/auto-imports.ts b/packages/bridge/src/auto-imports.ts index a53e3836a3..3f4545149c 100644 --- a/packages/bridge/src/auto-imports.ts +++ b/packages/bridge/src/auto-imports.ts @@ -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 }))