From e1d750e0776c1bb1e14b8751b52780dcd1d3dccd Mon Sep 17 00:00:00 2001 From: huymobile Date: Wed, 26 Aug 2026 12:01:21 +0700 Subject: [PATCH] fix(config): apply nested project defaults --- docs/projects.md | 2 +- .../cli-config/src/__tests__/schema-test.ts | 25 +++++++++++++++++++ packages/cli-config/src/schema.ts | 4 +-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 packages/cli-config/src/__tests__/schema-test.ts diff --git a/docs/projects.md b/docs/projects.md index 2c0537306..9e496a5cd 100644 --- a/docs/projects.md +++ b/docs/projects.md @@ -105,7 +105,7 @@ A boolean value to determine if you want to automatically install CocoaPods when If set to `true`, you can skip running `pod install` manually whenever it's needed. -> Note: Starting from React Native 0.73, CLI's `init` command scaffolds the project with `react-native.config.js` file with this value set to `true` by default. Older projects can opt-in after migrating to 0.73. Please note that if your setup does not follow the standard React Native template, e.g. you are not using Gems to install CocoaPods, this might not work properly for you. Starting from React Native 0.79, users shouldn't install CocoaPods manually, but can still opt-out of automatic installation by setting this value to `false`. +> Note: Starting from React Native 0.79, the CLI installs CocoaPods automatically when required, even if the project does not have a `react-native.config.js` file. You can opt out by setting this value to `false`. If your setup does not follow the standard React Native template, e.g. you are not using Gems to install CocoaPods, automatic installation might not work properly for you. ### project.ios.assets diff --git a/packages/cli-config/src/__tests__/schema-test.ts b/packages/cli-config/src/__tests__/schema-test.ts new file mode 100644 index 000000000..3e5ea5575 --- /dev/null +++ b/packages/cli-config/src/__tests__/schema-test.ts @@ -0,0 +1,25 @@ +import {projectConfig} from '../schema'; + +test.each([ + ['the entire config is omitted', undefined], + ['the config is empty', {}], + ['the project key is omitted', {dependencies: {}}], + ['the project config is empty', {project: {}}], +])('applies nested platform defaults when %s', (_description, config) => { + const {error, value} = projectConfig.validate(config); + + expect(error).toBeUndefined(); + expect(value.project).toEqual({ + android: {assets: []}, + ios: {assets: [], automaticPodsInstallation: true}, + }); +}); + +test('preserves an explicit automatic CocoaPods installation opt-out', () => { + const {error, value} = projectConfig.validate({ + project: {ios: {automaticPodsInstallation: false}}, + }); + + expect(error).toBeUndefined(); + expect(value.project.ios.automaticPodsInstallation).toBe(false); +}); diff --git a/packages/cli-config/src/schema.ts b/packages/cli-config/src/schema.ts index 0eb8e5013..7f41dcbcb 100644 --- a/packages/cli-config/src/schema.ts +++ b/packages/cli-config/src/schema.ts @@ -158,7 +158,7 @@ export const projectConfig = t automaticPodsInstallation: t.bool().default(true), assets: t.array().items(t.string()).default([]), }) - .default({}), + .default(), android: t // AndroidProjectParams .object({ @@ -170,7 +170,7 @@ export const projectConfig = t watchModeCommandParams: t.array().items(t.string()), assets: t.array().items(t.string()).default([]), }) - .default({}), + .default(), }) .default(), assets: t.array().items(t.string()).default([]),