Skip to content

Commit

Permalink
feat: new presetOverriding option
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 25, 2021
1 parent 218f5aa commit 785c141
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { presets } from '../presets'
import { ImportInfo, ImportsFlatMap, Options, ResolvedOptions } from '../types'

export function resolveOptions(options: Options = {}): ResolvedOptions {
const imports = flattenImportsMap(options.imports)
const imports = flattenImportsMap(options.imports, options.presetOverriding)
const resolved: ResolvedOptions = {
...options,
dts: options.dts === false
Expand All @@ -22,7 +22,7 @@ export function resolveOptions(options: Options = {}): ResolvedOptions {
return resolved
}

export function flattenImportsMap(map: Options['imports']): ImportsFlatMap {
export function flattenImportsMap(map: Options['imports'], overriding = false): ImportsFlatMap {
const flat: ImportsFlatMap = {}
toArray(map).forEach((definition) => {
if (typeof definition === 'string') {
Expand All @@ -45,7 +45,7 @@ export function flattenImportsMap(map: Options['imports']): ImportsFlatMap {
meta.name = id
}

if (flat[meta.name])
if (flat[meta.name] && !overriding)
throw new Error(`[auto-import] identifier ${meta.name} already defined with ${flat[meta.name].module}`)

flat[meta.name] = meta
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export interface Options {
* @default './auto-imports.d.ts'
*/
dts?: string | false
/**
* Allow overriding imports sources from multiple presets.
*
* @default false
*/
presetOverriding?: boolean
/**
* Rules to include transforming target.
*
Expand Down

0 comments on commit 785c141

Please sign in to comment.