Skip to content

Commit f8d4493

Browse files
committed
CR updates
1 parent 6c739d9 commit f8d4493

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

packages/cli-platform-ios/src/commands/runIOS/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ async function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
5353
await resolvePods(ctx.root, ctx.dependencies, {
5454
forceInstall: args.forcePods,
5555
});
56-
} else if (args.forcePods && !ctx.project.ios?.automaticPodsInstallation) {
56+
} else if (args.forcePods) {
5757
logger.warn(
5858
`${chalk.bold(
5959
'--force-pods',
6060
)} has no effect because automatic CocoaPods installation is disabled. In order to use this flag, set ${chalk.bold(
6161
'project.ios.automaticPodsInstallation',
62-
)} to true in ${chalk.bold('react-native.config.js')}.`,
62+
)} to true in ${chalk.bold(
63+
'react-native.config.js',
64+
)}. For more information, see ${chalk.underline(
65+
'https://github.com/react-native-community/cli/blob/main/docs/projects.md#projectiosautomaticpodsinstallation',
66+
)}`,
6367
);
6468
}
6569

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@react-native-community/cli-types": "12.0.0-alpha.18",
3636
"chalk": "^4.1.2",
3737
"commander": "^9.4.1",
38+
"deepmerge": "^4.3.0",
3839
"execa": "^5.0.0",
3940
"find-up": "^4.1.0",
4041
"fs-extra": "^8.1.0",
@@ -48,7 +49,6 @@
4849
"@types/hapi__joi": "^17.1.6",
4950
"@types/prompts": "^2.4.4",
5051
"@types/semver": "^6.0.2",
51-
"deepmerge": "^4.3.0",
5252
"slash": "^3.0.0",
5353
"snapshot-diff": "^0.7.0"
5454
},

packages/cli/src/commands/init/init.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {getBunVersionIfAvailable} from '../../tools/bun';
2828
import {getNpmVersionIfAvailable} from '../../tools/npm';
2929
import {getYarnVersionIfAvailable} from '../../tools/yarn';
3030
import {createHash} from 'crypto';
31+
import deepmerge from 'deepmerge';
3132

3233
const DEFAULT_VERSION = 'latest';
3334

@@ -270,6 +271,14 @@ function createTemplateUri(options: Options, version: string): string {
270271
return options.template || `react-native@${version}`;
271272
}
272273

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+
*/
273282
function createDefaultConfigFile(directory: string) {
274283
const content = `module.exports = {
275284
project: {
@@ -281,11 +290,22 @@ function createDefaultConfigFile(directory: string) {
281290
`;
282291

283292
const filepath = 'react-native.config.js';
284-
if (!fs.existsSync(path.join(directory, filepath))) {
293+
if (!doesDirectoryExist(path.join(directory, filepath))) {
285294
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);
287303

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+
}
289309
}
290310

291311
async function createProject(

0 commit comments

Comments
 (0)