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: 'RNCWebViewImpl.m',
31          find: /\b(_SwizzleHelperWK)\b/g,
32          replaceWith: `${prefix}$1`,
33        },
34        {
35          // see issue: https://github.com/expo/expo/issues/4463
36          paths: 'RNCWebViewImpl.m',
37          find: /MessageHandlerName = @"ABI\d+_\d+_\d+ReactNativeWebView";/,
38          replaceWith: `MessageHandlerName = @"ReactNativeWebView";`,
39        },
40        {
41          paths: 'RNCWebViewImpl.m',
42          find: 'NSString *const CUSTOM_SELECTOR',
43          replaceWith: 'static NSString *const CUSTOM_SELECTOR',
44        },
45      ],
46    },
47    'react-native-reanimated': {
48      path: [
49        {
50          find: /\b(ReanimatedSensor)/g,
51          replaceWith: `${prefix}$1`,
52        },
53      ],
54      content: [
55        {
56          find: 'namespace reanimated',
57          replaceWith: `namespace ${prefix}reanimated`,
58        },
59        {
60          find: /\breanimated::/g,
61          replaceWith: `${prefix}reanimated::`,
62        },
63        {
64          paths: '*.h',
65          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
66          replaceWith: `ReactCommon/${prefix}`,
67        },
68        {
69          paths: '**/Transitioning/*.m',
70          find: `RCTConvert+${prefix}REATransition.h`,
71          replaceWith: 'RCTConvert+REATransition.h',
72        },
73        {
74          paths: 'REAUIManager.{h,mm}',
75          find: /(blockSetter|_toBeRemovedRegister|_parentMapper|_animationsManager|_scheduler)/g,
76          replaceWith: `${prefix}$1`,
77        },
78        {
79          paths: 'REATransitionAnimation.m',
80          find: /(SimAnimationDragCoefficient)\(/g,
81          replaceWith: `${prefix}$1(`,
82        },
83        {
84          paths: 'REAAnimationsManager.m',
85          find: /^(#import <.*React)\/UIView\+(.+)\.h>/gm,
86          replaceWith: `$1/${prefix}UIView+$2.h>`,
87        },
88        {
89          paths: 'REAAnimationsManager.m',
90          // `dataComponenetsByName[@"ABI44_0_0RCTView"];` -> `dataComponenetsByName[@"RCTView"];`
91          // the RCTComponentData internal view name is not versioned
92          find: new RegExp(`(RCTComponentData .+)\\[@"${prefix}(RCT.+)"\\];`, 'g'),
93          replaceWith: '$1[@"$2"];',
94        },
95        {
96          paths: ['**/sensor/**', 'NativeProxy.mm'],
97          find: /\b(ReanimatedSensor)/g,
98          replaceWith: `${prefix}$1`,
99        },
100        {
101          paths: 'REANodesManager.mm',
102          find: /\b(ComponentUpdate)\b/g,
103          replaceWith: `${prefix}$1`,
104        },
105        {
106          paths: 'REASnapshot.m',
107          find: /^(const int (ScreenStackPresentationModal|DEFAULT_MODAL_TOP_OFFSET))/gm,
108          replaceWith: `static $1`,
109        },
110        {
111          paths: [
112            'NativeProxy.mm',
113            'ReanimatedRuntime.h',
114            'ReanimatedRuntime.cpp',
115            'ReanimatedHermesRuntime.h',
116            'ReanimatedHermesRuntime.cpp',
117            'REAMessageThread.h',
118          ],
119          find: new RegExp(
120            `(__has_include\\(|#import\\s+|#include\\s+)<(cxxreact|reacthermes)\\/(${prefix})?(MessageQueueThread|HermesExecutorFactory)(\\.h>\\)?)`,
121            'g'
122          ),
123          replaceWith: `$1<${prefix}$2/${prefix}$4$5`,
124        },
125        {
126          paths: ['ReanimatedRuntime.h', 'ReanimatedHermesRuntime.h'],
127          find: `        <reacthermes/${prefix}HermesExecutorFactory.h>) || __has_include(<hermes/hermes.h>))`,
128          replaceWith: `        <${prefix}reacthermes/${prefix}HermesExecutorFactory.h>) || __has_include(<hermes/hermes.h>))`,
129        },
130        {
131          paths: ['ReanimatedHermesRuntime.h', 'ReanimatedHermesRuntime.cpp'],
132          find: /^((#if __has_include|#include).+\/)(RuntimeAdapter|Registration)(\.h>)$/gm,
133          replaceWith: `$1${prefix}$3$4`,
134        },
135        {
136          paths: 'RCTAppDelegate+Reanimated.h',
137          find: new RegExp(`<${prefix}React-${prefix}RCTAppDelegate/`, 'g'),
138          replaceWith: `<${prefix}React-RCTAppDelegate/`,
139        },
140        {
141          paths: 'RCTAppDelegate+Reanimated.h',
142          find: new RegExp(
143            `(#if __has_include\\(|#import )<${prefix}React-cxxreact/cxxreact/JSExecutor\\.h>`,
144            'g'
145          ),
146          replaceWith: `$1<${prefix}React-cxxreact/${prefix}cxxreact/${prefix}JSExecutor.h>`,
147        },
148        {
149          // Workaround for jsi somehow be transformed back to unversioned path
150          find: /^#include <jsi\/jsi\.h>/gm,
151          replaceWith: `#include <${prefix}jsi/${prefix}jsi.h>`,
152        },
153        {
154          paths: 'RNReanimated.podspec.json',
155          find: /(REACT_NATIVE_MINOR_VERSION|REANIMATED_VERSION)/g,
156          replaceWith: `${prefix}$1`,
157        },
158        {
159          paths: 'RNReanimated.podspec.json',
160          find: new RegExp(
161            `\\/react-native-lab\\/react-native\\/packages\\/react-native\\/${prefix}ReactCommon`,
162            'g'
163          ),
164          replaceWith: `/ios/versioned-react-native/${prefix}/ReactNative/ReactCommon`,
165        },
166      ],
167    },
168    'react-native-gesture-handler': {
169      path: [
170        {
171          find: /\bRN(\w+?)\.(h|m|mm)/,
172          replaceWith: `${prefix}RN$1.$2`,
173        },
174      ],
175      content: [
176        {
177          // `RNG*` symbols are already prefixed at this point,
178          // but there are some new symbols in RNGH that don't have "G".
179          paths: '*.{h,m,mm}',
180          find: /\bRN(\w+?)\b/g,
181          replaceWith: `${prefix}RN$1`,
182        },
183        {
184          paths: 'RNGestureHandler.m',
185          find: /UIGestureRecognizer \(GestureHandler\)/g,
186          replaceWith: `UIGestureRecognizer (${prefix}GestureHandler)`,
187        },
188        {
189          paths: 'RNGestureHandler.m',
190          find: /gestureHandler/g,
191          replaceWith: `${prefix}gestureHandler`,
192        },
193      ],
194    },
195    'react-native-pager-view': {
196      path: [
197        {
198          find: /(ReactNativePageView|ReactViewPagerManager)\.(h|m)/,
199          replaceWith: `${prefix}$1.$2`,
200        },
201      ],
202      content: [
203        {
204          find: `${prefix}JKBigInteger.h`,
205          replaceWith: `JKBigInteger.h`,
206        },
207      ],
208    },
209    'react-native-screens': {
210      content: [],
211    },
212    '@shopify/react-native-skia': {
213      path: [
214        {
215          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager|SkiaUIView|SkiaPictureViewManager|SkiaDomViewManager|ViewScreenshotService)/g,
216          replaceWith: `${prefix}$1`,
217        },
218      ],
219      content: [
220        {
221          paths: '*.h',
222          find: new RegExp(`ReactCommon/(?!${prefix})`, 'g'),
223          replaceWith: `ReactCommon/${prefix}`,
224        },
225        {
226          find: /\b(DisplayLink|PlatformContext|SkiaDrawView|SkiaDrawViewManager|SkiaManager|RNJsi|SkiaUIView|SkiaPictureViewManager|SkiaDomViewManager|ViewScreenshotService)/g,
227          replaceWith: `${prefix}$1`,
228        },
229        {
230          find: /RCT_EXPORT_MODULE\((SkiaDomView)\)/g,
231          replaceWith: `RCT_EXPORT_MODULE(${prefix}$1)`,
232        },
233        {
234          // The module name in bridge should be unversioned `RNSkia`
235          paths: '*.mm',
236          find: new RegExp(`(\\smoduleForName:@")${prefix}(RNSkia")`, 'g'),
237          replaceWith: '$1$2',
238        },
239        {
240          // __typename__ exposed to js should be unversioned
241          find: new RegExp(
242            `(\\bJSI_PROPERTY_GET\\(__typename__\\) \\{\\n\\s*return jsi::String::createFromUtf8\\(runtime, ")${prefix}(.*")`,
243            'gm'
244          ),
245          replaceWith: '$1$2',
246        },
247      ],
248    },
249    'react-native-svg': {
250      content: [
251        {
252          find: new RegExp(`\\b(${prefix}RCTConvert)\\+${prefix}(RNSVG\.h)`, 'g'),
253          replaceWith: `$1+$2`,
254        },
255        {
256          paths: 'RNSVGRenderable.mm',
257          find: /\b(saturate)\(/g,
258          replaceWith: `${prefix}$1(`,
259        },
260        {
261          paths: 'RNSVGPainter.mm',
262          find: /\b(PatternFunction)\b/g,
263          replaceWith: `${prefix}$1`,
264        },
265        {
266          paths: 'RNSVGFontData.mm',
267          find: /\b(AbsoluteFontWeight|bolder|lighter|nearestFontWeight)\(/gi,
268          replaceWith: `${prefix}$1(`,
269        },
270        {
271          paths: 'RNSVGTSpan.mm',
272          find: new RegExp(`\\b(${prefix}RNSVGTopAlignedLabel\\s*\\*\\s*label)\\b`, 'gi'),
273          replaceWith: 'static $1',
274        },
275        {
276          paths: 'RNSVGMarker.mm',
277          find: /\b(deg2rad)\b/g,
278          replaceWith: `${prefix}$1`,
279        },
280        {
281          paths: 'RNSVGMarkerPosition.mm',
282          find: /\b(PathIsDone|rad2deg|SlopeAngleRadians|CurrentAngle|subtract|ExtractPathElementFeatures|UpdateFromPathElement)\b/g,
283          replaceWith: `${prefix}$1`,
284        },
285        {
286          paths: 'RNSVGMarkerPosition.mm',
287          find: /\b(positions_|element_index_|origin_|subpath_start_|in_slope_|out_slope_|auto_start_reverse_)\b/g,
288          replaceWith: `${prefix}$1`,
289        },
290        {
291          paths: 'RNSVGPathMeasure.mm',
292          find: /\b(distance|subdivideBezierAtT)\b/g,
293          replaceWith: `${prefix}$1`,
294        },
295      ],
296    },
297  };
298}
299