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'
|
|
|
|
|
|
|
|
export function addImports (imports: Import | Import[]) {
|
|
|
|
assertNuxtCompatibility({ bridge: true })
|
|
|
|
|
2022-11-16 02:26:35 +00:00
|
|
|
useNuxt().hook('imports:extend', (_imports) => {
|
2022-09-02 13:42:46 +00:00
|
|
|
_imports.push(...(Array.isArray(imports) ? imports : [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[]) => {
|
2022-09-02 13:42:46 +00:00
|
|
|
for (const dir of (Array.isArray(dirs) ? dirs : [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[]) => {
|
2022-09-06 10:17:41 +00:00
|
|
|
for (const preset of (Array.isArray(presets) ? presets : [presets])) {
|
|
|
|
_presets.push(preset)
|
|
|
|
}
|
2022-11-16 02:26:35 +00:00
|
|
|
})
|
2022-09-06 10:17:41 +00:00
|
|
|
}
|