1import { FileTransforms, StringTransform } from '../../../Transforms.types'; 2 3export function vendoredModulesTransforms(prefix: string): Record<string, FileTransforms> { 4 const sdkVersion = prefix.replace(/abi(\d+)_0_0/, 'sdk$1'); 5 return { 6 '@shopify/react-native-skia': { 7 content: [ 8 { 9 paths: 'build.gradle', 10 find: `def nodeModules = Paths.get(projectDir.getPath(), '../../../../../..', 'react-native-lab').toString()`, 11 replaceWith: `def nodeModules = Paths.get(projectDir.getPath(), '../../../../..').toString()`, 12 }, 13 { 14 paths: 'build.gradle', 15 find: 'sourceBuild = true', 16 replaceWith: 'sourceBuild = false', 17 }, 18 { 19 paths: 'build.gradle', 20 // The `android/versioned-react-native/ReactAndroid/gradle.properties` is not committed to git, 21 // we use the `ReactAndroid/gradle.properties` for versioned skia instead. 22 // Even though it not always correct, e.g. when ReactAndroid upgrades to newer version, the versions are inconsistent. 23 // Since skia current only uses the `REACT_NATIVE_VERSION` property, 24 // after we prebuild the lib and cleanup CMakeLists.txt, these properties are actually not be used. 25 find: '$nodeModules/versioned-react-native/ReactAndroid/gradle.properties', 26 replaceWith: '$defaultDir/gradle.properties', 27 }, 28 ], 29 }, 30 'react-native-svg': { 31 content: [ 32 { 33 paths: 'build.gradle', 34 find: /(implementation 'host.exp:reactandroid-abi\d+_0_0:1\.0\.0')/g, 35 replaceWith: 36 '$1\n' + 37 " compileOnly 'com.facebook.fresco:fresco:+'\n" + 38 " compileOnly 'com.facebook.fresco:imagepipeline-okhttp3:+'\n" + 39 " compileOnly 'com.facebook.fresco:ui-common:+'", 40 }, 41 { 42 find: /\b(import (static )?)(com.horcrux.)/g, 43 replaceWith: `$1${prefix}.$3`, 44 }, 45 ], 46 }, 47 'react-native-gesture-handler': { 48 content: [ 49 { 50 paths: 'build.gradle', 51 find: /vendored_unversioned_react-native-reanimated/g, 52 replaceWith: `vendored_${sdkVersion}_react-native-reanimated`, 53 }, 54 ], 55 }, 56 'react-native-reanimated': { 57 content: [ 58 { 59 paths: 'build.gradle', 60 find: `def reactNativeRootDir = Paths.get(projectDir.getPath(), '../../../../../react-native-lab/react-native').toFile()`, 61 replaceWith: `def reactNativeRootDir = Paths.get(projectDir.getPath(), '../../../../versioned-react-native').toFile()`, 62 }, 63 { 64 paths: 'build.gradle', 65 find: `compileOnly "com.facebook.react:hermes-android:\${REACT_NATIVE_VERSION}"`, 66 replaceWith: 67 `if (file("\${reactNativeRootDir}/ReactAndroid/hermes-engine/build/outputs/aar/hermes-engine-release.aar").exists()) {\n` + 68 ` compileOnly(files("\${reactNativeRootDir}/ReactAndroid/hermes-engine/build/outputs/aar/hermes-engine-release.aar"))\n` + 69 ` }\n` + 70 ` compileOnly 'androidx.swiperefreshlayout:swiperefreshlayout:+'`, 71 }, 72 { 73 paths: 'build.gradle', 74 transform: (text: string) => 75 text + `\nandroid.packagingOptions.excludes.add("**/libhermes*.so")`, 76 }, 77 { 78 paths: 'build.gradle', 79 // The `android/versioned-react-native/ReactAndroid/gradle.properties` is not committed to git, 80 // we use the `ReactAndroid/gradle.properties` for versioned reanimated instead. 81 // Even though it not always correct, e.g. when ReactAndroid upgrades to newer version, the versions are inconsistent. 82 // Since reanimated doesn't use these properties for react-native 0.71, that should be safe. 83 find: '$reactNativeRootDir/ReactAndroid/gradle.properties', 84 replaceWith: '$rootDir/../react-native-lab/react-native/ReactAndroid/gradle.properties', 85 }, 86 { 87 paths: 'CMakeLists.txt', 88 find: /\b(hermes-engine::libhermes)/g, 89 replaceWith: `$1_${prefix}`, 90 }, 91 { 92 paths: 'NativeProxy.java', 93 find: new RegExp(`\\b(?<!${prefix}\\.)(com.swmansion.gesturehandler.)`, 'g'), 94 replaceWith: `${prefix}.$1`, 95 }, 96 { 97 paths: '**/*.{java,kt}', 98 find: new RegExp(`\\b(?<!${prefix}\\.)(com.swmansion.reanimated.R\\.)`, 'g'), 99 replaceWith: `${prefix}.$1`, 100 }, 101 ], 102 }, 103 '@react-native-async-storage/async-storage': { 104 content: [ 105 { 106 find: /\b(import (static )?)(com.reactnativecommunity.asyncstorage.)/g, 107 replaceWith: `$1${prefix}.$3`, 108 }, 109 ], 110 }, 111 'react-native-pager-view': { 112 content: [ 113 { 114 find: /\b(import (static )?)(com.reactnativepagerview.)/g, 115 replaceWith: `$1${prefix}.$3`, 116 }, 117 ], 118 }, 119 }; 120} 121 122export function exponentPackageTransforms(prefix: string): Record<string, StringTransform[]> { 123 return { 124 '@shopify/react-native-skia': [ 125 { 126 find: /\bimport (com.shopify.reactnative.skia.RNSkiaPackage)/g, 127 replaceWith: `import ${prefix}.$1`, 128 }, 129 ], 130 '@shopify/flash-list': [ 131 { 132 find: /\bimport (com.shopify.reactnative.flash_list.ReactNativeFlashListPackage)/g, 133 replaceWith: `import ${prefix}.$1`, 134 }, 135 ], 136 '@react-native-community/slider': [ 137 { 138 find: /\bimport (com\.reactnativecommunity\.slider)/g, 139 replaceWith: `import ${prefix}.$1`, 140 }, 141 ], 142 'react-native-gesture-handler': [ 143 { 144 find: /\bimport (com.swmansion.gesturehandler)/g, 145 replaceWith: `import ${prefix}.$1`, 146 }, 147 ], 148 'react-native-screens': [ 149 { 150 find: /\bimport (com.swmansion.rnscreens)/g, 151 replaceWith: `import ${prefix}.$1`, 152 }, 153 ], 154 'react-native-svg': [ 155 { 156 find: /\bimport (com.horcrux.svg)/g, 157 replaceWith: `import ${prefix}.$1`, 158 }, 159 ], 160 '@react-native-async-storage/async-storage': [ 161 { 162 find: /\bimport (com.reactnativecommunity.asyncstorage.)/g, 163 replaceWith: `import ${prefix}.$1`, 164 }, 165 ], 166 'react-native-pager-view': [ 167 { 168 find: /\bimport (com.reactnativepagerview.)/g, 169 replaceWith: `import ${prefix}.$1`, 170 }, 171 ], 172 }; 173} 174