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    },
121    'react-native-gesture-handler': {
122      path: [
123        {
124          find: /\bRN(\w+?)\.(h|m|mm)/,
125          replaceWith: `${prefix}RN$1.$2`,
126        },
127      ],
128      content: [
129        {
130          // `RNG*` symbols are already prefixed at this point,
131          // but there are some new symbols in RNGH that don't have "G".
132          paths: '*.{h,m,mm}',
133          find: /\bRN(\w+?)\b/g,
134          replaceWith: `${prefix}RN$1`,
135        },
136        {
137          paths: 'RNGestureHandler.m',
138          find: /UIGestureRecognizer \(GestureHandler\)/g,
139          replaceWith: `UIGestureRecognizer (${prefix}GestureHandler)`,
140        },
141        {
142          paths: 'RNGestureHandler.m',
143          find: /gestureHandler/g,
144          replaceWith: `${prefix}gestureHandler`,
145        },
146      ],
147    },
148    'react-native-pager-view': {
149      path: [
150        {
151          find: /(ReactNativePageView|ReactViewPagerManager)\.(h|m)/,
152          replaceWith: `${prefix}$1.$2`,
153        },
154      ],
155      content: [
156        {
157          find: `${prefix}JKBigInteger.h`,
158          replaceWith: `JKBigInteger.h`,
159        },
160      ],
161    },
162    'react-native-screens': {
163      content: [],
164    },
165    '@shopify/react-native-skia': {
166      path: [
167        {
168          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager|SkiaUIView|SkiaPictureViewManager)/g,
169          replaceWith: `${prefix}$1`,
170        },
171      ],
172      content: [
173        {
174          paths: '*.h',
175          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
176          replaceWith: `ReactCommon/${prefix}`,
177        },
178        {
179          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager|RNJsi|SkiaUIView|SkiaPictureViewManager)/g,
180          replaceWith: `${prefix}$1`,
181        },
182        {
183          // The module name in bridge should be unversioned `RNSkia`
184          paths: 'SkiaDrawViewManager.mm',
185          find: new RegExp(`(\\smoduleForName:@")${prefix}(RNSkia")`, 'g'),
186          replaceWith: '$1$2',
187        },
188        {
189          // __typename__ exposed to js should be unversioned
190          find: new RegExp(
191            `(\\bJSI_PROPERTY_GET\\(__typename__\\) \\{\\n\\s*return jsi::String::createFromUtf8\\(runtime, ")${prefix}(.*")`,
192            'gm'
193          ),
194          replaceWith: '$1$2',
195        },
196      ],
197    },
198    'react-native-svg': {
199      content: [
200        {
201          find: new RegExp(`\\b(${prefix}RCTConvert)\\+${prefix}(RNSVG\.h)`, 'g'),
202          replaceWith: `$1+$2`,
203        },
204        {
205          paths: 'RNSVGRenderable.mm',
206          find: /\b(saturate)\(/g,
207          replaceWith: `${prefix}$1(`,
208        },
209        {
210          paths: 'RNSVGPainter.mm',
211          find: /\b(PatternFunction)\b/g,
212          replaceWith: `${prefix}$1`,
213        },
214        {
215          paths: 'RNSVGFontData.mm',
216          find: /\b(AbsoluteFontWeight|bolder|lighter|nearestFontWeight)\(/gi,
217          replaceWith: `${prefix}$1(`,
218        },
219        {
220          paths: 'RNSVGTSpan.mm',
221          find: new RegExp(`\\b(${prefix}RNSVGTopAlignedLabel\\s*\\*\\s*label)\\b`, 'gi'),
222          replaceWith: 'static $1',
223        },
224        {
225          paths: 'RNSVGMarker.mm',
226          find: /\b(deg2rad)\b/g,
227          replaceWith: `${prefix}$1`,
228        },
229        {
230          paths: 'RNSVGMarkerPosition.mm',
231          find: /\b(PathIsDone|rad2deg|SlopeAngleRadians|CurrentAngle|subtract|ExtractPathElementFeatures|UpdateFromPathElement)\b/g,
232          replaceWith: `${prefix}$1`,
233        },
234        {
235          paths: 'RNSVGMarkerPosition.mm',
236          find: /\b(positions_|element_index_|origin_|subpath_start_|in_slope_|out_slope_|auto_start_reverse_)\b/g,
237          replaceWith: `${prefix}$1`,
238        },
239        {
240          paths: 'RNSVGPathMeasure.mm',
241          find: /\b(distance|subdivideBezierAtT)\b/g,
242          replaceWith: `${prefix}$1`,
243        },
244      ],
245    },
246  };
247}
248