Skip to content

Commit 1418122

Browse files
committed
fix: merge input & output options
closes #640
1 parent 19bdd0e commit 1418122

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"dependencies": {
9494
"ansis": "catalog:prod",
9595
"cac": "catalog:prod",
96+
"defu": "catalog:prod",
9697
"empathic": "catalog:prod",
9798
"hookable": "catalog:prod",
9899
"import-without-cache": "catalog:prod",

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ catalogs:
5656
prod:
5757
ansis: ^4.2.0
5858
cac: ^6.7.14
59+
defu: ^6.1.4
5960
empathic: ^2.0.0
6061
hookable: ^5.5.3
6162
import-without-cache: ^0.2.3

src/config/options.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path'
22
import process from 'node:process'
33
import { blue } from 'ansis'
4+
import { createDefu } from 'defu'
45
import isInCi from 'is-in-ci'
56
import { createDebug } from 'obug'
67
import { resolveClean } from '../features/clean.ts'
@@ -277,6 +278,13 @@ export async function resolveUserConfig(
277278
})
278279
}
279280

281+
const defu = createDefu((obj, key, value) => {
282+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
283+
obj[key] = value
284+
return true
285+
}
286+
})
287+
280288
export async function mergeUserOptions<T extends object, A extends unknown[]>(
281289
defaults: T,
282290
user:
@@ -288,7 +296,8 @@ export async function mergeUserOptions<T extends object, A extends unknown[]>(
288296
): Promise<T> {
289297
const userOutputOptions =
290298
typeof user === 'function' ? await user(defaults, ...args) : user
291-
return { ...defaults, ...userOutputOptions }
299+
if (!userOutputOptions) return defaults
300+
return defu(userOutputOptions, defaults)
292301
}
293302

294303
export function resolveFeatureOption<T>(

0 commit comments

Comments
 (0)