diff --git a/src/preset.ts b/src/preset.ts index 7ae48c19..84f2c1ea 100644 --- a/src/preset.ts +++ b/src/preset.ts @@ -3,15 +3,23 @@ import type { Preset, Import } from './types' export function resolvePreset (preset: Preset): Import[] { const imports: Import[] = [] + + const defaults: Omit = { + from: preset.from + } + if (preset.priority != null) { + defaults.priority = preset.priority + } + for (const _import of preset.imports) { if (typeof _import === 'string') { - imports.push({ name: _import, as: _import, from: preset.from }) + imports.push({ ...defaults, name: _import, as: _import }) } else if (Array.isArray(_import)) { - imports.push({ name: _import[0], as: _import[1] || _import[0], from: _import[2] || preset.from }) + imports.push({ ...defaults, name: _import[0], as: _import[1] || _import[0], from: _import[2] || preset.from }) } else if ((_import as Preset).imports) { imports.push(...resolvePreset(_import as Preset)) } else { - imports.push({ from: preset.from, ..._import as Import }) + imports.push({ ...defaults, ..._import as Import }) } } return imports diff --git a/src/types.ts b/src/types.ts index a6f3087c..f6767ea7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,6 +22,7 @@ export type PresetImport = ImportName | [name: ImportName, as?: ImportName, from export interface Preset { from: ModuleId imports: (PresetImport | Preset)[] + priority?: number } export interface UnimportOptions {