1import { FileTransforms } from '../../../Transforms.types'; 2 3const objcFilesPattern = '*.{h,m,mm}'; 4const swiftFilesPattern = '*.swift'; 5 6export function expoModulesTransforms(prefix: string): FileTransforms { 7 return { 8 path: [ 9 // Here we prefix names of Objective-C/C++ files. 10 // There is no need to do the same for Swift files 11 // as we don't change the symbols inside. In Swift we don't use `EX` nor `UM` 12 // for symbols as the framework name takes part of the symbol signature, 13 // so there is no way we'll get duplicate symbols compilation errors. 14 // Files starting with `Expo` needs to be prefixed though, 15 // for umbrella headers (e.g. `ExpoModulesCore.h`). 16 { 17 find: /\b(Expo|EX|UM)([^/]*\.)(h|m|mm|cpp)\b/, 18 replaceWith: `${prefix}$1$2$3`, 19 }, 20 ], 21 content: [ 22 { 23 find: /\bReact/g, 24 replaceWith: `${prefix}React`, 25 }, 26 { 27 // Prefix symbols and imports. 28 find: /\b(EX|UM|RCT)/g, 29 replaceWith: `${prefix}$1`, 30 }, 31 32 // Only Swift 33 34 { 35 paths: swiftFilesPattern, 36 find: /\bimport (Expo|EX)(\w+)/g, 37 replaceWith: `import ${prefix}$1$2`, 38 }, 39 { 40 paths: swiftFilesPattern, 41 find: /@objc\((Expo|EX)\)/g, 42 replaceWith: `@objc(${prefix}$1)`, 43 }, 44 45 // Only Objective-C 46 47 { 48 // Prefix `Expo*` frameworks in imports. 49 paths: objcFilesPattern, 50 find: /#import <(Expo.*?)\//g, 51 replaceWith: `#import <${prefix}$1/`, 52 }, 53 { 54 paths: objcFilesPattern, 55 find: /#import <(.*?)\/(Expo.*?)\.h>/g, 56 replaceWith: `#import <$1/${prefix}$2.h>`, 57 }, 58 { 59 // Rename Swift compatibility headers from frameworks starting with `Expo`. 60 paths: objcFilesPattern, 61 find: /#import "(Expo.+?)-Swift\.h"/g, 62 replaceWith: `#import "${prefix}$1-Swift.h"`, 63 }, 64 { 65 // Unprefix imports to unversionable (e.g. expo-gl-cpp) modules. 66 paths: [objcFilesPattern, 'EXGL'], 67 find: new RegExp(`#import <${prefix}(EXGL_CPP)\\b`), 68 replaceWith: '#import <$1', 69 }, 70 ], 71 }; 72} 73