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: '*.m',
13          find: /RCT_EXTERN_MODULE\((ApplePayButtonManager|CardFieldManager|AuBECSDebitFormManager|StripeSdk|StripeContainerManager|CardFormManager)/,
14          replaceWith: `RCT_EXTERN_REMAP_MODULE($1, ${prefix}$1`,
15        },
16        {
17          paths: '',
18          find: /\.reactFocus\(/,
19          replaceWith: `.${prefix.toLowerCase()}ReactFocus(`,
20        },
21      ],
22    },
23    'lottie-react-native': {
24      content: [
25        {
26          paths: 'LRNAnimationViewManagerObjC.m',
27          find: /RCT_EXTERN_MODULE\(/,
28          replaceWith: `RCT_EXTERN_REMAP_MODULE(LottieAnimationView, ${prefix}`,
29        },
30        {
31          paths: 'ContainerView.swift',
32          find: /\breactSetFrame/g,
33          replaceWith: `${prefix.toLowerCase()}ReactSetFrame`,
34        },
35      ],
36    },
37    'react-native-webview': {
38      content: [
39        {
40          paths: 'RNCWebView.m',
41          find: new RegExp(`#import "objc/${prefix}runtime\\.h"`, ''),
42          replaceWith: '#import "objc/runtime.h"',
43        },
44        {
45          paths: 'RNCWebView.m',
46          find: /\b(_SwizzleHelperWK)\b/g,
47          replaceWith: `${prefix}$1`,
48        },
49        {
50          // see issue: https://github.com/expo/expo/issues/4463
51          paths: 'RNCWebView.m',
52          find: /MessageHandlerName = @"ABI\d+_\d+_\d+ReactNativeWebView";/,
53          replaceWith: `MessageHandlerName = @"ReactNativeWebView";`,
54        },
55        {
56          paths: 'RNCWebView.m',
57          find: 'NSString *const CUSTOM_SELECTOR',
58          replaceWith: 'static NSString *const CUSTOM_SELECTOR',
59        },
60      ],
61    },
62    'react-native-reanimated': {
63      path: [
64        {
65          find: /\b(ReanimatedSensor)/g,
66          replaceWith: `${prefix}$1`,
67        },
68      ],
69      content: [
70        {
71          find: 'namespace reanimated',
72          replaceWith: `namespace ${prefix}reanimated`,
73        },
74        {
75          find: /\breanimated::/g,
76          replaceWith: `${prefix}reanimated::`,
77        },
78        {
79          paths: '*.h',
80          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
81          replaceWith: `ReactCommon/${prefix}`,
82        },
83        {
84          paths: '**/Transitioning/*.m',
85          find: `RCTConvert+${prefix}REATransition.h`,
86          replaceWith: 'RCTConvert+REATransition.h',
87        },
88        {
89          paths: 'REAUIManager.{h,mm}',
90          find: /(blockSetter|_toBeRemovedRegister|_parentMapper|_animationsManager|_scheduler)/g,
91          replaceWith: `${prefix}$1`,
92        },
93        {
94          paths: 'REATransitionAnimation.m',
95          find: /(SimAnimationDragCoefficient)\(/g,
96          replaceWith: `${prefix}$1(`,
97        },
98        {
99          paths: 'REAAnimationsManager.m',
100          find: /^(#import <.*React)\/UIView\+(.+)\.h>/gm,
101          replaceWith: `$1/${prefix}UIView+$2.h>`,
102        },
103        {
104          paths: 'REAAnimationsManager.m',
105          find: `UIView+${prefix}React.h`,
106          replaceWith: `UIView+React.h`,
107        },
108        {
109          paths: 'REAAnimationsManager.m',
110          // `dataComponenetsByName[@"ABI44_0_0RCTView"];` -> `dataComponenetsByName[@"RCTView"];`
111          // the RCTComponentData internal view name is not versioned
112          find: new RegExp(`(RCTComponentData .+)\\[@"${prefix}(RCT.+)"\\];`, 'g'),
113          replaceWith: '$1[@"$2"];',
114        },
115        {
116          paths: ['**/sensor/**', 'NativeProxy.mm'],
117          find: /\b(ReanimatedSensor)/g,
118          replaceWith: `${prefix}$1`,
119        },
120        {
121          paths: 'REANodesManager.m',
122          find: /\b(ComponentUpdate)\b/g,
123          replaceWith: `${prefix}$1`,
124        },
125      ],
126    },
127    'react-native-gesture-handler': {
128      path: [
129        {
130          find: /\bRN(\w+?)\.(h|m|mm)/,
131          replaceWith: `${prefix}RN$1.$2`,
132        },
133      ],
134      content: [
135        {
136          find: `UIView+${prefix}React.h`,
137          replaceWith: `${prefix}UIView+React.h`,
138        },
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}',
143          find: /\bRN(\w+?)\b/g,
144          replaceWith: `${prefix}RN$1`,
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: `UIView+${prefix}React.h`,
158          replaceWith: `${prefix}UIView+React.h`,
159        },
160        {
161          find: `${prefix}JKBigInteger.h`,
162          replaceWith: `JKBigInteger.h`,
163        },
164      ],
165    },
166    '@react-native-segmented-control/segmented-control': {
167      content: [
168        {
169          find: `UIView+${prefix}React.h`,
170          replaceWith: `${prefix}UIView+React.h`,
171        },
172      ],
173    },
174    'react-native-screens': {
175      content: [],
176    },
177    '@shopify/react-native-skia': {
178      path: [
179        {
180          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager)/g,
181          replaceWith: `${prefix}$1`,
182        },
183      ],
184      content: [
185        {
186          paths: '*.h',
187          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
188          replaceWith: `ReactCommon/${prefix}`,
189        },
190        {
191          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager|RNJsi)/g,
192          replaceWith: `${prefix}$1`,
193        },
194        {
195          // The module name in bridge should be unversioned `RNSkia`
196          paths: 'SkiaDrawViewManager.mm',
197          find: new RegExp(`(\\smoduleForName:@")${prefix}(RNSkia")`, 'g'),
198          replaceWith: '$1$2',
199        },
200        {
201          // __typename__ exposed to js should be unversioned
202          find: new RegExp(
203            `(\\bJSI_PROPERTY_GET\\(__typename__\\) \\{\\n\\s*return jsi::String::createFromUtf8\\(runtime, ")${prefix}(.*")`,
204            'gm'
205          ),
206          replaceWith: '$1$2',
207        },
208      ],
209    },
210  };
211}
212