Skip to content

Commit e4ec71b

Browse files
committed
breaking: Bundle iOS and Android as core platforms
1 parent 9013a48 commit e4ec71b

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

packages/cli-config/src/loadConfig.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,37 @@ const removeDuplicateCommands = <T extends boolean>(commands: Command<T>[]) => {
8484
return Array.from(uniqueCommandsMap.values());
8585
};
8686

87+
/**
88+
* Returns the built-in platforms to seed the config with, honoring the
89+
* `selectedPlatform` filter the same way dependency platforms are filtered. The
90+
* project's own and dependencies' platforms are layered on top of these.
91+
*/
92+
const getBasePlatforms = (
93+
platforms: Config['platforms'] | undefined,
94+
selectedPlatform: string | undefined,
95+
): {[platform: string]: Config['platforms'][string]} => {
96+
if (!platforms) {
97+
return {};
98+
}
99+
if (selectedPlatform != null) {
100+
return platforms[selectedPlatform]
101+
? {[selectedPlatform]: platforms[selectedPlatform]}
102+
: {};
103+
}
104+
return platforms;
105+
};
106+
87107
/**
88108
* Loads CLI configuration
89109
*/
90110
export default function loadConfig({
91111
projectRoot = findProjectRoot(),
92112
selectedPlatform,
113+
platforms,
93114
}: {
94115
projectRoot?: string;
95116
selectedPlatform?: string;
117+
platforms?: Config['platforms'];
96118
}): Config {
97119
let lazyProject: ProjectConfig;
98120
const userConfig = readConfigFromDisk(projectRoot);
@@ -110,7 +132,10 @@ export default function loadConfig({
110132
dependencies: userConfig.dependencies,
111133
commands: userConfig.commands,
112134
healthChecks: userConfig.healthChecks || [],
113-
platforms: userConfig.platforms,
135+
platforms: {
136+
...getBasePlatforms(platforms, selectedPlatform),
137+
...userConfig.platforms,
138+
},
114139
assets: userConfig.assets,
115140
get project() {
116141
if (lazyProject) {
@@ -188,9 +213,11 @@ export default function loadConfig({
188213
export async function loadConfigAsync({
189214
projectRoot = findProjectRoot(),
190215
selectedPlatform,
216+
platforms,
191217
}: {
192218
projectRoot?: string;
193219
selectedPlatform?: string;
220+
platforms?: Config['platforms'];
194221
}): Promise<Config> {
195222
let lazyProject: ProjectConfig;
196223
const userConfig = await readConfigFromDiskAsync(projectRoot);
@@ -208,7 +235,10 @@ export async function loadConfigAsync({
208235
dependencies: userConfig.dependencies,
209236
commands: userConfig.commands,
210237
healthChecks: userConfig.healthChecks || [],
211-
platforms: userConfig.platforms,
238+
platforms: {
239+
...getBasePlatforms(platforms, selectedPlatform),
240+
...userConfig.platforms,
241+
},
212242
assets: userConfig.assets,
213243
get project() {
214244
if (lazyProject) {

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"@react-native-community/cli-clean": "20.2.0",
2828
"@react-native-community/cli-config": "20.2.0",
2929
"@react-native-community/cli-doctor": "20.2.0",
30+
"@react-native-community/cli-platform-android": "20.2.0",
31+
"@react-native-community/cli-platform-ios": "20.2.0",
3032
"@react-native-community/cli-server-api": "20.2.0",
3133
"@react-native-community/cli-tools": "20.2.0",
3234
"@react-native-community/cli-types": "20.2.0",

packages/cli/src/commands/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import {Command, DetachedCommand} from '@react-native-community/cli-types';
22
import {commands as cleanCommands} from '@react-native-community/cli-clean';
33
import {commands as doctorCommands} from '@react-native-community/cli-doctor';
44
import {commands as configCommands} from '@react-native-community/cli-config';
5+
import {commands as androidCommands} from '@react-native-community/cli-platform-android';
6+
import {commands as iosCommands} from '@react-native-community/cli-platform-ios';
57
import init from './init';
68

79
export const projectCommands = [
810
...configCommands,
911
cleanCommands.clean,
1012
doctorCommands.info,
13+
...iosCommands,
14+
...androidCommands,
1115
] as Command[];
1216

1317
export const detachedCommands = [

packages/cli/src/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import type {
55
Config,
66
DetachedCommand,
77
} from '@react-native-community/cli-types';
8+
import {
9+
projectConfig as androidProjectConfig,
10+
dependencyConfig as androidDependencyConfig,
11+
} from '@react-native-community/cli-platform-android';
12+
import {
13+
projectConfig as iosProjectConfig,
14+
dependencyConfig as iosDependencyConfig,
15+
} from '@react-native-community/cli-platform-ios';
816
import childProcess from 'child_process';
917
import {Command as CommanderCommand} from 'commander';
1018
import path from 'path';
@@ -197,6 +205,26 @@ async function setupAndRun(platformName?: string) {
197205

198206
config = await loadConfigAsync({
199207
selectedPlatform,
208+
// iOS and Android are core platforms bundled with the CLI, so they are
209+
// always registered. The project's own and dependencies' configs can
210+
// still override them.
211+
//
212+
// The cast is needed because the platform packages' `projectConfig`/
213+
// `dependencyConfig` return `null` and take required params, whereas the
214+
// `PlatformConfig` interface models these as `void`. These functions are
215+
// the canonical implementations the CLI already calls via the config scan.
216+
platforms: {
217+
ios: {
218+
npmPackageName: '@react-native-community/cli-platform-ios',
219+
projectConfig: iosProjectConfig,
220+
dependencyConfig: iosDependencyConfig,
221+
},
222+
android: {
223+
npmPackageName: '@react-native-community/cli-platform-android',
224+
projectConfig: androidProjectConfig,
225+
dependencyConfig: androidDependencyConfig,
226+
},
227+
} as Config['platforms'],
200228
});
201229

202230
logger.enable();

packages/cli/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
{"path": "../cli-config"},
1010
{"path": "../cli-doctor"},
1111
{"path": "../cli-link-assets"},
12+
{"path": "../cli-platform-android"},
13+
{"path": "../cli-platform-ios"},
1214
{"path": "../cli-server-api"},
1315
{"path": "../cli-types"},
1416
{"path": "../cli-tools"}

0 commit comments

Comments
 (0)