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(project(":ReactAndroid:hermes-engine"))`, 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 paths: 'build.gradle', 94 // The `android/versioned-react-native/ReactAndroid/gradle.properties` is not committed to git, 95 // we use the `react-native-lab/react-native/ReactAndroid/gradle.properties` instead. 96 find: 'file("$reactNativeRootDir/ReactAndroid/gradle.properties")', 97 replaceWith: 98 'file("$reactNativeRootDir/../../react-native-lab/react-native/ReactAndroid/gradle.properties")', 99 }, 100 ], 101 }, 102 }; 103} 104 105export function exponentPackageTransforms(prefix: string): Record<string, StringTransform[]> { 106 return { 107 '@shopify/react-native-skia': [ 108 { 109 find: /\bimport (com.shopify.reactnative.skia.RNSkiaPackage)/g, 110 replaceWith: `import ${prefix}.$1`, 111 }, 112 ], 113 '@shopify/flash-list': [ 114 { 115 find: /\bimport (com.shopify.reactnative.flash_list.ReactNativeFlashListPackage)/g, 116 replaceWith: `import ${prefix}.$1`, 117 }, 118 ], 119 '@react-native-community/slider': [ 120 { 121 find: /\bimport (com\.reactnativecommunity\.slider)/g, 122 replaceWith: `import ${prefix}.$1`, 123 }, 124 ], 125 'react-native-gesture-handler': [ 126 { 127 find: /\bimport (com.swmansion.gesturehandler)/g, 128 replaceWith: `import ${prefix}.$1`, 129 }, 130 ], 131 'react-native-screens': [ 132 { 133 find: /\bimport (com.swmansion.rnscreens)/g, 134 replaceWith: `import ${prefix}.$1`, 135 }, 136 ], 137 'react-native-svg': [ 138 { 139 find: /\bimport (com.horcrux.svg)/g, 140 replaceWith: `import ${prefix}.$1`, 141 }, 142 ], 143 }; 144} 145