diff --git a/packages/bridge/package.json b/packages/bridge/package.json index fb06cb27dc..d99860ab34 100644 --- a/packages/bridge/package.json +++ b/packages/bridge/package.json @@ -57,7 +57,7 @@ "scule": "^0.2.1", "semver": "^7.3.5", "ufo": "^0.8.1", - "unimport": "^0.1.2", + "unimport": "^0.1.3", "unplugin": "^0.6.0", "unplugin-vue2-script-setup": "^0.10.0", "untyped": "^0.4.3", diff --git a/packages/bridge/src/auto-imports.ts b/packages/bridge/src/auto-imports.ts index b5e108eda3..ce8e6eeb43 100644 --- a/packages/bridge/src/auto-imports.ts +++ b/packages/bridge/src/auto-imports.ts @@ -2,7 +2,7 @@ import { installModule, useNuxt } from '@nuxt/kit' import * as CompositionApi from '@vue/composition-api' import type { Preset } from 'unimport' import autoImports from '../../nuxt3/src/auto-imports/module' -import { vuePreset, commonPresets, appPreset } from '../../nuxt3/src/auto-imports/presets' +import { vuePreset } from '../../nuxt3/src/auto-imports/presets' const UnsupportedImports = new Set(['useAsyncData', 'useFetch', 'useError', 'throwError', 'clearError']) const CapiHelpers = new Set(Object.keys(CompositionApi)) @@ -11,19 +11,27 @@ export function setupAutoImports () { const nuxt = useNuxt() const bridgePresets: Preset[] = [ - ...commonPresets, - { - from: '#app', - imports: [ - ...appPreset.imports.filter(i => !UnsupportedImports.has(i as string)), - 'useNuxt2Meta' - ] - }, { from: '@vue/composition-api', imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string)) + }, + { + from: '#app', + imports: ['useNuxt2Meta'] } ] + 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 + } + } + }) nuxt.hook('modules:done', () => installModule(autoImports, { presets: bridgePresets })) } diff --git a/packages/kit/package.json b/packages/kit/package.json index 67e6a317e5..fa89198dc1 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -29,7 +29,7 @@ "scule": "^0.2.1", "semver": "^7.3.5", "unctx": "^1.1.0", - "unimport": "^0.1.2", + "unimport": "^0.1.3", "untyped": "^0.4.3" }, "devDependencies": { diff --git a/packages/nuxt3/package.json b/packages/nuxt3/package.json index d8efbc221f..28ae8d504e 100644 --- a/packages/nuxt3/package.json +++ b/packages/nuxt3/package.json @@ -59,7 +59,7 @@ "perfect-debounce": "^0.1.3", "scule": "^0.2.1", "ufo": "^0.8.1", - "unimport": "^0.1.2", + "unimport": "^0.1.3", "unplugin": "^0.6.0", "untyped": "^0.4.3", "vue": "^3.2.31", diff --git a/packages/nuxt3/src/auto-imports/module.ts b/packages/nuxt3/src/auto-imports/module.ts index ab2e9d2c83..97a996567c 100644 --- a/packages/nuxt3/src/auto-imports/module.ts +++ b/packages/nuxt3/src/auto-imports/module.ts @@ -1,7 +1,7 @@ import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolveAlias, useNuxt, addPluginTemplate, logger } from '@nuxt/kit' import { isAbsolute, join, relative, resolve, normalize } from 'pathe' import { createUnimport, Import, toImports, Unimport } from 'unimport' -import { AutoImportsOptions, ImportPresetWithDeperection } from '@nuxt/schema' +import { AutoImportsOptions, ImportPresetWithDeprecation } from '@nuxt/schema' import { TransformPlugin } from './transform' import { defaultPresets } from './presets' import { scanForComposables } from './composables' @@ -22,9 +22,9 @@ export default defineNuxtModule>({ }, async setup (options, nuxt) { // Allow modules extending sources - await nuxt.callHook('autoImports:sources', options.presets as ImportPresetWithDeperection[]) + await nuxt.callHook('autoImports:sources', options.presets as ImportPresetWithDeprecation[]) - options.presets.forEach((i: ImportPresetWithDeperection) => { + options.presets.forEach((i: ImportPresetWithDeprecation) => { if (typeof i !== 'string' && i.names && !i.imports) { i.imports = i.names logger.warn('auto-imports: presets.names is deprecated, use presets.imports instead') @@ -36,7 +36,7 @@ export default defineNuxtModule>({ // Create a context to share state between module internals const ctx = createUnimport({ - presets: defaultPresets, + presets: options.presets, imports: options.imports }) diff --git a/packages/schema/package.json b/packages/schema/package.json index 14f15d3478..85e323ec3d 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -28,7 +28,7 @@ "scule": "^0.2.1", "std-env": "^3.0.1", "ufo": "^0.8.1", - "unimport": "^0.1.2" + "unimport": "^0.1.3" }, "engines": { "node": "^14.16.0 || ^16.11.0 || ^17.0.0" diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index 716a24ab4e..47dc568daf 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -52,7 +52,7 @@ export type NuxtLayout = { file: string } -export interface ImportPresetWithDeperection extends ImportPreset { +export interface ImportPresetWithDeprecation extends ImportPreset { /** * @deprecated renamed to `imports` */ @@ -72,7 +72,7 @@ export interface NuxtHooks { 'pages:middleware:extend': (middleware: NuxtMiddleware[]) => HookResult // Auto imports - 'autoImports:sources': (presets: ImportPresetWithDeperection[]) => HookResult + 'autoImports:sources': (presets: ImportPresetWithDeprecation[]) => HookResult 'autoImports:extend': (imports: Import[]) => HookResult 'autoImports:dirs': (dirs: string[]) => HookResult diff --git a/yarn.lock b/yarn.lock index dd74a0a93d..04112d9bba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2675,7 +2675,7 @@ __metadata: semver: ^7.3.5 ufo: ^0.8.1 unbuild: latest - unimport: ^0.1.2 + unimport: ^0.1.3 unplugin: ^0.6.0 unplugin-vue2-script-setup: ^0.10.0 untyped: ^0.4.3 @@ -2974,7 +2974,7 @@ __metadata: semver: ^7.3.5 unbuild: latest unctx: ^1.1.0 - unimport: ^0.1.2 + unimport: ^0.1.3 untyped: ^0.4.3 languageName: unknown linkType: soft @@ -3138,7 +3138,7 @@ __metadata: std-env: ^3.0.1 ufo: ^0.8.1 unbuild: latest - unimport: ^0.1.2 + unimport: ^0.1.3 languageName: unknown linkType: soft @@ -15605,7 +15605,7 @@ __metadata: scule: ^0.2.1 ufo: ^0.8.1 unbuild: latest - unimport: ^0.1.2 + unimport: ^0.1.3 unplugin: ^0.6.0 untyped: ^0.4.3 vue: ^3.2.31 @@ -21301,9 +21301,9 @@ __metadata: languageName: node linkType: hard -"unimport@npm:^0.1.2": - version: 0.1.2 - resolution: "unimport@npm:0.1.2" +"unimport@npm:^0.1.3": + version: 0.1.3 + resolution: "unimport@npm:0.1.3" dependencies: "@rollup/pluginutils": ^4.1.2 escape-string-regexp: ^5.0.0 @@ -21314,7 +21314,7 @@ __metadata: pathe: ^0.2.0 scule: ^0.2.1 unplugin: ^0.3.3 - checksum: 212b56cd24796471c7af635f90275aa6f8d8c4c2085e89a8ebef0da5533e1d5fb56eeeb3b36753ee6365e62ccb241bf7baac961b34c123bbf5ce06c7f86d2a2c + checksum: a4e58b13cd1b9e8d6fbc783b026c66db5d101e6b660d4e92043c1b32089a12f8aa4864263823a05624ff55bac59b6637305cd22f35ac0c24e9f36b9cd3364752 languageName: node linkType: hard