@@ -28,6 +28,7 @@ import {getBunVersionIfAvailable} from '../../tools/bun';
28
28
import { getNpmVersionIfAvailable } from '../../tools/npm' ;
29
29
import { getYarnVersionIfAvailable } from '../../tools/yarn' ;
30
30
import { createHash } from 'crypto' ;
31
+ import deepmerge from 'deepmerge' ;
31
32
32
33
const DEFAULT_VERSION = 'latest' ;
33
34
@@ -270,6 +271,14 @@ function createTemplateUri(options: Options, version: string): string {
270
271
return options . template || `react-native@${ version } ` ;
271
272
}
272
273
274
+ /*
275
+ Starting from 0.73, react-native.config.js is created by CLI during the init process.
276
+ It contains automaticPodsInstallation flag set to true by default.
277
+ This flag is used by CLI to determine whether to install CocoaPods dependencies when running ios commands or not.
278
+ It's created by CLI rather than being a part of a template to avoid displaying this file in the Upgrade Helper,
279
+ as it might bring confusion for existing projects where this change might not be applicable.
280
+ For more details, see https://github.com/react-native-community/cli/blob/main/docs/projects.md#projectiosautomaticpodsinstallation
281
+ */
273
282
function createDefaultConfigFile ( directory : string ) {
274
283
const content = `module.exports = {
275
284
project: {
@@ -281,11 +290,22 @@ function createDefaultConfigFile(directory: string) {
281
290
` ;
282
291
283
292
const filepath = 'react-native.config.js' ;
284
- if ( ! fs . existsSync ( path . join ( directory , filepath ) ) ) {
293
+ if ( ! doesDirectoryExist ( path . join ( directory , filepath ) ) ) {
285
294
fs . createFileSync ( filepath ) ;
286
- }
295
+ fs . writeFileSync ( filepath , content , { encoding : 'utf-8' } ) ;
296
+ } else {
297
+ const tempFilePath = path . join ( directory , 'tempConfig.js' ) ;
298
+ fs . writeFileSync ( tempFilePath , content ) ;
299
+ const cliConfigFile = require ( tempFilePath ) ;
300
+ const existingConfigFile = require ( path . join ( directory , filepath ) ) ;
301
+
302
+ const mergedConfig = deepmerge ( existingConfigFile , cliConfigFile ) ;
287
303
288
- fs . writeFileSync ( filepath , content , { encoding : 'utf-8' } ) ;
304
+ fs . unlinkSync ( tempFilePath ) ;
305
+
306
+ const output = `module.exports = ${ JSON . stringify ( mergedConfig , null , 2 ) } ;` ;
307
+ fs . writeFileSync ( filepath , output , { encoding : 'utf-8' } ) ;
308
+ }
289
309
}
290
310
291
311
async function createProject (
0 commit comments