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: 'RCTView.m', 51 replace: /\b(SwitchAccessibilityTrait)\b/g, 52 with: `${versionName}$1`, 53 }, 54 { 55 paths: 'RCTSpringAnimation.m', 56 replace: /\b(MAX_DELTA_TIME)\b/g, 57 with: `${versionName}$1`, 58 }, 59 { 60 paths: 'ModuleRegistry.cpp', 61 replace: /(std::string normalizeName\(std::string name\) \{)/, 62 with: `$1\n if (name.compare(0, ${versionName.length}, "${versionName}") == 0) {\n name = name.substr(${versionName.length});\n }\n`, 63 }, 64 { 65 paths: 'ModuleRegistry.cpp', 66 replace: /(\(name\.compare\(\d+, \d+, ")([^"]+)(RCT"\))/, 67 with: '$1$3', 68 }, 69 { 70 paths: ['RCTSRWebSocket.h', 'UIView+Private.h'], 71 replace: /@interface (\w+) \((CertificateAdditions|Private)\)/g, 72 with: `@interface $1 (${versionName}$2)`, 73 }, 74 { 75 // Fix prefixing imports from React-bridging 76 paths: 'ReactCommon', 77 replace: new RegExp(`(React)\\/${versionName}(bridging)\\/`, 'g'), 78 with: `$1/$2/${versionName}`, 79 }, 80 { 81 // Codegen adds methods to `RCTCxxConvert` that start with `JS_`, which refer to `JS::` 82 // C++ namespace that we prefix, so these methods must be prefixed as well. 83 paths: ['FBReactNativeSpec.h', 'FBReactNativeSpec-generated.mm'], 84 replace: /(RCTManagedPointer \*\))(JS_)/g, 85 with: `$1${versionName}$2`, 86 }, 87 88 // Universal modules 89 { 90 paths: `UniversalModules/${versionName}EXScoped`, 91 replace: /(EXScopedABI\d+_\d+_\d+ReactNative)/g, 92 with: 'EXScopedReactNative', 93 }, 94 { 95 paths: `${versionName}EXFileSystem`, 96 replace: new RegExp(`NSData\\+${versionName}EXFileSystem\\.h`, 'g'), 97 with: `${versionName}NSData+EXFileSystem.h`, 98 }, 99 { 100 paths: [ 101 `${versionName}EXNotifications`, 102 `${versionName}EXUpdates`, 103 `${versionName}EXJSONUtils`, 104 ], 105 replace: new RegExp( 106 `NSDictionary\\+${versionName}(EXNotificationsVerifyingClass|EXJSONUtils)\\.h`, 107 'g' 108 ), 109 with: `${versionName}NSDictionary+$1.h`, 110 }, 111 { 112 paths: [ 113 `${versionName}EXNotifications`, 114 `${versionName}EXAppState`, 115 `${versionName}EXVersionManager`, 116 ], 117 replace: new RegExp(`EXModuleRegistryHolder${versionName}React`, 'g'), 118 with: 'EXModuleRegistryHolderReact', 119 }, 120 { 121 // Versioned ExpoKit has to use versioned modules provider 122 paths: 'EXVersionManager.mm', 123 replace: /@"(ExpoModulesProvider)"/, 124 with: `@"${versionName}$1"`, 125 }, 126 { 127 paths: `${versionName}EXVersionManager.mm`, 128 replace: `#import <${versionName}Reacthermes/HermesExecutorFactory.h>`, 129 with: `#import <${versionName}reacthermes/${versionName}HermesExecutorFactory.h>`, 130 }, 131 132 // react-native-maps 133 { 134 paths: 'AIRMapWMSTile', 135 replace: /\b(TileOverlay)\b/g, 136 with: `${versionName}$1`, 137 }, 138 { 139 paths: 'AIRGoogleMapWMSTile', 140 replace: /\b(WMSTileOverlay)\b/g, 141 with: `${versionName}$1`, 142 }, 143 144 // react-native-svg 145 { 146 paths: 'RNSVGRenderable.m', 147 replace: /\b(saturate)\(/g, 148 with: `${versionName}$1(`, 149 }, 150 { 151 paths: 'RNSVGPainter.m', 152 replace: /\b(PatternFunction)\b/g, 153 with: `${versionName}$1`, 154 }, 155 { 156 paths: 'RNSVGFontData.m', 157 replace: /\b(AbsoluteFontWeight|bolder|lighter|nearestFontWeight)\(/gi, 158 with: `${versionName}$1(`, 159 }, 160 { 161 paths: 'RNSVGTSpan.m', 162 replace: new RegExp(`\\b(${versionName}RNSVGTopAlignedLabel\\s*\\*\\s*label)\\b`, 'gi'), 163 with: 'static $1', 164 }, 165 { 166 paths: 'RNSVGMarker.m', 167 replace: /\b(deg2rad)\b/g, 168 with: `${versionName}$1`, 169 }, 170 { 171 paths: 'RNSVGMarkerPosition.m', 172 replace: 173 /\b(PathIsDone|rad2deg|SlopeAngleRadians|CurrentAngle|subtract|ExtractPathElementFeatures|UpdateFromPathElement)\b/g, 174 with: `${versionName}$1`, 175 }, 176 { 177 paths: 'RNSVGMarkerPosition.m', 178 replace: 179 /\b(positions_|element_index_|origin_|subpath_start_|in_slope_|out_slope_|auto_start_reverse_)\b/g, 180 with: `${versionName}$1`, 181 }, 182 { 183 paths: 'RNSVGPathMeasure.m', 184 replace: /\b(distance|subdivideBezierAtT)\b/g, 185 with: `${versionName}$1`, 186 }, 187 188 // react-native-webview 189 { 190 paths: 'RNCWebView.m', 191 replace: new RegExp(`#import "objc/${versionName}runtime\\.h"`, ''), 192 with: '#import "objc/runtime.h"', 193 }, 194 { 195 paths: 'RNCWebView.m', 196 replace: /\b(_SwizzleHelperWK)\b/g, 197 with: `${versionName}$1`, 198 }, 199 { 200 // see issue: https://github.com/expo/expo/issues/4463 201 paths: 'RNCWebView.m', 202 replace: /MessageHandlerName = @"ABI\d+_\d+_\d+ReactNativeWebView";/, 203 with: `MessageHandlerName = @"ReactNativeWebView";`, 204 }, 205 { 206 paths: 'EXVersionManager.mm', 207 replace: /\[(RNCWebView)/, 208 with: `[${versionName}$1`, 209 }, 210 211 // react-native-reanimated 212 { 213 paths: 'EXVersionManager.mm', 214 replace: /(_bridge_reanimated)/g, 215 with: `${versionName}$1`, 216 }, 217 { 218 paths: 'EXVersionManager.mm', 219 replace: /\b(REA)/g, 220 with: `${versionName}$1`, 221 }, 222 { 223 paths: 'NativeProxy.mm', 224 replace: /@"ABI\d+_\d+_\d+RCTView"/g, 225 with: `@"RCTView"`, 226 }, 227 228 // react-native-shared-element 229 { 230 paths: 'RNSharedElementNode.m', 231 replace: /\b(NSArray\s*\*\s*_imageResolvers)\b/, 232 with: 'static $1', 233 }, 234 235 // react-native-safe-area-context 236 { 237 paths: [ 238 'RNCSafeAreaUtils.h', 239 'RNCSafeAreaUtils.m', 240 'RNCSafeAreaProvider.m', 241 'RNCSafeAreaView.m', 242 ], 243 replace: /\b(UIEdgeInsetsEqualToEdgeInsetsWithThreshold)\b/g, 244 with: `${versionName}$1`, 245 }, 246 ], 247 }; 248} 249