Skip to content

Commit a860077

Browse files
author
Kræn Hansen
committed
Make react-native package name configurable
1 parent dc848fd commit a860077

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

packages/cli-config/src/__tests__/index-test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,22 @@ test('should convert project sourceDir relative path to absolute', async () => {
578578
path.join(DIR, androidProjectDir),
579579
);
580580
});
581+
582+
test('should be able to resolve platform-specific react-native path', async () => {
583+
DIR = getTempDirectory('config_test_apply_platform_react_native_path');
584+
writeFiles(DIR, {
585+
...REACT_NATIVE_MOCK,
586+
...PLATFORM_MOCK,
587+
'package.json': `{
588+
"dependencies": {
589+
"react-native": "0.0.1",
590+
"react-native-os": "0.0.1"
591+
}
592+
}`,
593+
});
594+
const {reactNativePath} = await loadConfigAsync({
595+
projectRoot: DIR,
596+
reactNativePackageName: 'react-native-os',
597+
});
598+
expect(reactNativePath).toMatch(/\/react-native-os$/);
599+
});

packages/cli-config/src/loadConfig.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ const removeDuplicateCommands = <T extends boolean>(commands: Command<T>[]) => {
9090
export default function loadConfig({
9191
projectRoot = findProjectRoot(),
9292
selectedPlatform,
93+
reactNativePackageName,
9394
}: {
9495
projectRoot?: string;
9596
selectedPlatform?: string;
97+
reactNativePackageName?: string;
9698
}): Config {
9799
let lazyProject: ProjectConfig;
98100
const userConfig = readConfigFromDisk(projectRoot);
@@ -102,7 +104,7 @@ export default function loadConfig({
102104
get reactNativePath() {
103105
return userConfig.reactNativePath
104106
? path.resolve(projectRoot, userConfig.reactNativePath)
105-
: resolveReactNativePath(projectRoot);
107+
: resolveReactNativePath(projectRoot, reactNativePackageName);
106108
},
107109
get reactNativeVersion() {
108110
return getReactNativeVersion(initialConfig.reactNativePath);
@@ -188,9 +190,11 @@ export default function loadConfig({
188190
export async function loadConfigAsync({
189191
projectRoot = findProjectRoot(),
190192
selectedPlatform,
193+
reactNativePackageName,
191194
}: {
192195
projectRoot?: string;
193196
selectedPlatform?: string;
197+
reactNativePackageName?: string;
194198
}): Promise<Config> {
195199
let lazyProject: ProjectConfig;
196200
const userConfig = await readConfigFromDiskAsync(projectRoot);
@@ -200,7 +204,7 @@ export async function loadConfigAsync({
200204
get reactNativePath() {
201205
return userConfig.reactNativePath
202206
? path.resolve(projectRoot, userConfig.reactNativePath)
203-
: resolveReactNativePath(projectRoot);
207+
: resolveReactNativePath(projectRoot, reactNativePackageName);
204208
},
205209
get reactNativeVersion() {
206210
return getReactNativeVersion(initialConfig.reactNativePath);

packages/cli-config/src/resolveReactNativePath.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import {
77
* Finds path to React Native inside `node_modules` or throws
88
* an error otherwise.
99
*/
10-
export default function resolveReactNativePath(root: string) {
10+
export default function resolveReactNativePath(
11+
root: string,
12+
reactNativePackageName = 'react-native',
13+
) {
1114
try {
12-
return resolveNodeModuleDir(root, 'react-native');
15+
return resolveNodeModuleDir(root, reactNativePackageName);
1316
} catch (_ignored) {
1417
throw new CLIError(`
15-
Unable to find React Native files looking up from ${root}. Make sure "react-native" module is installed
18+
Unable to find React Native files looking up from ${root}. Make sure "${reactNativePackageName}" module is installed
1619
in your project dependencies.
1720
1821
If you are using React Native from a non-standard location, consider setting:

0 commit comments

Comments
 (0)