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