2022-09-06 10:17:41 +00:00
|
|
|
import type { Import } from 'unimport'
|
|
|
|
import type { ImportPresetWithDeprecation } from '@nuxt/schema'
|
2022-09-02 13:42:46 +00:00
|
|
|
import { useNuxt } from './context'
|
|
|
|
import { assertNuxtCompatibility } from './compatibility'
|
2023-12-23 14:22:58 +00:00
|
|
|
import { toArray } from './utils'
|
2022-09-02 13:42:46 +00:00
|
|
|
|
|
|
|
export function addImports (imports: Import | Import[]) {
|
|
|
|
assertNuxtCompatibility({ bridge: true })
|
|
|
|
|
2022-11-16 02:26:35 +00:00
|
|
|
useNuxt().hook('imports:extend', (_imports) => {
|
2023-12-23 14:22:58 +00:00
|
|
|
_imports.push(...toArray(imports))
|
2022-11-16 02:26:35 +00:00
|
|
|
})
|
2022-09-02 13:42:46 +00:00
|
|
|
}
|
|
|
|
|
2023-04-29 22:21:45 +00:00
|
|
|
export function addImportsDir (dirs: string | string[], opts: { prepend?: boolean } = {}) {
|
2022-09-02 13:42:46 +00:00
|
|
|
assertNuxtCompatibility({ bridge: true })
|
|
|
|
|
2022-11-16 02:26:35 +00:00
|
|
|
useNuxt().hook('imports:dirs', (_dirs: string[]) => {
|
2023-12-23 14:22:58 +00:00
|
|
|
for (const dir of toArray(dirs)) {
|
2023-04-29 22:21:45 +00:00
|
|
|
_dirs[opts.prepend ? 'unshift' : 'push'](dir)
|
2022-09-02 13:42:46 +00:00
|
|
|
}
|
2022-11-16 02:26:35 +00:00
|
|
|
})
|
2022-09-02 13:42:46 +00:00
|
|
|
}
|
2022-09-06 10:17:41 +00:00
|
|
|
export function addImportsSources (presets: ImportPresetWithDeprecation | ImportPresetWithDeprecation[]) {
|
|
|
|
assertNuxtCompatibility({ bridge: true })
|
|
|
|
|
2022-11-16 02:26:35 +00:00
|
|
|
useNuxt().hook('imports:sources', (_presets: ImportPresetWithDeprecation[]) => {
|
2023-12-23 14:22:58 +00:00
|
|
|
for (const preset of toArray(presets)) {
|
2022-09-06 10:17:41 +00:00
|
|
|
_presets.push(preset)
|
|
|
|
}
|
2022-11-16 02:26:35 +00:00
|
|
|
})
|
2022-09-06 10:17:41 +00:00
|
|
|
}
|