1import chalk from 'chalk'; 2 3import { TransformPipeline } from '.'; 4 5export function postTransforms(versionName: string): TransformPipeline { 6 return { 7 logHeader(filePath: string) { 8 console.log(`Post-transforming ${chalk.magenta(filePath)}:`); 9 }, 10 transforms: [ 11 // react-native 12 { 13 paths: ['RCTRedBox.m', 'RCTLog.mm'], 14 replace: /#if (ABI\d+_\d+_\d+)RCT_DEBUG/g, 15 with: '#if $1RCT_DEV', 16 }, 17 { 18 paths: ['NSTextStorage+FontScaling.h', 'NSTextStorage+FontScaling.m'], 19 replace: /NSTextStorage \(FontScaling\)/, 20 with: `NSTextStorage (${versionName}FontScaling)`, 21 }, 22 { 23 paths: [ 24 'NSTextStorage+FontScaling.h', 25 'NSTextStorage+FontScaling.m', 26 'RCTTextShadowView.m', 27 ], 28 replace: /\b(scaleFontSizeToFitSize|scaleFontSizeWithRatio|compareToSize)\b/g, 29 with: `${versionName.toLowerCase()}_rct_$1`, 30 }, 31 { 32 paths: 'RCTWebView.m', 33 replace: /@"ABI\d+_\d+_\d+React-js-navigation"/, 34 with: '@"react-js-navigation"', 35 }, 36 { 37 replace: new RegExp(`FB${versionName}ReactNativeSpec`, 'g'), 38 with: 'FBReactNativeSpec', 39 }, 40 { 41 replace: new RegExp('\\b(Native\\w+Spec)\\b', 'g'), 42 with: `${versionName}$1`, 43 }, 44 { 45 paths: 'RCTInspectorPackagerConnection.m', 46 replace: /\b(RECONNECT_DELAY_MS)\b/g, 47 with: `${versionName}$1`, 48 }, 49 { 50 paths: `${versionName}FBReactNativeSpec`, 51 replace: /\b(NSStringToNativeAppearanceColorSchemeName|NativeAppearanceColorSchemeNameToNSString)\b/g, 52 with: `${versionName}$1`, 53 }, 54 { 55 paths: 'RCTView.m', 56 replace: /\b(SwitchAccessibilityTrait)\b/g, 57 with: `${versionName}$1`, 58 }, 59 { 60 paths: 'RCTSpringAnimation.m', 61 replace: /\b(MAX_DELTA_TIME)\b/g, 62 with: `${versionName}$1`, 63 }, 64 { 65 paths: 'ModuleRegistry.cpp', 66 replace: /(std::string normalizeName\(std::string name\) \{)/, 67 with: `$1\n if (name.compare(0, ${versionName.length}, "${versionName}") == 0) {\n name = name.substr(${versionName.length});\n }\n`, 68 }, 69 { 70 paths: 'ModuleRegistry.cpp', 71 replace: /(\(name\.compare\(\d+, \d+, ")([^"]+)(RCT"\))/, 72 with: '$1$3', 73 }, 74 { 75 paths: ['RCTSRWebSocket.h', 'UIView+Private.h'], 76 replace: /@interface (\w+) \((CertificateAdditions|Private)\)/g, 77 with: `@interface $1 (${versionName}$2)` 78 }, 79 80 // Universal modules 81 { 82 paths: `UniversalModules/${versionName}EXScoped`, 83 replace: /(EXScopedABI\d+_\d+_\d+ReactNative)/g, 84 with: 'EXScopedReactNative', 85 }, 86 { 87 paths: `${versionName}EXFileSystem`, 88 replace: new RegExp(`NSData\\+${versionName}EXFileSystem\\.h`, 'g'), 89 with: `${versionName}NSData+EXFileSystem.h`, 90 }, 91 { 92 paths: [ 93 `${versionName}EXNotifications`, 94 `${versionName}EXUpdates`, 95 `${versionName}EXJSONUtils`, 96 ], 97 replace: new RegExp( 98 `NSDictionary\\+${versionName}(EXNotificationsVerifyingClass|EXJSONUtils)\\.h`, 99 'g' 100 ), 101 with: `${versionName}NSDictionary+$1.h`, 102 }, 103 { 104 paths: [`${versionName}EXNotifications`, `${versionName}EXAppState`], 105 replace: new RegExp(`EXModuleRegistryHolder${versionName}React`, 'g'), 106 with: 'EXModuleRegistryHolderReact', 107 }, 108 { 109 // Versioned ExpoKit has to use versioned modules provider 110 paths: 'EXVersionManager.mm', 111 replace: /@"(ExpoModulesProvider)"/, 112 with: `@"${versionName}$1"`, 113 }, 114 115 // react-native-maps 116 { 117 paths: 'AIRMapWMSTile', 118 replace: /\b(TileOverlay)\b/g, 119 with: `${versionName}$1`, 120 }, 121 { 122 paths: 'AIRGoogleMapWMSTile', 123 replace: /\b(WMSTileOverlay)\b/g, 124 with: `${versionName}$1`, 125 }, 126 127 // react-native-svg 128 { 129 paths: 'RNSVGRenderable.m', 130 replace: /\b(saturate)\(/g, 131 with: `${versionName}$1(`, 132 }, 133 { 134 paths: 'RNSVGPainter.m', 135 replace: /\b(PatternFunction)\b/g, 136 with: `${versionName}$1`, 137 }, 138 { 139 paths: 'RNSVGFontData.m', 140 replace: /\b(AbsoluteFontWeight|bolder|lighter|nearestFontWeight)\(/gi, 141 with: `${versionName}$1(`, 142 }, 143 { 144 paths: 'RNSVGTSpan.m', 145 replace: new RegExp(`\\b(${versionName}RNSVGTopAlignedLabel\\s*\\*\\s*label)\\b`, 'gi'), 146 with: 'static $1', 147 }, 148 { 149 paths: 'RNSVGMarker.m', 150 replace: /\b(deg2rad)\b/g, 151 with: `${versionName}$1`, 152 }, 153 { 154 paths: 'RNSVGMarkerPosition.m', 155 replace: /\b(PathIsDone|rad2deg|SlopeAngleRadians|CurrentAngle|subtract|ExtractPathElementFeatures|UpdateFromPathElement)\b/g, 156 with: `${versionName}$1`, 157 }, 158 { 159 paths: 'RNSVGMarkerPosition.m', 160 replace: /\b(positions_|element_index_|origin_|subpath_start_|in_slope_|out_slope_|auto_start_reverse_)\b/g, 161 with: `${versionName}$1`, 162 }, 163 { 164 paths: 'RNSVGPathMeasure.m', 165 replace: /\b(distance|subdivideBezierAtT)\b/g, 166 with: `${versionName}$1`, 167 }, 168 169 // react-native-webview 170 { 171 paths: 'RNCWebView.m', 172 replace: new RegExp(`#import "objc/${versionName}runtime\\.h"`, ''), 173 with: '#import "objc/runtime.h"', 174 }, 175 { 176 paths: 'RNCWebView.m', 177 replace: /\b(_SwizzleHelperWK)\b/g, 178 with: `${versionName}$1`, 179 }, 180 { 181 // see issue: https://github.com/expo/expo/issues/4463 182 paths: 'RNCWebView.m', 183 replace: /MessageHandlerName = @"ABI\d+_\d+_\d+ReactNativeWebView";/, 184 with: `MessageHandlerName = @"ReactNativeWebView";`, 185 }, 186 { 187 paths: 'EXVersionManager.mm', 188 replace: /\[(RNCWebView)/, 189 with: `[${versionName}$1`, 190 }, 191 192 // react-native-reanimated 193 { 194 paths: 'EXVersionManager.mm', 195 replace: /(_bridge_reanimated)/g, 196 with: `${versionName}$1`, 197 }, 198 { 199 paths: 'EXVersionManager.mm', 200 replace: /\b(REA)/g, 201 with: `${versionName}$1`, 202 }, 203 { 204 paths: 'NativeProxy.mm', 205 replace: /@"ABI\d+_\d+_\d+RCTView"/g, 206 with: `@"RCTView"`, 207 }, 208 209 // react-native-shared-element 210 { 211 paths: 'RNSharedElementNode.m', 212 replace: /\b(NSArray\s*\*\s*_imageResolvers)\b/, 213 with: 'static $1', 214 }, 215 216 // react-native-safe-area-context 217 { 218 paths: [ 219 'RCTView+SafeAreaCompat.h', 220 'RCTView+SafeAreaCompat.m', 221 'RNCSafeAreaProvider.m', 222 'RNCSafeAreaView.m', 223 ], 224 replace: /\b(UIEdgeInsetsEqualToEdgeInsetsWithThreshold)\b/g, 225 with: `${versionName}$1`, 226 }, 227 ], 228 }; 229} 230