diff --git a/packages/core/hooks/android/extractors/class-declaration.ts b/packages/core/hooks/android/extractors/class-declaration.ts index 690b351..9137e62 100644 --- a/packages/core/hooks/android/extractors/class-declaration.ts +++ b/packages/core/hooks/android/extractors/class-declaration.ts @@ -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; } diff --git a/packages/core/hooks/android/extractors/modules.ts b/packages/core/hooks/android/extractors/modules.ts index 3c979a2..42202a7 100644 --- a/packages/core/hooks/android/extractors/modules.ts +++ b/packages/core/hooks/android/extractors/modules.ts @@ -67,6 +67,7 @@ export async function extractPackageModules(folder: string) { const superclassName = moduleClassSignature.match( /(?:extends\s+|\s+:\s+)(\w+)/ )?.[1]; + // if (!superclassName) { // continue; // } diff --git a/packages/core/hooks/android/getters/module-name.ts b/packages/core/hooks/android/getters/module-name.ts index 0e099c4..0489830 100644 --- a/packages/core/hooks/android/getters/module-name.ts +++ b/packages/core/hooks/android/getters/module-name.ts @@ -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] @@ -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) { diff --git a/packages/core/hooks/android/writers/load-module-contents.ts b/packages/core/hooks/android/writers/load-module-contents.ts index 7b4df96..3ac2753 100644 --- a/packages/core/hooks/android/writers/load-module-contents.ts +++ b/packages/core/hooks/android/writers/load-module-contents.ts @@ -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`; }