Skip to content

Commit 3786b48

Browse files
committed
Port isPureCxxDependency check from react-native-community/cli#2387
1 parent 1958032 commit 3786b48

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

packages/expo-modules-autolinking/src/reactNativeConfig/androidResolver.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,36 @@ export async function resolveDependencyConfigImplAndroidAsync(
2323
const sourceDir = reactNativeConfig?.sourceDir || 'android';
2424
const androidDir = path.join(packageRoot, sourceDir);
2525
const { gradle, manifest } = await findGradleAndManifestAsync({ androidDir, isLibrary: true });
26-
if (!manifest && !gradle) {
27-
return null;
28-
}
2926

30-
const packageName =
31-
reactNativeConfig?.packageName || (await parsePackageNameAsync(androidDir, manifest, gradle));
32-
if (!packageName) {
27+
const isPureCxxDependency =
28+
reactNativeConfig?.cxxModuleCMakeListsModuleName != null &&
29+
reactNativeConfig?.cxxModuleCMakeListsPath != null &&
30+
reactNativeConfig?.cxxModuleHeaderName != null &&
31+
!manifest &&
32+
!gradle;
33+
34+
if (!manifest && !gradle && !isPureCxxDependency) {
3335
return null;
3436
}
35-
const nativePackageClassName = await parseNativePackageClassNameAsync(packageRoot, androidDir);
36-
if (!nativePackageClassName) {
37-
return null;
37+
38+
let packageInstance: string | null = null;
39+
let packageImportPath: string | null = null;
40+
if (!isPureCxxDependency) {
41+
const packageName =
42+
reactNativeConfig?.packageName || (await parsePackageNameAsync(androidDir, manifest, gradle));
43+
if (!packageName) {
44+
return null;
45+
}
46+
const nativePackageClassName = await parseNativePackageClassNameAsync(packageRoot, androidDir);
47+
if (!nativePackageClassName) {
48+
return null;
49+
}
50+
packageImportPath =
51+
reactNativeConfig?.packageImportPath || `import ${packageName}.${nativePackageClassName};`;
52+
packageInstance = reactNativeConfig?.packageInstance || `new ${nativePackageClassName}()`;
3853
}
3954

4055
const packageJson = JSON.parse(await fs.readFile(path.join(packageRoot, 'package.json'), 'utf8'));
41-
const packageImportPath =
42-
reactNativeConfig?.packageImportPath || `import ${packageName}.${nativePackageClassName};`;
43-
const packageInstance = reactNativeConfig?.packageInstance || `new ${nativePackageClassName}()`;
4456
const buildTypes = reactNativeConfig?.buildTypes || [];
4557
const dependencyConfiguration = reactNativeConfig?.dependencyConfiguration;
4658
const libraryName =
@@ -75,6 +87,7 @@ export async function resolveDependencyConfigImplAndroidAsync(
7587
cxxModuleCMakeListsModuleName,
7688
cxxModuleCMakeListsPath,
7789
cxxModuleHeaderName,
90+
isPureCxxDependency,
7891
};
7992
if (!result.libraryName) {
8093
delete result.libraryName;

packages/expo-modules-autolinking/src/reactNativeConfig/reactNativeConfig.types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface RNConfigCommandOptions {
1616
*/
1717
export interface RNConfigDependencyAndroid {
1818
sourceDir: string;
19-
packageImportPath: string;
20-
packageInstance: string;
19+
packageImportPath: string | null;
20+
packageInstance: string | null;
2121
dependencyConfiguration?: string;
2222
buildTypes: string[];
2323
libraryName?: string | null;
@@ -26,6 +26,7 @@ export interface RNConfigDependencyAndroid {
2626
cxxModuleCMakeListsModuleName?: string | null;
2727
cxxModuleCMakeListsPath?: string | null;
2828
cxxModuleHeaderName?: string | null;
29+
isPureCxxDependency?: boolean;
2930
}
3031

3132
/**

0 commit comments

Comments
 (0)