1
- import fs from 'fs' ;
2
1
import path from 'path' ;
3
2
import {
4
3
ConfigT ,
@@ -10,7 +9,6 @@ import {
10
9
} from 'metro-config' ;
11
10
import { CLIError , logger } from '@react-native-community/cli-tools' ;
12
11
import type { Config } from '@react-native-community/cli-types' ;
13
- import getDefaultMetroConfig from './getDefaultMetroConfig' ;
14
12
import { reactNativePlatformResolver } from './metroPlatformResolver' ;
15
13
16
14
export type { Config } ;
@@ -20,6 +18,10 @@ export type ConfigLoadingContext = Pick<
20
18
'root' | 'reactNativePath' | 'platforms'
21
19
> ;
22
20
21
+ declare global {
22
+ var __REACT_NATIVE_METRO_CONFIG_LOADED : boolean ;
23
+ }
24
+
23
25
/**
24
26
* Get the config options to override based on RN CLI inputs.
25
27
*/
@@ -97,26 +99,22 @@ export default async function loadMetroConfig(
97
99
98
100
logger . debug ( `Reading Metro config from ${ projectConfig . filepath } ` ) ;
99
101
100
- if (
101
- ! / [ ' " ' ] @ r e a c t - n a t i v e \/ m e t r o - c o n f i g [ ' " ' ] / . test (
102
- fs . readFileSync ( projectConfig . filepath , 'utf8' ) ,
103
- )
104
- ) {
105
- logger . warn (
106
- 'From React Native 0.72, your metro.config.js file should extend' +
107
- "'@react-native/metro-config'. Please see the React Native 0.72 " +
108
- 'changelog, or copy the template at:\n' +
109
- 'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js' ,
110
- ) ;
111
- logger . warn ( 'Falling back to internal defaults.' ) ;
102
+ if ( ! global . __REACT_NATIVE_METRO_CONFIG_LOADED ) {
103
+ const warning = `
104
+ =================================================================================================
112
105
113
- const loadedConfig = await loadConfig (
114
- { cwd : ctx . root , ...options } ,
115
- // Provide React Native defaults on top of Metro defaults
116
- getDefaultMetroConfig ( ctx ) ,
117
- ) ;
106
+ From React Native 0.73, your project's Metro config should extend '@react-native/metro-config'
107
+ or it will fail to build. Please copy the template at:
108
+ https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js
109
+
110
+ This warning will be removed in future (https://github.com/facebook/metro/issues/1018).
111
+
112
+ =================================================================================================
113
+ ` ;
118
114
119
- return mergeConfig ( loadedConfig , overrideConfig ) ;
115
+ for ( const line of warning . trim ( ) . split ( '\n' ) ) {
116
+ logger . warn ( line ) ;
117
+ }
120
118
}
121
119
122
120
return mergeConfig (
0 commit comments