Compare commits

...

2 Commits

Author SHA1 Message Date
Joaquín Sánchez
cd4cb3c081
Merge 27169820a2 into 9bf8465806 2024-11-19 23:30:27 +02:00
userquin
27169820a2 feat(nuxt): update imports module with unimport addon changes 2024-11-06 13:06:21 +01:00

View File

@ -1,7 +1,7 @@
import { existsSync } from 'node:fs' import { existsSync } from 'node:fs'
import { addBuildPlugin, addTemplate, addTypeTemplate, defineNuxtModule, isIgnored, logger, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit' import { addBuildPlugin, addTemplate, addTypeTemplate, defineNuxtModule, isIgnored, logger, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit'
import { isAbsolute, join, normalize, relative, resolve } from 'pathe' import { isAbsolute, join, normalize, relative, resolve } from 'pathe'
import type { Import, Unimport } from 'unimport' import type { AddonsOptions, Import, Unimport } from 'unimport'
import { createUnimport, scanDirExports, toExports } from 'unimport' import { createUnimport, scanDirExports, toExports } from 'unimport'
import type { ImportPresetWithDeprecation, ImportsOptions, ResolvedNuxtTemplate } from 'nuxt/schema' import type { ImportPresetWithDeprecation, ImportsOptions, ResolvedNuxtTemplate } from 'nuxt/schema'
import escapeRE from 'escape-string-regexp' import escapeRE from 'escape-string-regexp'
@ -41,14 +41,23 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
// Filter disabled sources // Filter disabled sources
// options.sources = options.sources.filter(source => source.disabled !== true) // options.sources = options.sources.filter(source => source.disabled !== true)
const { addons: inlineAddons, ...rest } = options
const addons: AddonsOptions = {
addons: inlineAddons && Array.isArray(inlineAddons)
? [...inlineAddons]
: [],
vueDirectives: inlineAddons && !Array.isArray(inlineAddons)
? inlineAddons.vueDirectives
: options.autoImport === false ? undefined : true,
vueTemplate: options.autoImport,
}
// Create a context to share state between module internals // Create a context to share state between module internals
const ctx = createUnimport({ const ctx = createUnimport({
injectAtEnd: true, injectAtEnd: true,
...options, ...rest,
addons: { addons,
vueTemplate: options.autoImport,
...options.addons,
},
presets, presets,
}) })