Skip to content

Commit ccd17b1

Browse files
committed
feat: export mergeConfig
1 parent 628edec commit ccd17b1

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

dts.snapshot.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
2-
"config.d.mts": {
2+
"config-!~{00e}~.d.mts": {
33
"defineConfig": "declare function defineConfig(_: UserConfigExport): UserConfigExport",
4+
"mergeConfig": "declare function mergeConfig(_: InlineConfig, _: InlineConfig): InlineConfig"
5+
},
6+
"config.d.mts": {
47
"#exports": [
58
"UserConfig",
69
"UserConfigExport",
710
"UserConfigFn",
8-
"defineConfig"
11+
"defineConfig",
12+
"mergeConfig"
913
]
1014
},
11-
"index-!~{00a}~.d.mts": {
15+
"index-!~{00c}~.d.mts": {
1216
"Arrayable": "type Arrayable<T> = T | T[]",
1317
"AttwOptions": "interface AttwOptions extends CheckPackageOptions {\n profile?: 'strict' | 'node16' | 'esm-only'\n level?: 'error' | 'warn'\n ignoreRules?: string[]\n}",
1418
"Awaitable": "type Awaitable<T> = T | Promise<T>",
@@ -111,7 +115,8 @@
111115
"Workspace",
112116
"build",
113117
"defineConfig",
114-
"globalLogger"
118+
"globalLogger",
119+
"mergeConfig"
115120
]
116121
},
117122
"plugins.d.mts": {

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
UserConfigExport,
44
UserConfigFn,
55
} from './config/index.ts'
6-
76
/**
87
* Defines the configuration for tsdown.
98
*/
@@ -16,3 +15,4 @@ export function defineConfig(options: UserConfigExport): UserConfigExport {
1615
}
1716

1817
export type { UserConfig, UserConfigExport, UserConfigFn }
18+
export { mergeConfig } from './config/options.ts'

src/config/options.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import isInCi from 'is-in-ci'
22
import { describe, expect, test } from 'vitest'
3-
import { resolveFeatureOption as _resolveFeatureOption } from './options.ts'
3+
import {
4+
resolveFeatureOption as _resolveFeatureOption,
5+
mergeConfig,
6+
} from './options.ts'
47

58
const defaultOption = { a: 1 }
69
interface DefaultOption {
@@ -55,3 +58,33 @@ describe('resolveFeatureOption', () => {
5558
}
5659
})
5760
})
61+
62+
test('mergeConfig', () => {
63+
expect(
64+
mergeConfig(
65+
{
66+
a: 1,
67+
obj: { c: 2, d: 3 },
68+
arr: [1, 2, 3],
69+
} as any,
70+
{
71+
obj: { c: 42 },
72+
arr: [4, 5],
73+
e: 5,
74+
} as any,
75+
),
76+
).toMatchInlineSnapshot(`
77+
{
78+
"a": 1,
79+
"arr": [
80+
4,
81+
5,
82+
],
83+
"e": 5,
84+
"obj": {
85+
"c": 42,
86+
"d": 3,
87+
},
88+
}
89+
`)
90+
})

src/config/options.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,21 @@ const defu = createDefu((obj, key, value) => {
335335
}
336336
})
337337

338+
export function mergeConfig(
339+
defaults: UserConfig,
340+
overrides: UserConfig,
341+
): UserConfig
342+
export function mergeConfig(
343+
defaults: InlineConfig,
344+
overrides: InlineConfig,
345+
): InlineConfig
346+
export function mergeConfig(
347+
defaults: InlineConfig,
348+
overrides: InlineConfig,
349+
): InlineConfig {
350+
return defu(overrides, defaults)
351+
}
352+
338353
export async function mergeUserOptions<T extends object, A extends unknown[]>(
339354
defaults: T,
340355
user:

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ const pkgRoot: string = path.resolve(dirname, '..')
298298
/** @internal */
299299
export const shimFile: string = path.resolve(pkgRoot, 'esm-shims.js')
300300

301-
export { defineConfig } from './config.ts'
301+
export { defineConfig, mergeConfig } from './config.ts'
302302
export * from './config/types.ts'
303303
export { globalLogger, type Logger } from './utils/logger.ts'
304304
export * as Rolldown from 'rolldown'

0 commit comments

Comments
 (0)