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 // Universal modules 76 { 77 paths: `UniversalModules/${versionName}EXScoped`, 78 replace: /(EXScopedABI\d+_\d+_\d+ReactNative)/g, 79 with: 'EXScopedReactNative', 80 }, 81 { 82 paths: `${versionName}EXFileSystem`, 83 replace: new RegExp(`NSData\\+${versionName}EXFileSystem\\.h`, 'g'), 84 with: `${versionName}NSData+EXFileSystem.h`, 85 }, 86 { 87 paths: `${versionName}EXNotifications`, 88 replace: new RegExp(`NSDictionary\\+${versionName}EXNotificationsVerifyingClass\\.h`, 'g'), 89 with: `${versionName}NSDictionary+EXNotificationsVerifyingClass.h`, 90 }, 91 92 // react-native-maps 93 { 94 paths: 'AIRMapWMSTile', 95 replace: /\b(TileOverlay)\b/g, 96 with: `${versionName}$1`, 97 }, 98 { 99 paths: 'AIRGoogleMapWMSTile', 100 replace: /\b(WMSTileOverlay)\b/g, 101 with: `${versionName}$1`, 102 }, 103 104 // react-native-svg 105 { 106 paths: 'RNSVGRenderable.m', 107 replace: /\b(saturate)\(/g, 108 with: `${versionName}$1(`, 109 }, 110 { 111 paths: 'RNSVGPainter.m', 112 replace: /\b(PatternFunction)\b/g, 113 with: `${versionName}$1`, 114 }, 115 { 116 paths: 'RNSVGFontData.m', 117 replace: /\b(AbsoluteFontWeight|bolder|lighter|nearestFontWeight)\(/gi, 118 with: `${versionName}$1(`, 119 }, 120 { 121 paths: 'RNSVGTSpan.m', 122 replace: /\b(TopAlignedLabel\s*\*\s*label)\b/gi, 123 with: 'static $1', 124 }, 125 { 126 paths: 'RNSVGTSpan.m', 127 replace: /\b(TopAlignedLabel)\b/gi, 128 with: `${versionName}$1`, 129 }, 130 { 131 paths: 'RNSVGMarker.m', 132 replace: /\b(deg2rad)\b/g, 133 with: `${versionName}$1`, 134 }, 135 { 136 paths: 'RNSVGMarkerPosition.m', 137 replace: /\b(PathIsDone|rad2deg|SlopeAngleRadians|CurrentAngle|subtract|ExtractPathElementFeatures|UpdateFromPathElement)\b/g, 138 with: `${versionName}$1`, 139 }, 140 { 141 paths: 'RNSVGMarkerPosition.m', 142 replace: /\b(positions_|element_index_|origin_|subpath_start_|in_slope_|out_slope_|auto_start_reverse_)\b/g, 143 with: `${versionName}$1`, 144 }, 145 { 146 paths: 'RNSVGPathMeasure.m', 147 replace: /\b(distance|subdivideBezierAtT)\b/g, 148 with: `${versionName}$1`, 149 }, 150 151 // react-native-webview 152 { 153 paths: 'RNCWebView.m', 154 replace: new RegExp(`#import "objc/${versionName}runtime\\.h"`, ''), 155 with: '#import "objc/runtime.h"', 156 }, 157 { 158 paths: 'RNCWebView.m', 159 replace: /\b(_SwizzleHelperWK)\b/g, 160 with: `${versionName}$1`, 161 }, 162 { 163 // see issue: https://github.com/expo/expo/issues/4463 164 paths: 'RNCWebView.m', 165 replace: /MessageHandlerName = @"ABI\d+_\d+_\d+ReactNativeWebView";/, 166 with: `MessageHandlerName = @"ReactNativeWebView";`, 167 }, 168 169 // react-native-reanimated 170 { 171 paths: 'REATransitionAnimation.m', 172 replace: /(SimAnimationDragCoefficient)\(/g, 173 with: `${versionName}$1(`, 174 }, 175 { 176 paths: 'Reanimated', 177 replace: /(_bridge_reanimated)/g, 178 with: `${versionName}$1`, 179 }, 180 { 181 paths: 'EXVersionManager.mm', 182 replace: /(_bridge_reanimated)/g, 183 with: `${versionName}$1`, 184 }, 185 { 186 paths: 'NativeProxy.mm', 187 replace: /@"ABI\d+_\d+_\d+RCTView"/g, 188 with: `@"RCTView"`, 189 }, 190 191 // react-native-shared-element 192 { 193 paths: 'RNSharedElementNode.m', 194 replace: /\b(NSArray\s*\*\s*_imageResolvers)\b/, 195 with: 'static $1', 196 }, 197 198 // react-native-safe-area-context 199 { 200 paths: [ 201 'RCTView+SafeAreaCompat.h', 202 'RCTView+SafeAreaCompat.m', 203 'RNCSafeAreaProvider.m', 204 'RNCSafeAreaView.m', 205 ], 206 replace: /\b(UIEdgeInsetsEqualToEdgeInsetsWithThreshold)\b/g, 207 with: `${versionName}$1`, 208 }, 209 ], 210 }; 211} 212