From a8600774138f52413b99cf7b6bb211c8d507d8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Sun, 2 Nov 2025 22:43:25 +0100 Subject: [PATCH 1/2] Make react-native package name configurable --- .../cli-config/src/__tests__/index-test.ts | 19 +++++++++++++++++++ packages/cli-config/src/loadConfig.ts | 8 ++++++-- .../cli-config/src/resolveReactNativePath.ts | 9 ++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/cli-config/src/__tests__/index-test.ts b/packages/cli-config/src/__tests__/index-test.ts index 3740e8d1c..edd9ed324 100644 --- a/packages/cli-config/src/__tests__/index-test.ts +++ b/packages/cli-config/src/__tests__/index-test.ts @@ -578,3 +578,22 @@ test('should convert project sourceDir relative path to absolute', async () => { path.join(DIR, androidProjectDir), ); }); + +test('should be able to resolve platform-specific react-native path', async () => { + DIR = getTempDirectory('config_test_apply_platform_react_native_path'); + writeFiles(DIR, { + ...REACT_NATIVE_MOCK, + ...PLATFORM_MOCK, + 'package.json': `{ + "dependencies": { + "react-native": "0.0.1", + "react-native-os": "0.0.1" + } + }`, + }); + const {reactNativePath} = await loadConfigAsync({ + projectRoot: DIR, + reactNativePackageName: 'react-native-os', + }); + expect(reactNativePath).toMatch(/\/react-native-os$/); +}); diff --git a/packages/cli-config/src/loadConfig.ts b/packages/cli-config/src/loadConfig.ts index b01c2d03b..294ccec3b 100644 --- a/packages/cli-config/src/loadConfig.ts +++ b/packages/cli-config/src/loadConfig.ts @@ -90,9 +90,11 @@ const removeDuplicateCommands = (commands: Command[]) => { export default function loadConfig({ projectRoot = findProjectRoot(), selectedPlatform, + reactNativePackageName, }: { projectRoot?: string; selectedPlatform?: string; + reactNativePackageName?: string; }): Config { let lazyProject: ProjectConfig; const userConfig = readConfigFromDisk(projectRoot); @@ -102,7 +104,7 @@ export default function loadConfig({ get reactNativePath() { return userConfig.reactNativePath ? path.resolve(projectRoot, userConfig.reactNativePath) - : resolveReactNativePath(projectRoot); + : resolveReactNativePath(projectRoot, reactNativePackageName); }, get reactNativeVersion() { return getReactNativeVersion(initialConfig.reactNativePath); @@ -188,9 +190,11 @@ export default function loadConfig({ export async function loadConfigAsync({ projectRoot = findProjectRoot(), selectedPlatform, + reactNativePackageName, }: { projectRoot?: string; selectedPlatform?: string; + reactNativePackageName?: string; }): Promise { let lazyProject: ProjectConfig; const userConfig = await readConfigFromDiskAsync(projectRoot); @@ -200,7 +204,7 @@ export async function loadConfigAsync({ get reactNativePath() { return userConfig.reactNativePath ? path.resolve(projectRoot, userConfig.reactNativePath) - : resolveReactNativePath(projectRoot); + : resolveReactNativePath(projectRoot, reactNativePackageName); }, get reactNativeVersion() { return getReactNativeVersion(initialConfig.reactNativePath); diff --git a/packages/cli-config/src/resolveReactNativePath.ts b/packages/cli-config/src/resolveReactNativePath.ts index a3b8403b7..271e77b26 100644 --- a/packages/cli-config/src/resolveReactNativePath.ts +++ b/packages/cli-config/src/resolveReactNativePath.ts @@ -7,12 +7,15 @@ import { * Finds path to React Native inside `node_modules` or throws * an error otherwise. */ -export default function resolveReactNativePath(root: string) { +export default function resolveReactNativePath( + root: string, + reactNativePackageName = 'react-native', +) { try { - return resolveNodeModuleDir(root, 'react-native'); + return resolveNodeModuleDir(root, reactNativePackageName); } catch (_ignored) { throw new CLIError(` - Unable to find React Native files looking up from ${root}. Make sure "react-native" module is installed + Unable to find React Native files looking up from ${root}. Make sure "${reactNativePackageName}" module is installed in your project dependencies. If you are using React Native from a non-standard location, consider setting: From 5be468671bf319df594961c1d96cdda79c7fd466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Sun, 2 Nov 2025 22:43:47 +0100 Subject: [PATCH 2/2] Pass --react-native-package-name into config when loading --- packages/cli-config/src/commands/config.ts | 5 +++++ packages/cli/src/index.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/cli-config/src/commands/config.ts b/packages/cli-config/src/commands/config.ts index 1a2c92665..923a545a9 100644 --- a/packages/cli-config/src/commands/config.ts +++ b/packages/cli-config/src/commands/config.ts @@ -27,6 +27,11 @@ export default { name: '--platform ', description: 'Output configuration for a specific platform', }, + { + name: '--react-native-package-name ', + description: + 'Optional package name to use when resolving react-native, passable by out-of-tree platforms.', + }, ], func: async (_argv: string[], ctx: Config) => { console.log(JSON.stringify(filterConfig(ctx), null, 2)); diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index c2841f402..c66e87653 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -182,6 +182,7 @@ async function setupAndRun(platformName?: string) { let config: Config | undefined; try { let selectedPlatform: string | undefined; + let reactNativePackageName: string | undefined; /* When linking dependencies in iOS and Android build we're passing `--platform` argument, @@ -193,10 +194,22 @@ async function setupAndRun(platformName?: string) { if (platformIndex !== -1 && platformIndex < process.argv.length - 1) { selectedPlatform = process.argv[platformIndex + 1]; } + + const reactNativePackageNameIndex = process.argv.indexOf( + '--react-native-package-name', + ); + + if ( + reactNativePackageNameIndex !== -1 && + reactNativePackageNameIndex < process.argv.length - 1 + ) { + reactNativePackageName = process.argv[reactNativePackageNameIndex + 1]; + } } config = await loadConfigAsync({ selectedPlatform, + reactNativePackageName, }); logger.enable();