|
1 | 1 | import path from 'path'; |
2 | | -import {ConfigT, InputConfigT, loadConfig} from 'metro-config'; |
| 2 | +import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config'; |
3 | 3 | import type {Config} from '@react-native-community/cli-types'; |
4 | 4 | import {reactNativePlatformResolver} from './metroPlatformResolver'; |
5 | 5 |
|
@@ -69,13 +69,21 @@ export interface ConfigOptionsT { |
69 | 69 | * Allows the CLI to override certain defaults in the base `metro.config.js` |
70 | 70 | * based on dynamic user options in `ctx`. |
71 | 71 | */ |
72 | | -export default function loadMetroConfig( |
| 72 | +export default async function loadMetroConfig( |
73 | 73 | ctx: ConfigLoadingContext, |
74 | | - options?: ConfigOptionsT, |
| 74 | + options: ConfigOptionsT = {}, |
75 | 75 | ): Promise<ConfigT> { |
76 | 76 | const overrideConfig = getOverrideConfig(ctx); |
77 | | - if (options && options.reporter) { |
| 77 | + if (options.reporter) { |
78 | 78 | overrideConfig.reporter = options.reporter; |
79 | 79 | } |
| 80 | + |
| 81 | + const projectConfig = await resolveConfig(undefined, ctx.root); |
| 82 | + |
| 83 | + // @ts-ignore resolveConfig return value is mistyped |
| 84 | + if (projectConfig.isEmpty) { |
| 85 | + throw new Error(`No metro config found in ${ctx.root}`); |
| 86 | + } |
| 87 | + |
80 | 88 | return loadConfig({cwd: ctx.root, ...options}, overrideConfig); |
81 | 89 | } |
0 commit comments