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
*/
@@ -98,26 +100,22 @@ export default async function loadMetroConfig(
98
100
99
101
logger . debug ( `Reading Metro config from ${ projectConfig . filepath } ` ) ;
100
102
101
- if (
102
- ! / [ ' " ' ] @ r e a c t - n a t i v e \/ m e t r o - c o n f i g [ ' " ' ] / . test (
103
- fs . readFileSync ( projectConfig . filepath , 'utf8' ) ,
104
- )
105
- ) {
106
- logger . warn (
107
- 'From React Native 0.72, your metro.config.js file should extend' +
108
- "'@react-native/metro-config'. Please see the React Native 0.72 " +
109
- 'changelog, or copy the template at:\n' +
110
- 'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js' ,
111
- ) ;
112
- logger . warn ( 'Falling back to internal defaults.' ) ;
103
+ if ( ! global . __REACT_NATIVE_METRO_CONFIG_LOADED ) {
104
+ const warning = `
105
+ =================================================================================================
113
106
114
- const loadedConfig = await loadConfig (
115
- { cwd : ctx . root , ...options } ,
116
- // Provide React Native defaults on top of Metro defaults
117
- getDefaultMetroConfig ( ctx ) ,
118
- ) ;
107
+ From React Native 0.73, your project's Metro config should extend '@react-native/metro-config'
108
+ or it will fail to build. Please copy the template at:
109
+ https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js
110
+
111
+ This warning will be removed in future (https://github.com/facebook/metro/issues/1018).
112
+
113
+ =================================================================================================
114
+ ` ;
119
115
120
- return mergeConfig ( loadedConfig , overrideConfig ) ;
116
+ for ( const line of warning . trim ( ) . split ( '\n' ) ) {
117
+ logger . warn ( line ) ;
118
+ }
121
119
}
122
120
123
121
return mergeConfig (
0 commit comments