diff --git a/packages/kit/src/imports.ts b/packages/kit/src/imports.ts index 10dfdb8962f..d8ce03ef87f 100644 --- a/packages/kit/src/imports.ts +++ b/packages/kit/src/imports.ts @@ -1,4 +1,5 @@ -import { Import } from 'unimport' +import type { Import } from 'unimport' +import type { ImportPresetWithDeprecation } from '@nuxt/schema' import { useNuxt } from './context' import { assertNuxtCompatibility } from './compatibility' @@ -31,3 +32,14 @@ export function addImportsDir (dirs: string | string[]) { * @deprecated Please use `addImportsDir` instead with nuxt>=3.0.0-rc.9 */ export const addAutoImportDir = addImportsDir + +export function addImportsSources (presets: ImportPresetWithDeprecation | ImportPresetWithDeprecation[]) { + assertNuxtCompatibility({ bridge: true }) + + // TODO: Use imports:* when widely adopted + useNuxt().hook('autoImports:sources', (_presets: ImportPresetWithDeprecation[]) => { + for (const preset of (Array.isArray(presets) ? presets : [presets])) { + _presets.push(preset) + } + }, { allowDeprecated: true }) +} diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index faefa9c92a8..16b60315274 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -152,7 +152,7 @@ async function initNuxt (nuxt: Nuxt) { nuxt.hooks.deprecateHooks({ 'autoImports:sources': { to: 'imports:sources', - message: '`autoImports:sources` hook is deprecated. Use `imports:sources` with `nuxt>=3.0.0-rc.9`.' + message: '`autoImports:sources` hook is deprecated. Use `addImportsSources()` from `@nuxt/kit` or `imports:dirs` with `nuxt>=3.0.0-rc.10`.' }, 'autoImports:dirs': { to: 'imports:dirs',