Skip to content

Commit

Permalink
fix kotlin module detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed Apr 19, 2024
1 parent 19cba6e commit 5389f90
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/core/hooks/android/extractors/class-declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ export function extractClassDeclarationForModule(file: string) {

let ktModuleMatch =
file.match(
/class\s+(\w+)(\s+|)\(.*\)(\s+|):(\s+|)ReactContextBaseJavaModule/gm
/class\s+(\w+)(\s+|)\(.*\)(\s+|):(\s+|)ReactContextBaseJavaModule/
) ||
file.match(/class\s+(\w+)(\s+|)\(.*\)(\s+|):(\s+|)(\w+Spec)/g);
file.match(/class\s+(\w+)(\s+|)(\s+|):(\s+|)(ViewGroupManager)/) ||
file.match(/class\s+(\w+)(\s+|)\(.*\)(\s+|):(\s+|)(\w+Spec)/);

return ktModuleMatch;
}
1 change: 1 addition & 0 deletions packages/core/hooks/android/extractors/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export async function extractPackageModules(folder: string) {
const superclassName = moduleClassSignature.match(
/(?:extends\s+|\s+:\s+)(\w+)/
)?.[1];

// if (!superclassName) {
// continue;
// }
Expand Down
4 changes: 3 additions & 1 deletion packages/core/hooks/android/getters/module-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const MODULE_NAME_ANNOTATION = /(?<=@ReactModule\(name.*=).*(?=\))/gm;
function resolveKtModuleName(moduleContents: string) {
return (
moduleContents
.match(/(?<=override fun getName\(\)\s+=).*(?=)/gm)?.[0]
.match(/(?<=override fun getName\(\)(:\s+String|)\s+=).*(?=)/gm)?.[0]
?.trim() ||
moduleContents
.match(ANDROID_GET_NAME_FN)?.[0]
Expand Down Expand Up @@ -40,6 +40,8 @@ export function getModuleName(
? resolveKtModuleName(moduleContents)
: resolveJavaModuleName(moduleContents);



// The module doesn't have a getName() method at all. It may be a spec, or not
// a ReactModule in the first place.
if (!getNameFunctionReturnValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function loadModuleContents(modulePath: string) {
const contents = readFileSync(modulePath, { encoding: 'utf-8' });
const matchedPrivateMethods = contents.match(ANDROID_PRIVATE_METHOD_REGEX);
let updatedContents = contents;
if (modulePath.endsWith('.kt')) {
if (modulePath.endsWith('.kt') && !contents.includes('//#kotlin')) {
updatedContents += `\n//#kotlin`;
}

Expand Down

0 comments on commit 5389f90

Please sign in to comment.