From 81ab0a3d9a1654d9897a42071ab0eb1c0bf497da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Fri, 24 Nov 2023 06:40:10 +0100 Subject: [PATCH] fix(rn-072): fix generated code to be compatible with { + const filePath = path.join(dir, file); + const fileExtension = path.extname(file); + if (fileExtension === '.java') { + let fileContent = fs.readFileSync(filePath, 'utf-8'); + let newFileContent = fileContent.replace( + /extends ReactContextBaseJavaModule implements TurboModule/g, + 'extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule', + ); + if (fileContent !== newFileContent) { + // also insert an import line with `import com.facebook.react.bridge.ReactModuleWithSpec;` + newFileContent = newFileContent.replace( + /import com.facebook.react.bridge.ReactMethod;/, + 'import com.facebook.react.bridge.ReactMethod;\nimport com.facebook.react.bridge.ReactModuleWithSpec;', + ); + + console.log(' => fixOldArchJava applied to:', filePath); + fs.writeFileSync(filePath, newFileContent, 'utf-8'); + } + } else if (fs.lstatSync(filePath).isDirectory()) { + fixOldArchJavaForRN72Compat(filePath); + } + }); +} + async function generateCodegenJavaOldArch() { exec(`rm -rf ${GENERATED_DIR} ${OLD_ARCH_DIR}`); exec(`mkdir -p ${GENERATED_DIR}/source/codegen/`); @@ -35,6 +63,7 @@ async function generateCodegenJavaOldArch() { `node ${RN_DIR}/scripts/generate-specs-cli.js --platform android --schemaPath ${GENERATED_DIR}/source/codegen/schema.json --outputDir ${GENERATED_DIR}/source/codegen --libraryName rnmapbox_maps_specs --javaPackageName com.rnmapbox.rnmbx`, ); + fixOldArchJavaForRN72Compat(`${GENERATED_DIR}/source/codegen/java/`); exec(`cp -rf ${GENERATED_DIR}/source/codegen/java/ ${OLD_ARCH_DIR}/`); }