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/versioned-react-native/packages/react-native/packages').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/versioned-react-native/packages/react-native/packages/react-native').toFile()`, 61 replaceWith: `def reactNativeRootDir = Paths.get(projectDir.getPath(), '../../../../versioned-react-native/packages/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: 85 '$rootDir/../react-native-lab/react-native/packages/react-native/ReactAndroid/gradle.properties', 86 }, 87 { 88 paths: 'CMakeLists.txt', 89 find: /\b(hermes-engine::libhermes)/g, 90 replaceWith: `$1_${prefix}`, 91 }, 92 { 93 paths: 'NativeProxyCommon.java', 94 find: new RegExp(`\\b(?<!${prefix}\\.)(com.swmansion.gesturehandler.)`, 'g'), 95 replaceWith: `${prefix}.$1`, 96 }, 97 { 98 paths: '**/*.{java,kt}', 99 find: new RegExp(`\\b(?<!${prefix}\\.)(com.swmansion.reanimated.R\\.)`, 'g'), 100 replaceWith: `${prefix}.$1`, 101 }, 102 ], 103 }, 104 '@react-native-async-storage/async-storage': { 105 content: [ 106 { 107 find: /\b(import (static )?)(com.reactnativecommunity.asyncstorage.)/g, 108 replaceWith: `$1${prefix}.$3`, 109 }, 110 ], 111 }, 112 'react-native-pager-view': { 113 content: [ 114 { 115 find: /\b(import (static )?)(com.reactnativepagerview.)/g, 116 replaceWith: `$1${prefix}.$3`, 117 }, 118 ], 119 }, 120 }; 121} 122 123export function exponentPackageTransforms(prefix: string): Record<string, StringTransform[]> { 124 return { 125 '@shopify/react-native-skia': [ 126 { 127 find: /\bimport (com.shopify.reactnative.skia.RNSkiaPackage)/g, 128 replaceWith: `import ${prefix}.$1`, 129 }, 130 ], 131 '@shopify/flash-list': [ 132 { 133 find: /\bimport (com.shopify.reactnative.flash_list.ReactNativeFlashListPackage)/g, 134 replaceWith: `import ${prefix}.$1`, 135 }, 136 ], 137 '@react-native-community/slider': [ 138 { 139 find: /\bimport (com\.reactnativecommunity\.slider)/g, 140 replaceWith: `import ${prefix}.$1`, 141 }, 142 ], 143 'react-native-gesture-handler': [ 144 { 145 find: /\bimport (com.swmansion.gesturehandler)/g, 146 replaceWith: `import ${prefix}.$1`, 147 }, 148 ], 149 'react-native-screens': [ 150 { 151 find: /\bimport (com.swmansion.rnscreens)/g, 152 replaceWith: `import ${prefix}.$1`, 153 }, 154 ], 155 'react-native-svg': [ 156 { 157 find: /\bimport (com.horcrux.svg)/g, 158 replaceWith: `import ${prefix}.$1`, 159 }, 160 ], 161 '@react-native-async-storage/async-storage': [ 162 { 163 find: /\bimport (com.reactnativecommunity.asyncstorage.)/g, 164 replaceWith: `import ${prefix}.$1`, 165 }, 166 ], 167 'react-native-pager-view': [ 168 { 169 find: /\bimport (com.reactnativepagerview.)/g, 170 replaceWith: `import ${prefix}.$1`, 171 }, 172 ], 173 }; 174} 175