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