1import { FileTransforms } from '../../../Transforms.types';
2
3type Config = {
4  [key: string]: FileTransforms;
5};
6
7export default function vendoredModulesTransformsFactory(prefix: string): Config {
8  return {
9    '@stripe/stripe-react-native': {
10      content: [
11        {
12          paths: '',
13          find: /\.reactFocus\(/,
14          replaceWith: `.${prefix.toLowerCase()}ReactFocus(`,
15        },
16      ],
17    },
18    'lottie-react-native': {
19      content: [
20        {
21          paths: 'ContainerView.swift',
22          find: /\breactSetFrame/g,
23          replaceWith: `${prefix.toLowerCase()}ReactSetFrame`,
24        },
25      ],
26    },
27    'react-native-webview': {
28      content: [
29        {
30          paths: 'RNCWebView.m',
31          find: new RegExp(`#import "objc/${prefix}runtime\\.h"`, ''),
32          replaceWith: '#import "objc/runtime.h"',
33        },
34        {
35          paths: 'RNCWebView.m',
36          find: /\b(_SwizzleHelperWK)\b/g,
37          replaceWith: `${prefix}$1`,
38        },
39        {
40          // see issue: https://github.com/expo/expo/issues/4463
41          paths: 'RNCWebView.m',
42          find: /MessageHandlerName = @"ABI\d+_\d+_\d+ReactNativeWebView";/,
43          replaceWith: `MessageHandlerName = @"ReactNativeWebView";`,
44        },
45        {
46          paths: 'RNCWebView.m',
47          find: 'NSString *const CUSTOM_SELECTOR',
48          replaceWith: 'static NSString *const CUSTOM_SELECTOR',
49        },
50      ],
51    },
52    'react-native-reanimated': {
53      path: [
54        {
55          find: /\b(ReanimatedSensor)/g,
56          replaceWith: `${prefix}$1`,
57        },
58      ],
59      content: [
60        {
61          find: 'namespace reanimated',
62          replaceWith: `namespace ${prefix}reanimated`,
63        },
64        {
65          find: /\breanimated::/g,
66          replaceWith: `${prefix}reanimated::`,
67        },
68        {
69          paths: '*.h',
70          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
71          replaceWith: `ReactCommon/${prefix}`,
72        },
73        {
74          paths: '**/Transitioning/*.m',
75          find: `RCTConvert+${prefix}REATransition.h`,
76          replaceWith: 'RCTConvert+REATransition.h',
77        },
78        {
79          paths: 'REAUIManager.{h,mm}',
80          find: /(blockSetter|_toBeRemovedRegister|_parentMapper|_animationsManager|_scheduler)/g,
81          replaceWith: `${prefix}$1`,
82        },
83        {
84          paths: 'REATransitionAnimation.m',
85          find: /(SimAnimationDragCoefficient)\(/g,
86          replaceWith: `${prefix}$1(`,
87        },
88        {
89          paths: 'REAAnimationsManager.m',
90          find: /^(#import <.*React)\/UIView\+(.+)\.h>/gm,
91          replaceWith: `$1/${prefix}UIView+$2.h>`,
92        },
93        {
94          paths: 'REAAnimationsManager.m',
95          // `dataComponenetsByName[@"ABI44_0_0RCTView"];` -> `dataComponenetsByName[@"RCTView"];`
96          // the RCTComponentData internal view name is not versioned
97          find: new RegExp(`(RCTComponentData .+)\\[@"${prefix}(RCT.+)"\\];`, 'g'),
98          replaceWith: '$1[@"$2"];',
99        },
100        {
101          paths: ['**/sensor/**', 'NativeProxy.mm'],
102          find: /\b(ReanimatedSensor)/g,
103          replaceWith: `${prefix}$1`,
104        },
105        {
106          paths: 'REANodesManager.m',
107          find: /\b(ComponentUpdate)\b/g,
108          replaceWith: `${prefix}$1`,
109        },
110        {
111          // versioning reacthermes import
112          paths: 'NativeProxy.mm',
113          find: new RegExp(
114            `(#if\\s+__has_include\\(|#import\\s+)<reacthermes\\/${prefix}HermesExecutorFactory.h>`,
115            'g'
116          ),
117          replaceWith: `$1<${prefix}reacthermes/${prefix}HermesExecutorFactory.h>`,
118        },
119        {
120          paths: '**/*.{h,mm}',
121          find: new RegExp(`${prefix}(REACT_NATIVE_MINOR_VERSION)`, 'g'),
122          replaceWith: '$1',
123        },
124        {
125          paths: 'RNReanimated.podspec.json',
126          find: /(REANIMATED_VERSION)/g,
127          replaceWith: `${prefix}$1`,
128        },
129      ],
130    },
131    'react-native-gesture-handler': {
132      path: [
133        {
134          find: /\bRN(\w+?)\.(h|m|mm)/,
135          replaceWith: `${prefix}RN$1.$2`,
136        },
137      ],
138      content: [
139        {
140          // `RNG*` symbols are already prefixed at this point,
141          // but there are some new symbols in RNGH that don't have "G".
142          paths: '*.{h,m,mm}',
143          find: /\bRN(\w+?)\b/g,
144          replaceWith: `${prefix}RN$1`,
145        },
146        {
147          paths: 'RNGestureHandler.m',
148          find: /UIGestureRecognizer \(GestureHandler\)/g,
149          replaceWith: `UIGestureRecognizer (${prefix}GestureHandler)`,
150        },
151        {
152          paths: 'RNGestureHandler.m',
153          find: /gestureHandler/g,
154          replaceWith: `${prefix}gestureHandler`,
155        },
156      ],
157    },
158    'react-native-pager-view': {
159      path: [
160        {
161          find: /(ReactNativePageView|ReactViewPagerManager)\.(h|m)/,
162          replaceWith: `${prefix}$1.$2`,
163        },
164      ],
165      content: [
166        {
167          find: `${prefix}JKBigInteger.h`,
168          replaceWith: `JKBigInteger.h`,
169        },
170      ],
171    },
172    'react-native-screens': {
173      content: [],
174    },
175    '@shopify/react-native-skia': {
176      path: [
177        {
178          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager|SkiaUIView|SkiaPictureViewManager|SkiaDomViewManager)/g,
179          replaceWith: `${prefix}$1`,
180        },
181      ],
182      content: [
183        {
184          paths: '*.h',
185          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
186          replaceWith: `ReactCommon/${prefix}`,
187        },
188        {
189          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager|RNJsi|SkiaUIView|SkiaPictureViewManager|SkiaDomViewManager)/g,
190          replaceWith: `${prefix}$1`,
191        },
192        {
193          find: /RCT_EXPORT_MODULE\((SkiaDomView)\)/g,
194          replaceWith: `RCT_EXPORT_MODULE(${prefix}$1)`,
195        },
196        {
197          // The module name in bridge should be unversioned `RNSkia`
198          paths: '*.mm',
199          find: new RegExp(`(\\smoduleForName:@")${prefix}(RNSkia")`, 'g'),
200          replaceWith: '$1$2',
201        },
202        {
203          // __typename__ exposed to js should be unversioned
204          find: new RegExp(
205            `(\\bJSI_PROPERTY_GET\\(__typename__\\) \\{\\n\\s*return jsi::String::createFromUtf8\\(runtime, ")${prefix}(.*")`,
206            'gm'
207          ),
208          replaceWith: '$1$2',
209        },
210      ],
211    },
212    'react-native-svg': {
213      content: [
214        {
215          find: new RegExp(`\\b(${prefix}RCTConvert)\\+${prefix}(RNSVG\.h)`, 'g'),
216          replaceWith: `$1+$2`,
217        },
218        {
219          paths: 'RNSVGRenderable.mm',
220          find: /\b(saturate)\(/g,
221          replaceWith: `${prefix}$1(`,
222        },
223        {
224          paths: 'RNSVGPainter.mm',
225          find: /\b(PatternFunction)\b/g,
226          replaceWith: `${prefix}$1`,
227        },
228        {
229          paths: 'RNSVGFontData.mm',
230          find: /\b(AbsoluteFontWeight|bolder|lighter|nearestFontWeight)\(/gi,
231          replaceWith: `${prefix}$1(`,
232        },
233        {
234          paths: 'RNSVGTSpan.mm',
235          find: new RegExp(`\\b(${prefix}RNSVGTopAlignedLabel\\s*\\*\\s*label)\\b`, 'gi'),
236          replaceWith: 'static $1',
237        },
238        {
239          paths: 'RNSVGMarker.mm',
240          find: /\b(deg2rad)\b/g,
241          replaceWith: `${prefix}$1`,
242        },
243        {
244          paths: 'RNSVGMarkerPosition.mm',
245          find: /\b(PathIsDone|rad2deg|SlopeAngleRadians|CurrentAngle|subtract|ExtractPathElementFeatures|UpdateFromPathElement)\b/g,
246          replaceWith: `${prefix}$1`,
247        },
248        {
249          paths: 'RNSVGMarkerPosition.mm',
250          find: /\b(positions_|element_index_|origin_|subpath_start_|in_slope_|out_slope_|auto_start_reverse_)\b/g,
251          replaceWith: `${prefix}$1`,
252        },
253        {
254          paths: 'RNSVGPathMeasure.mm',
255          find: /\b(distance|subdivideBezierAtT)\b/g,
256          replaceWith: `${prefix}$1`,
257        },
258      ],
259    },
260  };
261}
262