Skip to content

Commit

Permalink
perf: skip getting package class name inside expo module (#2487)
Browse files Browse the repository at this point in the history
* perf: skip getting package class name inside expo module

* fix: move early return

* fix: replace condition validating expo package with `*Package.kt/java` check
  • Loading branch information
szymonrybczak authored Aug 31, 2024
1 parent a99b27e commit 4573eca
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/cli-platform-android/src/config/findPackageClassName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,29 @@ export default function getPackageClassName(folder: string) {
let files = getMainActivityFiles(folder);
let packages = getClassNameMatches(files, folder);

if (!packages.length) {
files = getMainActivityFiles(folder, false);
packages = getClassNameMatches(files, folder);
if (packages && packages.length > 0 && Array.isArray(packages[0])) {
return packages[0][1];
}

/*
When module contains `expo-module.config.json` we return null
because expo modules follow other practices and don't implement
ReactPackage/TurboReactPackage directly, so it doesn't make sense
to scan and read hundreds of files to get package class name.
Exception is `expo` package itself which contains `expo-module.config.json`
and implements `ReactPackage/TurboReactPackage`.
Following logic is done due to performance optimization.
*/

if (fs.existsSync(path.join(folder, '..', 'expo-module.config.json'))) {
return null;
}

files = getMainActivityFiles(folder, false);
packages = getClassNameMatches(files, folder);

// @ts-ignore
return packages.length ? packages[0][1] : null;
}
Expand Down

0 comments on commit 4573eca

Please sign in to comment.