@@ -103,7 +103,7 @@ async function resolveConfig(
103
103
return result ;
104
104
}
105
105
106
- const resolveExtra = ( base : any = { } , key : string , resolver ) => {
106
+ const resolveExtra = ( base : any = { } , key : string , resolver : Function ) => {
107
107
const value = base [ key ] ;
108
108
return value != null ? { [ key ] : resolver ( value ) } : { } ;
109
109
} ;
@@ -115,17 +115,25 @@ function mergeConfig<T: $ReadOnly<InputConfigT>>(
115
115
// If the file is a plain object we merge the file with the default config,
116
116
// for the function we don't do this since that's the responsibility of the user
117
117
return xtends . populateSync ( defaultConfig , {
118
+ // $FlowFixMe[prop-missing]
119
+ cwd : mergeConfig . cwd ,
118
120
extends : configs . map ( c => {
119
121
return {
120
122
...c ,
121
123
transformer : {
122
124
...( c . transformer || { } ) ,
123
- ...resolveExtra ( c . transformer , 'babelTransformerPath' , resolve ) ,
125
+ ...( resolveExtra ( c . transformer , 'babelTransformerPath' , resolve ) : {
126
+ babelTransformerPath ? : string ,
127
+ } ) ,
124
128
} ,
125
129
resolver : {
126
130
...( c . resolver || { } ) ,
127
- ...resolveExtra ( c . resolver , 'dependencyExtractor' , resolve ) ,
128
- ...resolveExtra ( c . resolver , 'hasteImplModulePath' , resolve ) ,
131
+ ...( resolveExtra ( c . resolver , 'dependencyExtractor' , resolve ) : {
132
+ dependencyExtractor ? : string ,
133
+ } ) ,
134
+ ...( resolveExtra ( c . resolver , 'hasteImplModulePath' , resolve ) : {
135
+ hasteImplModulePath ? : string ,
136
+ } ) ,
129
137
} ,
130
138
...resolveExtra ( c , 'cacheStores' , stores => {
131
139
return typeof stores === 'function' ? stores ( MetroCache ) : stores ;
@@ -146,6 +154,24 @@ function mergeConfig<T: $ReadOnly<InputConfigT>>(
146
154
} ) ;
147
155
}
148
156
157
+ // mergeConfig is public, we should try to keep the API stable
158
+ // We use this trick to pass cwd to `populateSync`
159
+ const mergeConfigHooked = < T : $ReadOnly < InputConfigT >> (
160
+ cwd : string ,
161
+ base : T ,
162
+ extra : ConfigT | InputConfigT ,
163
+ ) : T => {
164
+ // $FlowFixMe[prop-missing]
165
+ mergeConfig . cwd = cwd ;
166
+
167
+ // $FlowFixMe[incompatible-variance]
168
+ // $FlowFixMe[incompatible-call]
169
+ const config = mergeConfig ( base , extra ) ;
170
+ // $FlowFixMe[prop-missing]
171
+ mergeConfig . cwd = undefined ;
172
+ return config ;
173
+ } ;
174
+
149
175
async function loadMetroConfigFromDisk (
150
176
path ?: string ,
151
177
cwd ?: string ,
@@ -160,23 +186,21 @@ async function loadMetroConfigFromDisk(
160
186
const rootPath = dirname ( filepath ) ;
161
187
162
188
const defaults = await getDefaultConfig ( rootPath ) ;
163
- // $FlowFixMe[incompatible-variance]
164
- // $FlowFixMe[incompatible-call]
165
- const defaultConfig : ConfigT = mergeConfig ( defaults , defaultConfigOverrides ) ;
189
+ const defaultConfig : ConfigT = mergeConfigHooked (
190
+ rootPath ,
191
+ defaults ,
192
+ defaultConfigOverrides ,
193
+ ) ;
166
194
167
195
if ( typeof configModule === 'function' ) {
168
196
// Get a default configuration based on what we know, which we in turn can pass
169
197
// to the function.
170
198
171
199
const resultedConfig = await configModule ( defaultConfig ) ;
172
- // $FlowFixMe[incompatible-call]
173
- // $FlowFixMe[incompatible-variance]
174
- return mergeConfig ( defaultConfig , resultedConfig ) ;
200
+ return mergeConfigHooked ( rootPath , defaultConfig , resultedConfig ) ;
175
201
}
176
202
177
- // $FlowFixMe[incompatible-variance]
178
- // $FlowFixMe[incompatible-call]
179
- return mergeConfig ( defaultConfig , configModule ) ;
203
+ return mergeConfigHooked ( rootPath , defaultConfig , configModule ) ;
180
204
}
181
205
182
206
function overrideConfigWithArguments (
0 commit comments