File tree 3 files changed +18
-13
lines changed
3 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ export interface LoadConfigOptions<T extends InputConfig=InputConfig> {
40
40
resolve ?: ( id : string , opts : LoadConfigOptions ) => null | ResolvedConfig | Promise < ResolvedConfig | null >
41
41
42
42
extend ?: false | {
43
- extendKey ?: string
43
+ extendKey ?: string | string [ ]
44
44
}
45
45
}
46
46
@@ -128,12 +128,14 @@ export async function loadConfig<T extends InputConfig=InputConfig> (opts: LoadC
128
128
129
129
async function extendConfig ( config , opts : LoadConfigOptions ) {
130
130
config . _layers = config . _layers || [ ]
131
- if ( ! opts . extend ) {
132
- return
131
+ if ( ! opts . extend ) { return }
132
+ let keys = opts . extend . extendKey
133
+ if ( typeof keys === 'string' ) { keys = [ keys ] }
134
+ const extendSources = [ ]
135
+ for ( const key of keys ) {
136
+ extendSources . push ( ...( Array . isArray ( config [ key ] ) ? config [ key ] : [ config [ key ] ] ) . filter ( Boolean ) )
137
+ delete config [ key ]
133
138
}
134
- const key = opts . extend . extendKey
135
- const extendSources = ( Array . isArray ( config [ key ] ) ? config [ key ] : [ config [ key ] ] ) . filter ( Boolean )
136
- delete config [ key ]
137
139
for ( const extendSource of extendSources ) {
138
140
const _config = await resolveConfig ( extendSource , opts )
139
141
if ( ! _config . config ) {
Original file line number Diff line number Diff line change 1
1
export default {
2
+ theme : './theme' ,
2
3
extends : [
3
- './theme' ,
4
4
'./config.dev' ,
5
5
'c12-npm-test'
6
6
] ,
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ describe('c12', () => {
11
11
const { config, layers } = await loadConfig ( {
12
12
cwd : r ( './fixture' ) ,
13
13
dotenv : true ,
14
+ extend : {
15
+ extendKey : [ 'theme' , 'extends' ]
16
+ } ,
14
17
resolve : ( id ) => {
15
18
if ( id === 'virtual' ) {
16
19
return { config : { virtual : true } }
@@ -67,11 +70,11 @@ describe('c12', () => {
67
70
},
68
71
"configFile": true,
69
72
"extends": [
70
- "./theme",
71
73
"./config.dev",
72
74
"c12-npm-test",
73
75
],
74
76
"overriden": false,
77
+ "theme": "./theme",
75
78
},
76
79
"configFile": "config",
77
80
"cwd": "<path>/fixture",
@@ -82,11 +85,6 @@ describe('c12', () => {
82
85
},
83
86
"configFile": ".configrc",
84
87
},
85
- {
86
- "config": {
87
- "virtual": true,
88
- },
89
- },
90
88
{
91
89
"config": {
92
90
"colors": {
@@ -111,6 +109,11 @@ describe('c12', () => {
111
109
"configFile": "<path>/fixture/base/config.ts",
112
110
"cwd": "<path>/fixture/base",
113
111
},
112
+ {
113
+ "config": {
114
+ "virtual": true,
115
+ },
116
+ },
114
117
{
115
118
"config": {
116
119
"devConfig": true,
You can’t perform that action at this time.
0 commit comments