customerio-expo-plugin 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -1
- package/plugin/lib/commonjs/helpers/constants/ios.js +76 -8
- package/plugin/lib/commonjs/helpers/constants/ios.js.map +1 -1
- package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js +20 -7
- package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js.map +1 -1
- package/plugin/lib/commonjs/index.js +7 -0
- package/plugin/lib/commonjs/index.js.map +1 -1
- package/plugin/lib/commonjs/ios/withCIOIosSwift.js +18 -12
- package/plugin/lib/commonjs/ios/withCIOIosSwift.js.map +1 -1
- package/plugin/lib/commonjs/postInstallHelper.js +58 -11
- package/plugin/lib/commonjs/postInstallHelper.js.map +1 -1
- package/plugin/lib/commonjs/utils/resolveRNSDK.js +97 -0
- package/plugin/lib/commonjs/utils/resolveRNSDK.js.map +1 -0
- package/plugin/lib/commonjs/utils/writeExpoVersion.js +56 -0
- package/plugin/lib/commonjs/utils/writeExpoVersion.js.map +1 -0
- package/plugin/lib/module/helpers/constants/ios.js +75 -8
- package/plugin/lib/module/helpers/constants/ios.js.map +1 -1
- package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js +20 -7
- package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js.map +1 -1
- package/plugin/lib/module/index.js +7 -0
- package/plugin/lib/module/index.js.map +1 -1
- package/plugin/lib/module/ios/withCIOIosSwift.js +18 -12
- package/plugin/lib/module/ios/withCIOIosSwift.js.map +1 -1
- package/plugin/lib/module/postInstallHelper.js +58 -11
- package/plugin/lib/module/postInstallHelper.js.map +1 -1
- package/plugin/lib/module/utils/resolveRNSDK.js +88 -0
- package/plugin/lib/module/utils/resolveRNSDK.js.map +1 -0
- package/plugin/lib/module/utils/writeExpoVersion.js +48 -0
- package/plugin/lib/module/utils/writeExpoVersion.js.map +1 -0
- package/plugin/lib/typescript/helpers/constants/ios.d.ts +18 -0
- package/plugin/lib/typescript/helpers/utils/injectCIOPodfileCode.d.ts +11 -1
- package/plugin/lib/typescript/utils/resolveRNSDK.d.ts +7 -0
- package/plugin/lib/typescript/utils/writeExpoVersion.d.ts +3 -0
- package/plugin/src/helpers/constants/ios.ts +87 -8
- package/plugin/src/helpers/utils/injectCIOPodfileCode.ts +22 -10
- package/plugin/src/index.ts +7 -0
- package/plugin/src/ios/withCIOIosSwift.ts +25 -12
- package/plugin/src/postInstallHelper.js +75 -17
- package/plugin/src/utils/resolveRNSDK.ts +118 -0
- package/plugin/src/utils/writeExpoVersion.ts +62 -0
|
@@ -332,29 +332,35 @@ const addDidFailToRegisterForRemoteNotificationsWithError = content => {
|
|
|
332
332
|
|
|
333
333
|
/**
|
|
334
334
|
* Add deep link handling for killed state
|
|
335
|
-
*
|
|
336
|
-
*
|
|
335
|
+
*
|
|
336
|
+
* On modern Expo Swift templates, RN is bootstrapped by `factory.startReactNative(...)`
|
|
337
|
+
* inside an `#if os(iOS) || os(tvOS)` guard, *before* the trailing `return super.application(...)`.
|
|
338
|
+
* The deep-link block must run before that call so `modifiedLaunchOptions` flows into RN's
|
|
339
|
+
* initial launchOptions; otherwise the workaround is a no-op.
|
|
340
|
+
*
|
|
341
|
+
* For older templates (no `factory.startReactNative` — `super.application(...)` is what
|
|
342
|
+
* starts RN), the snippet is injected before the return statement as before.
|
|
337
343
|
*/
|
|
338
344
|
const addHandleDeeplinkInKilledState = content => {
|
|
339
|
-
// Check if deep link code snippet is already present
|
|
340
345
|
const deepLinkMarker = 'Deep link workaround for app killed state start';
|
|
341
346
|
if (content.includes(deepLinkMarker)) {
|
|
342
347
|
return content;
|
|
343
348
|
}
|
|
344
|
-
|
|
345
|
-
// Find the return statement with launchOptions
|
|
346
349
|
const returnStatementRegex = /return\s+super\.application\s*\(\s*application\s*,\s*didFinishLaunchingWithOptions\s*:\s*launchOptions\s*\)/;
|
|
347
|
-
const
|
|
348
|
-
|
|
350
|
+
const modifiedReturnStatement = 'return super.application(application, didFinishLaunchingWithOptions: modifiedLaunchOptions)';
|
|
351
|
+
const factoryStartRegex = /(\s*)#if\s+os\(iOS\)\s*\|\|\s*os\(tvOS\)([\s\S]*?factory\.startReactNative\s*\([\s\S]*?launchOptions:\s*)launchOptions(\s*\)[\s\S]*?#endif)/;
|
|
352
|
+
if (factoryStartRegex.test(content)) {
|
|
353
|
+
let result = content.replace(factoryStartRegex, `\n${CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET}\n#if os(iOS) || os(tvOS)$2modifiedLaunchOptions$3`);
|
|
354
|
+
if (returnStatementRegex.test(result)) {
|
|
355
|
+
result = result.replace(returnStatementRegex, modifiedReturnStatement);
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
if (!returnStatementRegex.test(content)) {
|
|
349
360
|
logger.warn('Could not find return statement with launchOptions');
|
|
350
361
|
return content;
|
|
351
362
|
}
|
|
352
|
-
|
|
353
|
-
// Create the replacement code with deep link handling and modified return statement
|
|
354
|
-
const modifiedReturnStatement = 'return super.application(application, didFinishLaunchingWithOptions: modifiedLaunchOptions)';
|
|
355
363
|
const replacementCode = CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET + '\n\n ' + modifiedReturnStatement;
|
|
356
|
-
|
|
357
|
-
// Replace the return statement with deep link handling code and modified return statement
|
|
358
364
|
return content.replace(returnStatementRegex, replacementCode);
|
|
359
365
|
};
|
|
360
366
|
//# sourceMappingURL=withCIOIosSwift.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["withAppDelegate","withXcodeProject","path","PLATFORM","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET","CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX","CIO_NATIVE_SDK_INITIALIZE_CALL","CIO_NATIVE_SDK_INITIALIZE_SNIPPET","CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2","CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER","replaceCodeByRegex","FileManagement","patchNativeSDKInitializer","logger","getIosNativeFilesPath","copyFileToXcode","getOrCreateCustomerIOGroup","isFcmPushProvider","CIO_SDK_APP_DELEGATE_HANDLER_CLASS","CIO_SDK_APP_DELEGATE_HANDLER_FILENAME","copyAndConfigureAppDelegateHandler","config","sdkConfig","props","location","projectName","modRequest","warn","xcodeProject","modResults","projectRoot","iosProjectRoot","join","group","pushNotification","copyAndConfigurePushAppDelegateHandler","copyAndConfigureNativeSDKInitializer","_props$pushNotificati","_props$pushNotificati2","_props$pushNotificati3","_props$pushNotificati4","_props$pushNotificati5","useFcm","handlerSourcePath","handlerDestPath","copyFile","addSourceFile","handlerFileContent","readFile","disableNotificationRegistration","snippet","autoTrackPushEvents","toString","autoFetchDeviceToken","showPushAppInForeground","appGroupId","appGroupIdBuilderLine","JSON","stringify","replace","writeFile","_sdkConfig$location","locationOptions","enabled","trackingMode","undefined","filename","sourcePath","sourceFilePath","targetFileName","transform","content","IOS","customerIOGroup","withCIOIosSwift","configOuter","modifyAppDelegateWithPushAppDelegateHandler","modifyAppDelegateWithNativeSDKInitializer","_props$pushNotificati6","appDelegateContent","contents","includes","info","modifiedContent","addHandlerPropertyDeclaration","modifyDidFinishLaunchingWithOptions","addDidRegisterForRemoteNotificationsWithDeviceToken","addDidFailToRegisterForRemoteNotificationsWithError","handleDeeplinkInKilledState","addHandleDeeplinkInKilledState","methodExistsInAppDelegate","methodSignature","classDeclarationRegex","match","position","index","length","substring","codeToInject","returnStatementRegex","returnStatementMatch","insertPosition","methodRegex","methodContent","openBraceIndex","indexOf","modifiedMethod","classEndRegex","classEndMatch","deepLinkMarker","modifiedReturnStatement","replacementCode"],"sources":["withCIOIosSwift.ts"],"sourcesContent":["import type {\n ExportedConfigWithProps,\n XcodeProject,\n} from '@expo/config-plugins';\nimport { withAppDelegate, withXcodeProject } from '@expo/config-plugins';\nimport type { ExpoConfig } from '@expo/config-types';\nimport path from 'path';\nimport { PLATFORM } from '../helpers/constants/common';\nimport {\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET,\n CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX,\n CIO_NATIVE_SDK_INITIALIZE_CALL,\n CIO_NATIVE_SDK_INITIALIZE_SNIPPET,\n CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2,\n CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER,\n} from '../helpers/constants/ios';\nimport { replaceCodeByRegex } from '../helpers/utils/codeInjection';\nimport { FileManagement } from '../helpers/utils/fileManagement';\nimport { patchNativeSDKInitializer } from '../helpers/utils/patchPluginNativeCode';\nimport type {\n CustomerIOPluginOptionsIOS,\n CustomerIOPluginLocationOptions,\n NativeSDKConfig,\n} from '../types/cio-types';\nimport { logger } from '../utils/logger';\nimport { getIosNativeFilesPath } from '../utils/plugin';\nimport { copyFileToXcode, getOrCreateCustomerIOGroup } from '../utils/xcode';\nimport { isFcmPushProvider } from './utils';\n\n// Constants\nconst CIO_SDK_APP_DELEGATE_HANDLER_CLASS = 'CioSdkAppDelegateHandler';\nconst CIO_SDK_APP_DELEGATE_HANDLER_FILENAME = `${CIO_SDK_APP_DELEGATE_HANDLER_CLASS}.swift`;\n\n/**\n * Copy and configure the CioSdkAppDelegateHandler.swift file\n */\nconst copyAndConfigureAppDelegateHandler = (\n config: ExportedConfigWithProps<XcodeProject>,\n sdkConfig?: NativeSDKConfig,\n props?: CustomerIOPluginOptionsIOS,\n location?: CustomerIOPluginLocationOptions,\n): ExportedConfigWithProps<XcodeProject> => {\n // Destination path in the iOS project\n const projectName = config.modRequest.projectName || '';\n if (!projectName) {\n logger.warn(\n 'Project name is undefined, cannot copy CustomerIO files'\n );\n return config;\n }\n\n // Add files to the Xcode project\n const xcodeProject = config.modResults;\n const projectRoot = config.modRequest.projectRoot;\n const iosProjectRoot = path.join(projectRoot, 'ios');\n\n const group = getOrCreateCustomerIOGroup(xcodeProject, projectName);\n if (props?.pushNotification) {\n // Copy CioSdkAppDelegateHandler.swift for full push notification + auto-init support\n copyAndConfigurePushAppDelegateHandler({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n props,\n location,\n });\n } else if (sdkConfig) {\n // Copy only CustomerIOSDKInitializer.swift for auto-init without push notifications\n copyAndConfigureNativeSDKInitializer({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n location,\n });\n }\n\n return config;\n};\n\nconst copyAndConfigurePushAppDelegateHandler = ({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n props,\n location,\n}: {\n xcodeProject: XcodeProject;\n group: XcodeProject['pbxCreateGroup'];\n iosProjectRoot: string;\n projectName: string;\n sdkConfig: NativeSDKConfig | undefined;\n props: CustomerIOPluginOptionsIOS;\n location?: CustomerIOPluginLocationOptions;\n}) => {\n const useFcm = isFcmPushProvider(props);\n\n // Source path for the handler file\n const handlerSourcePath = path.join(\n getIosNativeFilesPath(),\n useFcm ? 'fcm' : 'apn',\n CIO_SDK_APP_DELEGATE_HANDLER_FILENAME\n );\n\n const handlerDestPath = path.join(\n iosProjectRoot,\n projectName,\n CIO_SDK_APP_DELEGATE_HANDLER_FILENAME\n );\n\n FileManagement.copyFile(handlerSourcePath, handlerDestPath);\n\n // Add the file to the Xcode project\n xcodeProject.addSourceFile(\n `${projectName}/${CIO_SDK_APP_DELEGATE_HANDLER_FILENAME}`,\n null,\n group\n );\n\n let handlerFileContent = FileManagement.readFile(handlerDestPath);\n\n const disableNotificationRegistration =\n props.pushNotification?.disableNotificationRegistration;\n let snippet = '';\n // unless this property is explicity set to true, push notification\n // registration will be added to the AppDelegate\n if (disableNotificationRegistration !== true) {\n snippet = CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2;\n }\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER,\n snippet\n );\n\n const autoTrackPushEvents =\n props.pushNotification?.autoTrackPushEvents !== false;\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{AUTO_TRACK_PUSH_EVENTS\\}\\}/,\n autoTrackPushEvents.toString()\n );\n\n const autoFetchDeviceToken =\n props.pushNotification?.autoFetchDeviceToken !== false;\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{AUTO_FETCH_DEVICE_TOKEN\\}\\}/,\n autoFetchDeviceToken.toString()\n );\n\n const showPushAppInForeground =\n props.pushNotification?.showPushAppInForeground !== false;\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{SHOW_PUSH_APP_IN_FOREGROUND\\}\\}/,\n showPushAppInForeground.toString()\n );\n\n const appGroupId = props.pushNotification?.appGroupId;\n const appGroupIdBuilderLine = appGroupId\n ? ` .appGroupId(${JSON.stringify(appGroupId)})\\n`\n : '';\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{APP_GROUP_ID_BUILDER_LINE\\}\\}/,\n appGroupIdBuilderLine\n );\n\n // Add auto initialization if sdkConfig is provided\n if (sdkConfig) {\n // Also copy CustomerIOSDKInitializer.swift for auto-initialization\n copyAndConfigureNativeSDKInitializer({ xcodeProject, group, iosProjectRoot, projectName, sdkConfig, location });\n\n // Inject auto initialization call before MessagingPush initialization\n handlerFileContent = handlerFileContent.replace(CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX, CIO_NATIVE_SDK_INITIALIZE_SNIPPET + '$1');\n }\n\n FileManagement.writeFile(handlerDestPath, handlerFileContent);\n};\n\nconst copyAndConfigureNativeSDKInitializer = ({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n location,\n}: {\n xcodeProject: XcodeProject;\n group: XcodeProject['pbxCreateGroup'];\n iosProjectRoot: string;\n projectName: string;\n sdkConfig: NativeSDKConfig;\n location?: CustomerIOPluginLocationOptions;\n}) => {\n const locationOptions = location\n ? { enabled: location.enabled === true, trackingMode: sdkConfig?.location?.trackingMode }\n : undefined;\n const filename = 'CustomerIOSDKInitializer.swift';\n const sourcePath = path.join(getIosNativeFilesPath(), filename);\n // Add the CustomerIOSDKInitializer.swift file to the same Xcode group as CioSdkAppDelegateHandler\n copyFileToXcode({\n xcodeProject,\n iosProjectRoot,\n projectName,\n sourceFilePath: sourcePath,\n targetFileName: filename,\n transform: (content) =>\n patchNativeSDKInitializer(content, PLATFORM.IOS, sdkConfig, locationOptions),\n customerIOGroup: group,\n });\n};\n\nexport const withCIOIosSwift = (\n configOuter: ExpoConfig,\n sdkConfig?: NativeSDKConfig,\n props?: CustomerIOPluginOptionsIOS,\n location?: CustomerIOPluginLocationOptions,\n) => {\n // First, copy required swift files to iOS folder and add it to Xcode project\n configOuter = withXcodeProject(configOuter, async (config) => {\n return copyAndConfigureAppDelegateHandler(config, sdkConfig, props, location);\n });\n\n // Modify the AppDelegate based on configuration\n if (props?.pushNotification) {\n // With push notifications: delegate to CioSdkAppDelegateHandler for both push and auto-init\n return withAppDelegate(configOuter, async (config) => {\n return modifyAppDelegateWithPushAppDelegateHandler(config, props);\n });\n } else if (sdkConfig) {\n // Without push notifications: directly inject auto initialization into AppDelegate\n return withAppDelegate(configOuter, async (config) => {\n return modifyAppDelegateWithNativeSDKInitializer(config);\n });\n } else {\n return configOuter;\n }\n};\n\n/**\n * Modify the AppDelegate to integrate with Customer.io SDK\n */\nconst modifyAppDelegateWithPushAppDelegateHandler = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n config: any,\n props: CustomerIOPluginOptionsIOS\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any => {\n const appDelegateContent = config.modResults.contents;\n\n // Check if modifications have already been applied\n if (appDelegateContent.includes(CIO_SDK_APP_DELEGATE_HANDLER_CLASS)) {\n logger.info(\n 'CustomerIO Swift AppDelegate changes already exist. Skipping...'\n );\n return config;\n }\n\n // Add the handler property declaration\n let modifiedContent = addHandlerPropertyDeclaration(appDelegateContent);\n\n // Modify didFinishLaunchingWithOptions to initialize and call the handler\n modifiedContent = modifyDidFinishLaunchingWithOptions(\n modifiedContent,\n ` cioSdkHandler.application(application, didFinishLaunchingWithOptions: launchOptions)\\n\\n `\n );\n\n // Add didRegisterForRemoteNotificationsWithDeviceToken implementation\n modifiedContent =\n addDidRegisterForRemoteNotificationsWithDeviceToken(modifiedContent);\n\n // Add didFailToRegisterForRemoteNotificationsWithError implementation\n modifiedContent =\n addDidFailToRegisterForRemoteNotificationsWithError(modifiedContent);\n\n // Add deep link handling for killed state if enabled\n if (props.pushNotification?.handleDeeplinkInKilledState === true) {\n modifiedContent = addHandleDeeplinkInKilledState(modifiedContent);\n }\n\n config.modResults.contents = modifiedContent;\n return config;\n};\n\n/**\n * Modify the AppDelegate to integrate with Customer.io SDK\n */\nconst modifyAppDelegateWithNativeSDKInitializer = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n config: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any => {\n const appDelegateContent = config.modResults.contents;\n\n // Check if modifications have already been applied\n if (appDelegateContent.includes(CIO_NATIVE_SDK_INITIALIZE_CALL)) {\n logger.info(\n 'CustomerIO Swift AppDelegate changes already exist. Skipping...'\n );\n return config;\n }\n\n // Modify didFinishLaunchingWithOptions to initialize and call the handler\n const modifiedContent = modifyDidFinishLaunchingWithOptions(\n appDelegateContent,\n CIO_NATIVE_SDK_INITIALIZE_SNIPPET,\n );\n\n config.modResults.contents = modifiedContent;\n return config;\n};\n\n/**\n * Check if a method exists in the AppDelegate content\n * @param content The AppDelegate content\n * @param methodSignature The method signature to check for\n * @returns true if the method exists, false otherwise\n */\nconst methodExistsInAppDelegate = (\n content: string,\n methodSignature: string\n): boolean => {\n return content.includes(methodSignature);\n};\n\n/**\n * Add handler property declaration to the AppDelegate class\n * This adds the line: let cioSdkHandler = CioSdkAppDelegateHandler()\n * to the AppDelegate class\n */\nconst addHandlerPropertyDeclaration = (content: string): string => {\n // Look for the AppDelegate class declaration\n const classDeclarationRegex = /class\\s+AppDelegate\\s*:\\s*.*\\s*{/;\n const match = content.match(classDeclarationRegex);\n\n if (!match) {\n logger.warn('Could not find AppDelegate class declaration');\n return content;\n }\n\n const position = (match.index ?? 0) + match[0].length;\n return (\n content.substring(0, position) +\n `\\n let cioSdkHandler = ${CIO_SDK_APP_DELEGATE_HANDLER_CLASS}()\\n` +\n content.substring(position)\n );\n};\n\n/**\n * Modify didFinishLaunchingWithOptions to inject Customer.io code\n * Injects the provided code (either handler call or auto initialization) before the return statement\n */\nconst modifyDidFinishLaunchingWithOptions = (content: string, codeToInject: string): string => {\n // Find the return statement in didFinishLaunchingWithOptions\n // Always look for launchOptions since modifiedLaunchOptions is only set later\n const returnStatementRegex =\n /return\\s+super\\.application\\s*\\(\\s*application\\s*,\\s*didFinishLaunchingWithOptions\\s*:\\s*launchOptions\\s*\\)/;\n\n const returnStatementMatch = content.match(returnStatementRegex);\n\n if (!returnStatementMatch) {\n logger.warn(\n 'Could not find return statement with super.application in didFinishLaunchingWithOptions'\n );\n return content;\n }\n\n // Inject Customer.io code before the return statement\n const insertPosition = returnStatementMatch.index ?? 0;\n\n return (\n content.substring(0, insertPosition) +\n codeToInject +\n content.substring(insertPosition)\n );\n};\n\n/**\n * Add or modify didRegisterForRemoteNotificationsWithDeviceToken implementation\n * If the method already exists, it adds the handler call to the existing method\n * If the method doesn't exist, it adds a new method implementation\n */\nconst addDidRegisterForRemoteNotificationsWithDeviceToken = (\n content: string\n): string => {\n const methodSignature =\n 'func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken:';\n\n // Check if method already exists\n if (methodExistsInAppDelegate(content, methodSignature)) {\n // Method exists, modify it to call our handler\n const methodRegex =\n /func\\s+application\\s*\\(\\s*_\\s+application\\s*:\\s*UIApplication\\s*,\\s*didRegisterForRemoteNotificationsWithDeviceToken\\s+deviceToken\\s*:\\s*Data\\s*\\)\\s*{[\\s\\S]*?}/;\n const match = content.match(methodRegex);\n\n if (match) {\n // Add our handler call to the existing method\n const methodContent = match[0];\n const openBraceIndex = methodContent.indexOf('{') + 1;\n const modifiedMethod =\n methodContent.substring(0, openBraceIndex) +\n '\\n // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\\n' +\n methodContent.substring(openBraceIndex);\n\n return content.replace(methodRegex, modifiedMethod);\n }\n\n return content;\n } else {\n // Method doesn't exist, add it inside the AppDelegate class\n // Find the end of the AppDelegate class\n const classEndRegex = /^}(\\s*$|\\s*\\/\\/)/m;\n const classEndMatch = content.match(classEndRegex);\n\n if (!classEndMatch) {\n logger.warn('Could not find end of AppDelegate class');\n return content;\n }\n\n // Insert the method inside the class\n const position = classEndMatch.index ?? 0;\n return (\n content.substring(0, position) +\n '\\n // Handle device token registration\\n' +\n ' public override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\\n' +\n ' // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\\n' +\n ' super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\\n' +\n ' }\\n' +\n content.substring(position)\n );\n }\n};\n\n/**\n * Add or modify didFailToRegisterForRemoteNotificationsWithError implementation\n * If the method already exists, it adds the handler call to the existing method\n * If the method doesn't exist, it adds a new method implementation\n */\nconst addDidFailToRegisterForRemoteNotificationsWithError = (\n content: string\n): string => {\n const methodSignature =\n 'func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error:';\n\n // Check if method already exists\n if (methodExistsInAppDelegate(content, methodSignature)) {\n // Method exists, modify it to call our handler\n const methodRegex =\n /func\\s+application\\s*\\(\\s*_\\s+application\\s*:\\s*UIApplication\\s*,\\s*didFailToRegisterForRemoteNotificationsWithError\\s+error\\s*:\\s*Error\\s*\\)\\s*{[\\s\\S]*?}/;\n const match = content.match(methodRegex);\n\n if (match) {\n // Add our handler call to the existing method\n const methodContent = match[0];\n const openBraceIndex = methodContent.indexOf('{') + 1;\n const modifiedMethod =\n methodContent.substring(0, openBraceIndex) +\n '\\n // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\\n' +\n methodContent.substring(openBraceIndex);\n\n return content.replace(methodRegex, modifiedMethod);\n }\n\n return content;\n } else {\n // Method doesn't exist, add it inside the AppDelegate class\n // Find the end of the AppDelegate class\n const classEndRegex = /^}(\\s*$|\\s*\\/\\/)/m;\n const classEndMatch = content.match(classEndRegex);\n\n if (!classEndMatch) {\n logger.warn('Could not find end of AppDelegate class');\n return content;\n }\n\n // Insert the method inside the class\n const position = classEndMatch.index ?? 0;\n return (\n content.substring(0, position) +\n '\\n // Handle remote notification registration errors\\n' +\n ' public override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {\\n' +\n ' // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\\n' +\n ' super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\\n' +\n ' }\\n' +\n content.substring(position)\n );\n }\n};\n\n/**\n * Add deep link handling for killed state\n * This replaces the return statement with deep link handling code\n * and a modified return statement that uses modifiedLaunchOptions\n */\nconst addHandleDeeplinkInKilledState = (content: string): string => {\n // Check if deep link code snippet is already present\n const deepLinkMarker = 'Deep link workaround for app killed state start';\n if (content.includes(deepLinkMarker)) {\n return content;\n }\n\n // Find the return statement with launchOptions\n const returnStatementRegex =\n /return\\s+super\\.application\\s*\\(\\s*application\\s*,\\s*didFinishLaunchingWithOptions\\s*:\\s*launchOptions\\s*\\)/;\n const returnStatementMatch = content.match(returnStatementRegex);\n\n if (!returnStatementMatch) {\n logger.warn('Could not find return statement with launchOptions');\n return content;\n }\n\n // Create the replacement code with deep link handling and modified return statement\n const modifiedReturnStatement =\n 'return super.application(application, didFinishLaunchingWithOptions: modifiedLaunchOptions)';\n const replacementCode =\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET +\n '\\n\\n ' +\n modifiedReturnStatement;\n\n // Replace the return statement with deep link handling code and modified return statement\n return content.replace(returnStatementRegex, replacementCode);\n};\n"],"mappings":"AAIA,SAASA,eAAe,EAAEC,gBAAgB,QAAQ,sBAAsB;AAExE,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,QAAQ,6BAA6B;AACtD,SACEC,+CAA+C,EAC/CC,0CAA0C,EAC1CC,8BAA8B,EAC9BC,iCAAiC,EACjCC,wCAAwC,EACxCC,0CAA0C,QACrC,0BAA0B;AACjC,SAASC,kBAAkB,QAAQ,gCAAgC;AACnE,SAASC,cAAc,QAAQ,iCAAiC;AAChE,SAASC,yBAAyB,QAAQ,wCAAwC;AAMlF,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,qBAAqB,QAAQ,iBAAiB;AACvD,SAASC,eAAe,EAAEC,0BAA0B,QAAQ,gBAAgB;AAC5E,SAASC,iBAAiB,QAAQ,SAAS;;AAE3C;AACA,MAAMC,kCAAkC,GAAG,0BAA0B;AACrE,MAAMC,qCAAqC,GAAG,GAAGD,kCAAkC,QAAQ;;AAE3F;AACA;AACA;AACA,MAAME,kCAAkC,GAAGA,CACzCC,MAA6C,EAC7CC,SAA2B,EAC3BC,KAAkC,EAClCC,QAA0C,KACA;EAC1C;EACA,MAAMC,WAAW,GAAGJ,MAAM,CAACK,UAAU,CAACD,WAAW,IAAI,EAAE;EACvD,IAAI,CAACA,WAAW,EAAE;IAChBZ,MAAM,CAACc,IAAI,CACT,yDACF,CAAC;IACD,OAAON,MAAM;EACf;;EAEA;EACA,MAAMO,YAAY,GAAGP,MAAM,CAACQ,UAAU;EACtC,MAAMC,WAAW,GAAGT,MAAM,CAACK,UAAU,CAACI,WAAW;EACjD,MAAMC,cAAc,GAAG7B,IAAI,CAAC8B,IAAI,CAACF,WAAW,EAAE,KAAK,CAAC;EAEpD,MAAMG,KA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EA,OAAOnC,OAAO;EAChB,CAAC,MAAM;IACL;IACA;IACA,MAAMoC,aAAa,GAAG,mBAAmB;IACzC,MAAMC,aAAa,GAAGrC,OAAO,CAACsB,KAAK,CAACc,aAAa,CAAC;IAElD,IAAI,CAACC,aAAa,EAAE;MAClB/F,MAAM,CAACc,IAAI,CAAC,yCAAyC,CAAC;MACtD,OAAO4C,OAAO;IAChB;;IAEA;IACA,MAAMuB,QAAQ,GAAGc,aAAa,CAACb,KAAK,IAAI,CAAC;IACzC,OACExB,OAAO,CAAC0B,SAAS,CAAC,CAAC,EAAEH,QAAQ,CAAC,GAC9B,yDAAyD,GACzD,qIAAqI,GACrI,sCAAsC,GACtC,uGAAuG,GACvG,+FAA+F,GAC/F,OAAO,GACPvB,OAAO,CAAC0B,SAAS,CAACH,QAAQ,CAAC;EAE/B;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAML,8BAA8B,GAAIlB,OAAe,IAAa;EAClE;EACA,MAAMsC,cAAc,GAAG,iDAAiD;EACxE,IAAItC,OAAO,CAACU,QAAQ,CAAC4B,cAAc,CAAC,EAAE;IACpC,OAAOtC,OAAO;EAChB;;EAEA;EACA,MAAM4B,oBAAoB,GACxB,6GAA6G;EAC/G,MAAMC,oBAAoB,GAAG7B,OAAO,CAACsB,KAAK,CAACM,oBAAoB,CAAC;EAEhE,IAAI,CAACC,oBAAoB,EAAE;IACzBvF,MAAM,CAACc,IAAI,CAAC,oDAAoD,CAAC;IACjE,OAAO4C,OAAO;EAChB;;EAEA;EACA,MAAMuC,uBAAuB,GAC3B,6FAA6F;EAC/F,MAAMC,eAAe,GACnB3G,+CAA+C,GAC/C,UAAU,GACV0G,uBAAuB;;EAEzB;EACA,OAAOvC,OAAO,CAACZ,OAAO,CAACwC,oBAAoB,EAAEY,eAAe,CAAC;AAC/D,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["withAppDelegate","withXcodeProject","path","PLATFORM","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET","CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX","CIO_NATIVE_SDK_INITIALIZE_CALL","CIO_NATIVE_SDK_INITIALIZE_SNIPPET","CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2","CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER","replaceCodeByRegex","FileManagement","patchNativeSDKInitializer","logger","getIosNativeFilesPath","copyFileToXcode","getOrCreateCustomerIOGroup","isFcmPushProvider","CIO_SDK_APP_DELEGATE_HANDLER_CLASS","CIO_SDK_APP_DELEGATE_HANDLER_FILENAME","copyAndConfigureAppDelegateHandler","config","sdkConfig","props","location","projectName","modRequest","warn","xcodeProject","modResults","projectRoot","iosProjectRoot","join","group","pushNotification","copyAndConfigurePushAppDelegateHandler","copyAndConfigureNativeSDKInitializer","_props$pushNotificati","_props$pushNotificati2","_props$pushNotificati3","_props$pushNotificati4","_props$pushNotificati5","useFcm","handlerSourcePath","handlerDestPath","copyFile","addSourceFile","handlerFileContent","readFile","disableNotificationRegistration","snippet","autoTrackPushEvents","toString","autoFetchDeviceToken","showPushAppInForeground","appGroupId","appGroupIdBuilderLine","JSON","stringify","replace","writeFile","_sdkConfig$location","locationOptions","enabled","trackingMode","undefined","filename","sourcePath","sourceFilePath","targetFileName","transform","content","IOS","customerIOGroup","withCIOIosSwift","configOuter","modifyAppDelegateWithPushAppDelegateHandler","modifyAppDelegateWithNativeSDKInitializer","_props$pushNotificati6","appDelegateContent","contents","includes","info","modifiedContent","addHandlerPropertyDeclaration","modifyDidFinishLaunchingWithOptions","addDidRegisterForRemoteNotificationsWithDeviceToken","addDidFailToRegisterForRemoteNotificationsWithError","handleDeeplinkInKilledState","addHandleDeeplinkInKilledState","methodExistsInAppDelegate","methodSignature","classDeclarationRegex","match","position","index","length","substring","codeToInject","returnStatementRegex","returnStatementMatch","insertPosition","methodRegex","methodContent","openBraceIndex","indexOf","modifiedMethod","classEndRegex","classEndMatch","deepLinkMarker","modifiedReturnStatement","factoryStartRegex","test","result","replacementCode"],"sources":["withCIOIosSwift.ts"],"sourcesContent":["import type {\n ExportedConfigWithProps,\n XcodeProject,\n} from '@expo/config-plugins';\nimport { withAppDelegate, withXcodeProject } from '@expo/config-plugins';\nimport type { ExpoConfig } from '@expo/config-types';\nimport path from 'path';\nimport { PLATFORM } from '../helpers/constants/common';\nimport {\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET,\n CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX,\n CIO_NATIVE_SDK_INITIALIZE_CALL,\n CIO_NATIVE_SDK_INITIALIZE_SNIPPET,\n CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2,\n CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER,\n} from '../helpers/constants/ios';\nimport { replaceCodeByRegex } from '../helpers/utils/codeInjection';\nimport { FileManagement } from '../helpers/utils/fileManagement';\nimport { patchNativeSDKInitializer } from '../helpers/utils/patchPluginNativeCode';\nimport type {\n CustomerIOPluginOptionsIOS,\n CustomerIOPluginLocationOptions,\n NativeSDKConfig,\n} from '../types/cio-types';\nimport { logger } from '../utils/logger';\nimport { getIosNativeFilesPath } from '../utils/plugin';\nimport { copyFileToXcode, getOrCreateCustomerIOGroup } from '../utils/xcode';\nimport { isFcmPushProvider } from './utils';\n\n// Constants\nconst CIO_SDK_APP_DELEGATE_HANDLER_CLASS = 'CioSdkAppDelegateHandler';\nconst CIO_SDK_APP_DELEGATE_HANDLER_FILENAME = `${CIO_SDK_APP_DELEGATE_HANDLER_CLASS}.swift`;\n\n/**\n * Copy and configure the CioSdkAppDelegateHandler.swift file\n */\nconst copyAndConfigureAppDelegateHandler = (\n config: ExportedConfigWithProps<XcodeProject>,\n sdkConfig?: NativeSDKConfig,\n props?: CustomerIOPluginOptionsIOS,\n location?: CustomerIOPluginLocationOptions,\n): ExportedConfigWithProps<XcodeProject> => {\n // Destination path in the iOS project\n const projectName = config.modRequest.projectName || '';\n if (!projectName) {\n logger.warn(\n 'Project name is undefined, cannot copy CustomerIO files'\n );\n return config;\n }\n\n // Add files to the Xcode project\n const xcodeProject = config.modResults;\n const projectRoot = config.modRequest.projectRoot;\n const iosProjectRoot = path.join(projectRoot, 'ios');\n\n const group = getOrCreateCustomerIOGroup(xcodeProject, projectName);\n if (props?.pushNotification) {\n // Copy CioSdkAppDelegateHandler.swift for full push notification + auto-init support\n copyAndConfigurePushAppDelegateHandler({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n props,\n location,\n });\n } else if (sdkConfig) {\n // Copy only CustomerIOSDKInitializer.swift for auto-init without push notifications\n copyAndConfigureNativeSDKInitializer({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n location,\n });\n }\n\n return config;\n};\n\nconst copyAndConfigurePushAppDelegateHandler = ({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n props,\n location,\n}: {\n xcodeProject: XcodeProject;\n group: XcodeProject['pbxCreateGroup'];\n iosProjectRoot: string;\n projectName: string;\n sdkConfig: NativeSDKConfig | undefined;\n props: CustomerIOPluginOptionsIOS;\n location?: CustomerIOPluginLocationOptions;\n}) => {\n const useFcm = isFcmPushProvider(props);\n\n // Source path for the handler file\n const handlerSourcePath = path.join(\n getIosNativeFilesPath(),\n useFcm ? 'fcm' : 'apn',\n CIO_SDK_APP_DELEGATE_HANDLER_FILENAME\n );\n\n const handlerDestPath = path.join(\n iosProjectRoot,\n projectName,\n CIO_SDK_APP_DELEGATE_HANDLER_FILENAME\n );\n\n FileManagement.copyFile(handlerSourcePath, handlerDestPath);\n\n // Add the file to the Xcode project\n xcodeProject.addSourceFile(\n `${projectName}/${CIO_SDK_APP_DELEGATE_HANDLER_FILENAME}`,\n null,\n group\n );\n\n let handlerFileContent = FileManagement.readFile(handlerDestPath);\n\n const disableNotificationRegistration =\n props.pushNotification?.disableNotificationRegistration;\n let snippet = '';\n // unless this property is explicity set to true, push notification\n // registration will be added to the AppDelegate\n if (disableNotificationRegistration !== true) {\n snippet = CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2;\n }\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER,\n snippet\n );\n\n const autoTrackPushEvents =\n props.pushNotification?.autoTrackPushEvents !== false;\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{AUTO_TRACK_PUSH_EVENTS\\}\\}/,\n autoTrackPushEvents.toString()\n );\n\n const autoFetchDeviceToken =\n props.pushNotification?.autoFetchDeviceToken !== false;\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{AUTO_FETCH_DEVICE_TOKEN\\}\\}/,\n autoFetchDeviceToken.toString()\n );\n\n const showPushAppInForeground =\n props.pushNotification?.showPushAppInForeground !== false;\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{SHOW_PUSH_APP_IN_FOREGROUND\\}\\}/,\n showPushAppInForeground.toString()\n );\n\n const appGroupId = props.pushNotification?.appGroupId;\n const appGroupIdBuilderLine = appGroupId\n ? ` .appGroupId(${JSON.stringify(appGroupId)})\\n`\n : '';\n handlerFileContent = replaceCodeByRegex(\n handlerFileContent,\n /\\{\\{APP_GROUP_ID_BUILDER_LINE\\}\\}/,\n appGroupIdBuilderLine\n );\n\n // Add auto initialization if sdkConfig is provided\n if (sdkConfig) {\n // Also copy CustomerIOSDKInitializer.swift for auto-initialization\n copyAndConfigureNativeSDKInitializer({ xcodeProject, group, iosProjectRoot, projectName, sdkConfig, location });\n\n // Inject auto initialization call before MessagingPush initialization\n handlerFileContent = handlerFileContent.replace(CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX, CIO_NATIVE_SDK_INITIALIZE_SNIPPET + '$1');\n }\n\n FileManagement.writeFile(handlerDestPath, handlerFileContent);\n};\n\nconst copyAndConfigureNativeSDKInitializer = ({\n xcodeProject,\n group,\n iosProjectRoot,\n projectName,\n sdkConfig,\n location,\n}: {\n xcodeProject: XcodeProject;\n group: XcodeProject['pbxCreateGroup'];\n iosProjectRoot: string;\n projectName: string;\n sdkConfig: NativeSDKConfig;\n location?: CustomerIOPluginLocationOptions;\n}) => {\n const locationOptions = location\n ? { enabled: location.enabled === true, trackingMode: sdkConfig?.location?.trackingMode }\n : undefined;\n const filename = 'CustomerIOSDKInitializer.swift';\n const sourcePath = path.join(getIosNativeFilesPath(), filename);\n // Add the CustomerIOSDKInitializer.swift file to the same Xcode group as CioSdkAppDelegateHandler\n copyFileToXcode({\n xcodeProject,\n iosProjectRoot,\n projectName,\n sourceFilePath: sourcePath,\n targetFileName: filename,\n transform: (content) =>\n patchNativeSDKInitializer(content, PLATFORM.IOS, sdkConfig, locationOptions),\n customerIOGroup: group,\n });\n};\n\nexport const withCIOIosSwift = (\n configOuter: ExpoConfig,\n sdkConfig?: NativeSDKConfig,\n props?: CustomerIOPluginOptionsIOS,\n location?: CustomerIOPluginLocationOptions,\n) => {\n // First, copy required swift files to iOS folder and add it to Xcode project\n configOuter = withXcodeProject(configOuter, async (config) => {\n return copyAndConfigureAppDelegateHandler(config, sdkConfig, props, location);\n });\n\n // Modify the AppDelegate based on configuration\n if (props?.pushNotification) {\n // With push notifications: delegate to CioSdkAppDelegateHandler for both push and auto-init\n return withAppDelegate(configOuter, async (config) => {\n return modifyAppDelegateWithPushAppDelegateHandler(config, props);\n });\n } else if (sdkConfig) {\n // Without push notifications: directly inject auto initialization into AppDelegate\n return withAppDelegate(configOuter, async (config) => {\n return modifyAppDelegateWithNativeSDKInitializer(config);\n });\n } else {\n return configOuter;\n }\n};\n\n/**\n * Modify the AppDelegate to integrate with Customer.io SDK\n */\nconst modifyAppDelegateWithPushAppDelegateHandler = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n config: any,\n props: CustomerIOPluginOptionsIOS\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any => {\n const appDelegateContent = config.modResults.contents;\n\n // Check if modifications have already been applied\n if (appDelegateContent.includes(CIO_SDK_APP_DELEGATE_HANDLER_CLASS)) {\n logger.info(\n 'CustomerIO Swift AppDelegate changes already exist. Skipping...'\n );\n return config;\n }\n\n // Add the handler property declaration\n let modifiedContent = addHandlerPropertyDeclaration(appDelegateContent);\n\n // Modify didFinishLaunchingWithOptions to initialize and call the handler\n modifiedContent = modifyDidFinishLaunchingWithOptions(\n modifiedContent,\n ` cioSdkHandler.application(application, didFinishLaunchingWithOptions: launchOptions)\\n\\n `\n );\n\n // Add didRegisterForRemoteNotificationsWithDeviceToken implementation\n modifiedContent =\n addDidRegisterForRemoteNotificationsWithDeviceToken(modifiedContent);\n\n // Add didFailToRegisterForRemoteNotificationsWithError implementation\n modifiedContent =\n addDidFailToRegisterForRemoteNotificationsWithError(modifiedContent);\n\n // Add deep link handling for killed state if enabled\n if (props.pushNotification?.handleDeeplinkInKilledState === true) {\n modifiedContent = addHandleDeeplinkInKilledState(modifiedContent);\n }\n\n config.modResults.contents = modifiedContent;\n return config;\n};\n\n/**\n * Modify the AppDelegate to integrate with Customer.io SDK\n */\nconst modifyAppDelegateWithNativeSDKInitializer = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n config: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any => {\n const appDelegateContent = config.modResults.contents;\n\n // Check if modifications have already been applied\n if (appDelegateContent.includes(CIO_NATIVE_SDK_INITIALIZE_CALL)) {\n logger.info(\n 'CustomerIO Swift AppDelegate changes already exist. Skipping...'\n );\n return config;\n }\n\n // Modify didFinishLaunchingWithOptions to initialize and call the handler\n const modifiedContent = modifyDidFinishLaunchingWithOptions(\n appDelegateContent,\n CIO_NATIVE_SDK_INITIALIZE_SNIPPET,\n );\n\n config.modResults.contents = modifiedContent;\n return config;\n};\n\n/**\n * Check if a method exists in the AppDelegate content\n * @param content The AppDelegate content\n * @param methodSignature The method signature to check for\n * @returns true if the method exists, false otherwise\n */\nconst methodExistsInAppDelegate = (\n content: string,\n methodSignature: string\n): boolean => {\n return content.includes(methodSignature);\n};\n\n/**\n * Add handler property declaration to the AppDelegate class\n * This adds the line: let cioSdkHandler = CioSdkAppDelegateHandler()\n * to the AppDelegate class\n */\nconst addHandlerPropertyDeclaration = (content: string): string => {\n // Look for the AppDelegate class declaration\n const classDeclarationRegex = /class\\s+AppDelegate\\s*:\\s*.*\\s*{/;\n const match = content.match(classDeclarationRegex);\n\n if (!match) {\n logger.warn('Could not find AppDelegate class declaration');\n return content;\n }\n\n const position = (match.index ?? 0) + match[0].length;\n return (\n content.substring(0, position) +\n `\\n let cioSdkHandler = ${CIO_SDK_APP_DELEGATE_HANDLER_CLASS}()\\n` +\n content.substring(position)\n );\n};\n\n/**\n * Modify didFinishLaunchingWithOptions to inject Customer.io code\n * Injects the provided code (either handler call or auto initialization) before the return statement\n */\nconst modifyDidFinishLaunchingWithOptions = (content: string, codeToInject: string): string => {\n // Find the return statement in didFinishLaunchingWithOptions\n // Always look for launchOptions since modifiedLaunchOptions is only set later\n const returnStatementRegex =\n /return\\s+super\\.application\\s*\\(\\s*application\\s*,\\s*didFinishLaunchingWithOptions\\s*:\\s*launchOptions\\s*\\)/;\n\n const returnStatementMatch = content.match(returnStatementRegex);\n\n if (!returnStatementMatch) {\n logger.warn(\n 'Could not find return statement with super.application in didFinishLaunchingWithOptions'\n );\n return content;\n }\n\n // Inject Customer.io code before the return statement\n const insertPosition = returnStatementMatch.index ?? 0;\n\n return (\n content.substring(0, insertPosition) +\n codeToInject +\n content.substring(insertPosition)\n );\n};\n\n/**\n * Add or modify didRegisterForRemoteNotificationsWithDeviceToken implementation\n * If the method already exists, it adds the handler call to the existing method\n * If the method doesn't exist, it adds a new method implementation\n */\nconst addDidRegisterForRemoteNotificationsWithDeviceToken = (\n content: string\n): string => {\n const methodSignature =\n 'func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken:';\n\n // Check if method already exists\n if (methodExistsInAppDelegate(content, methodSignature)) {\n // Method exists, modify it to call our handler\n const methodRegex =\n /func\\s+application\\s*\\(\\s*_\\s+application\\s*:\\s*UIApplication\\s*,\\s*didRegisterForRemoteNotificationsWithDeviceToken\\s+deviceToken\\s*:\\s*Data\\s*\\)\\s*{[\\s\\S]*?}/;\n const match = content.match(methodRegex);\n\n if (match) {\n // Add our handler call to the existing method\n const methodContent = match[0];\n const openBraceIndex = methodContent.indexOf('{') + 1;\n const modifiedMethod =\n methodContent.substring(0, openBraceIndex) +\n '\\n // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\\n' +\n methodContent.substring(openBraceIndex);\n\n return content.replace(methodRegex, modifiedMethod);\n }\n\n return content;\n } else {\n // Method doesn't exist, add it inside the AppDelegate class\n // Find the end of the AppDelegate class\n const classEndRegex = /^}(\\s*$|\\s*\\/\\/)/m;\n const classEndMatch = content.match(classEndRegex);\n\n if (!classEndMatch) {\n logger.warn('Could not find end of AppDelegate class');\n return content;\n }\n\n // Insert the method inside the class\n const position = classEndMatch.index ?? 0;\n return (\n content.substring(0, position) +\n '\\n // Handle device token registration\\n' +\n ' public override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\\n' +\n ' // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\\n' +\n ' super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\\n' +\n ' }\\n' +\n content.substring(position)\n );\n }\n};\n\n/**\n * Add or modify didFailToRegisterForRemoteNotificationsWithError implementation\n * If the method already exists, it adds the handler call to the existing method\n * If the method doesn't exist, it adds a new method implementation\n */\nconst addDidFailToRegisterForRemoteNotificationsWithError = (\n content: string\n): string => {\n const methodSignature =\n 'func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error:';\n\n // Check if method already exists\n if (methodExistsInAppDelegate(content, methodSignature)) {\n // Method exists, modify it to call our handler\n const methodRegex =\n /func\\s+application\\s*\\(\\s*_\\s+application\\s*:\\s*UIApplication\\s*,\\s*didFailToRegisterForRemoteNotificationsWithError\\s+error\\s*:\\s*Error\\s*\\)\\s*{[\\s\\S]*?}/;\n const match = content.match(methodRegex);\n\n if (match) {\n // Add our handler call to the existing method\n const methodContent = match[0];\n const openBraceIndex = methodContent.indexOf('{') + 1;\n const modifiedMethod =\n methodContent.substring(0, openBraceIndex) +\n '\\n // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\\n' +\n methodContent.substring(openBraceIndex);\n\n return content.replace(methodRegex, modifiedMethod);\n }\n\n return content;\n } else {\n // Method doesn't exist, add it inside the AppDelegate class\n // Find the end of the AppDelegate class\n const classEndRegex = /^}(\\s*$|\\s*\\/\\/)/m;\n const classEndMatch = content.match(classEndRegex);\n\n if (!classEndMatch) {\n logger.warn('Could not find end of AppDelegate class');\n return content;\n }\n\n // Insert the method inside the class\n const position = classEndMatch.index ?? 0;\n return (\n content.substring(0, position) +\n '\\n // Handle remote notification registration errors\\n' +\n ' public override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {\\n' +\n ' // Call CustomerIO SDK handler\\n' +\n ' cioSdkHandler.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\\n' +\n ' super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\\n' +\n ' }\\n' +\n content.substring(position)\n );\n }\n};\n\n/**\n * Add deep link handling for killed state\n *\n * On modern Expo Swift templates, RN is bootstrapped by `factory.startReactNative(...)`\n * inside an `#if os(iOS) || os(tvOS)` guard, *before* the trailing `return super.application(...)`.\n * The deep-link block must run before that call so `modifiedLaunchOptions` flows into RN's\n * initial launchOptions; otherwise the workaround is a no-op.\n *\n * For older templates (no `factory.startReactNative` — `super.application(...)` is what\n * starts RN), the snippet is injected before the return statement as before.\n */\nconst addHandleDeeplinkInKilledState = (content: string): string => {\n const deepLinkMarker = 'Deep link workaround for app killed state start';\n if (content.includes(deepLinkMarker)) {\n return content;\n }\n\n const returnStatementRegex =\n /return\\s+super\\.application\\s*\\(\\s*application\\s*,\\s*didFinishLaunchingWithOptions\\s*:\\s*launchOptions\\s*\\)/;\n const modifiedReturnStatement =\n 'return super.application(application, didFinishLaunchingWithOptions: modifiedLaunchOptions)';\n\n const factoryStartRegex =\n /(\\s*)#if\\s+os\\(iOS\\)\\s*\\|\\|\\s*os\\(tvOS\\)([\\s\\S]*?factory\\.startReactNative\\s*\\([\\s\\S]*?launchOptions:\\s*)launchOptions(\\s*\\)[\\s\\S]*?#endif)/;\n\n if (factoryStartRegex.test(content)) {\n let result = content.replace(\n factoryStartRegex,\n `\\n${CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET}\\n#if os(iOS) || os(tvOS)$2modifiedLaunchOptions$3`\n );\n if (returnStatementRegex.test(result)) {\n result = result.replace(returnStatementRegex, modifiedReturnStatement);\n }\n return result;\n }\n\n if (!returnStatementRegex.test(content)) {\n logger.warn('Could not find return statement with launchOptions');\n return content;\n }\n const replacementCode =\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET +\n '\\n\\n ' +\n modifiedReturnStatement;\n return content.replace(returnStatementRegex, replacementCode);\n};\n"],"mappings":"AAIA,SAASA,eAAe,EAAEC,gBAAgB,QAAQ,sBAAsB;AAExE,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,QAAQ,6BAA6B;AACtD,SACEC,+CAA+C,EAC/CC,0CAA0C,EAC1CC,8BAA8B,EAC9BC,iCAAiC,EACjCC,wCAAwC,EACxCC,0CAA0C,QACrC,0BAA0B;AACjC,SAASC,kBAAkB,QAAQ,gCAAgC;AACnE,SAASC,cAAc,QAAQ,iCAAiC;AAChE,SAASC,yBAAyB,QAAQ,wCAAwC;AAMlF,SAASC,MAAM,QAAQ,iBAAiB;AACxC,SAASC,qBAAqB,QAAQ,iBAAiB;AACvD,SAASC,eAAe,E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AAML,8BAA8B,GAAIlB,OAAe,IAAa;EAClE,MAAMsC,cAAc,GAAG,iDAAiD;EACxE,IAAItC,OAAO,CAACU,QAAQ,CAAC4B,cAAc,CAAC,EAAE;IACpC,OAAOtC,OAAO;EAChB;EAEA,MAAM4B,oBAAoB,GACxB,6GAA6G;EAC/G,MAAMW,uBAAuB,GAC3B,6FAA6F;EAE/F,MAAMC,iBAAiB,GACrB,6IAA6I;EAE/I,IAAIA,iBAAiB,CAACC,IAAI,CAACzC,OAAO,CAAC,EAAE;IACnC,IAAI0C,MAAM,GAAG1C,OAAO,CAACZ,OAAO,CAC1BoD,iBAAiB,EACjB,KAAK3G,+CAA+C,oDACtD,CAAC;IACD,IAAI+F,oBAAoB,CAACa,IAAI,CAACC,MAAM,CAAC,EAAE;MACrCA,MAAM,GAAGA,MAAM,CAACtD,OAAO,CAACwC,oBAAoB,EAAEW,uBAAuB,CAAC;IACxE;IACA,OAAOG,MAAM;EACf;EAEA,IAAI,CAACd,oBAAoB,CAACa,IAAI,CAACzC,OAAO,CAAC,EAAE;IACvC1D,MAAM,CAACc,IAAI,CAAC,oDAAoD,CAAC;IACjE,OAAO4C,OAAO;EAChB;EACA,MAAM2C,eAAe,GACnB9G,+CAA+C,GAC/C,UAAU,GACV0G,uBAAuB;EACzB,OAAOvC,OAAO,CAACZ,OAAO,CAACwC,oBAAoB,EAAEe,eAAe,CAAC;AAC/D,CAAC","ignoreList":[]}
|
|
@@ -1,20 +1,67 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const RN_SDK_PACKAGE = 'customerio-reactnative';
|
|
4
|
+
|
|
5
|
+
// Locate customerio-reactnative/package.json from a postinstall context.
|
|
6
|
+
//
|
|
7
|
+
// `INIT_CWD` is set by npm, pnpm, and yarn during lifecycle scripts to point
|
|
8
|
+
// at the consumer's project root. That makes it the most reliable starting
|
|
9
|
+
// point — the plugin's own __dirname can be deep inside `.pnpm/...` under pnpm.
|
|
10
|
+
//
|
|
11
|
+
// We probe `${INIT_CWD}/node_modules/customerio-reactnative/package.json` first
|
|
12
|
+
// so we agree with the symlinked layout React Native autolinking expects, then
|
|
13
|
+
// fall back to resolve-from from the consumer root, then to the legacy
|
|
14
|
+
// __dirname-relative walk-up for environments where INIT_CWD is missing.
|
|
15
|
+
function findRNSDKPackageJson() {
|
|
16
|
+
const candidates = [];
|
|
17
|
+
if (process.env.INIT_CWD) {
|
|
18
|
+
candidates.push(path.join(process.env.INIT_CWD, 'node_modules', RN_SDK_PACKAGE, 'package.json'));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Legacy flat-npm layout fallback: plugin lives at
|
|
22
|
+
// <consumer>/node_modules/customerio-expo-plugin/plugin/src and the SDK at
|
|
23
|
+
// <consumer>/node_modules/customerio-reactnative.
|
|
24
|
+
candidates.push(path.join(__dirname, '..', '..', '..', RN_SDK_PACKAGE, 'package.json'));
|
|
25
|
+
for (const candidate of candidates) {
|
|
26
|
+
if (fs.existsSync(candidate)) {
|
|
27
|
+
return candidate;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Final fallback: resolve-from from INIT_CWD. This walks up node_modules
|
|
32
|
+
// and handles yarn classic workspaces where the dep is hoisted.
|
|
33
|
+
if (process.env.INIT_CWD) {
|
|
34
|
+
try {
|
|
35
|
+
const resolveFrom = require('resolve-from');
|
|
36
|
+
const resolved = resolveFrom.silent(process.env.INIT_CWD, `${RN_SDK_PACKAGE}/package.json`);
|
|
37
|
+
if (resolved) return resolved;
|
|
38
|
+
} catch (_) {
|
|
39
|
+
// resolve-from missing or unable to resolve — fall through to null.
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
2
44
|
function runPostInstall() {
|
|
3
|
-
|
|
4
|
-
const reactNativePackageJsonFile = `${__dirname}/../../../customerio-reactnative/package.json`;
|
|
5
|
-
const expoPackageJsonFile = `${__dirname}/../../package.json`;
|
|
45
|
+
const expoPackageJsonFile = path.join(__dirname, '..', '..', 'package.json');
|
|
6
46
|
try {
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
47
|
+
const reactNativePackageJsonFile = findRNSDKPackageJson();
|
|
48
|
+
if (!reactNativePackageJsonFile) {
|
|
49
|
+
// Not necessarily an error: the plugin may be installed without the RN
|
|
50
|
+
// SDK (e.g., during a tooling-only install). The prebuild-time write
|
|
51
|
+
// covers the common case anyway.
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const expoPackageJson = require(expoPackageJsonFile);
|
|
55
|
+
const reactNativePackage = JSON.parse(fs.readFileSync(reactNativePackageJsonFile, 'utf8'));
|
|
56
|
+
if (reactNativePackage.expoVersion === expoPackageJson.version) {
|
|
57
|
+
return;
|
|
14
58
|
}
|
|
59
|
+
reactNativePackage.expoVersion = expoPackageJson.version;
|
|
60
|
+
fs.writeFileSync(reactNativePackageJsonFile, JSON.stringify(reactNativePackage, null, 2));
|
|
15
61
|
} catch (error) {
|
|
16
|
-
console.warn('
|
|
62
|
+
console.warn('customerio-expo-plugin postinstall: failed to write expoVersion into customerio-reactnative/package.json. ' + 'The expo prebuild step will retry this. Original error:', error);
|
|
17
63
|
}
|
|
18
64
|
}
|
|
19
65
|
exports.runPostInstall = runPostInstall;
|
|
66
|
+
exports.findRNSDKPackageJson = findRNSDKPackageJson;
|
|
20
67
|
//# sourceMappingURL=postInstallHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["fs","require","
|
|
1
|
+
{"version":3,"names":["fs","require","path","RN_SDK_PACKAGE","findRNSDKPackageJson","candidates","process","env","INIT_CWD","push","join","__dirname","candidate","existsSync","resolveFrom","resolved","silent","_","runPostInstall","expoPackageJsonFile","reactNativePackageJsonFile","expoPackageJson","reactNativePackage","JSON","parse","readFileSync","expoVersion","version","writeFileSync","stringify","error","console","warn","exports"],"sources":["postInstallHelper.js"],"sourcesContent":["const fs = require('fs');\nconst path = require('path');\n\nconst RN_SDK_PACKAGE = 'customerio-reactnative';\n\n// Locate customerio-reactnative/package.json from a postinstall context.\n//\n// `INIT_CWD` is set by npm, pnpm, and yarn during lifecycle scripts to point\n// at the consumer's project root. That makes it the most reliable starting\n// point — the plugin's own __dirname can be deep inside `.pnpm/...` under pnpm.\n//\n// We probe `${INIT_CWD}/node_modules/customerio-reactnative/package.json` first\n// so we agree with the symlinked layout React Native autolinking expects, then\n// fall back to resolve-from from the consumer root, then to the legacy\n// __dirname-relative walk-up for environments where INIT_CWD is missing.\nfunction findRNSDKPackageJson() {\n const candidates = [];\n\n if (process.env.INIT_CWD) {\n candidates.push(\n path.join(process.env.INIT_CWD, 'node_modules', RN_SDK_PACKAGE, 'package.json')\n );\n }\n\n // Legacy flat-npm layout fallback: plugin lives at\n // <consumer>/node_modules/customerio-expo-plugin/plugin/src and the SDK at\n // <consumer>/node_modules/customerio-reactnative.\n candidates.push(path.join(__dirname, '..', '..', '..', RN_SDK_PACKAGE, 'package.json'));\n\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n }\n\n // Final fallback: resolve-from from INIT_CWD. This walks up node_modules\n // and handles yarn classic workspaces where the dep is hoisted.\n if (process.env.INIT_CWD) {\n try {\n const resolveFrom = require('resolve-from');\n const resolved = resolveFrom.silent(\n process.env.INIT_CWD,\n `${RN_SDK_PACKAGE}/package.json`\n );\n if (resolved) return resolved;\n } catch (_) {\n // resolve-from missing or unable to resolve — fall through to null.\n }\n }\n\n return null;\n}\n\nfunction runPostInstall() {\n const expoPackageJsonFile = path.join(__dirname, '..', '..', 'package.json');\n\n try {\n const reactNativePackageJsonFile = findRNSDKPackageJson();\n if (!reactNativePackageJsonFile) {\n // Not necessarily an error: the plugin may be installed without the RN\n // SDK (e.g., during a tooling-only install). The prebuild-time write\n // covers the common case anyway.\n return;\n }\n\n const expoPackageJson = require(expoPackageJsonFile);\n const reactNativePackage = JSON.parse(\n fs.readFileSync(reactNativePackageJsonFile, 'utf8')\n );\n\n if (reactNativePackage.expoVersion === expoPackageJson.version) {\n return;\n }\n\n reactNativePackage.expoVersion = expoPackageJson.version;\n fs.writeFileSync(\n reactNativePackageJsonFile,\n JSON.stringify(reactNativePackage, null, 2)\n );\n } catch (error) {\n console.warn(\n 'customerio-expo-plugin postinstall: failed to write expoVersion into customerio-reactnative/package.json. ' +\n 'The expo prebuild step will retry this. Original error:',\n error\n );\n }\n}\n\nexports.runPostInstall = runPostInstall;\nexports.findRNSDKPackageJson = findRNSDKPackageJson;\n"],"mappings":"AAAA,MAAMA,EAAE,GAAGC,OAAO,CAAC,IAAI,CAAC;AACxB,MAAMC,IAAI,GAAGD,OAAO,CAAC,MAAM,CAAC;AAE5B,MAAME,cAAc,GAAG,wBAAwB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,oBAAoBA,CAAA,EAAG;EAC9B,MAAMC,UAAU,GAAG,EAAE;EAErB,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,EAAE;IACxBH,UAAU,CAACI,IAAI,CACbP,IAAI,CAACQ,IAAI,CAACJ,OAAO,CAACC,GAAG,CAACC,QAAQ,EAAE,cAAc,EAAEL,cAAc,EAAE,cAAc,CAChF,CAAC;EACH;;EAEA;EACA;EACA;EACAE,UAAU,CAACI,IAAI,CAACP,IAAI,CAACQ,IAAI,CAACC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAER,cAAc,EAAE,cAAc,CAAC,CAAC;EAEvF,KAAK,MAAMS,SAAS,IAAIP,UAAU,EAAE;IAClC,IAAIL,EAAE,CAACa,UAAU,CAACD,SAAS,CAAC,EAAE;MAC5B,OAAOA,SAAS;IAClB;EACF;;EAEA;EACA;EACA,IAAIN,OAAO,CAACC,GAAG,CAACC,QAAQ,EAAE;IACxB,IAAI;MACF,MAAMM,WAAW,GAAGb,OAAO,CAAC,cAAc,CAAC;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customerio-reactnative';
|
|
4
|
+
const REACT_NATIVE_PACKAGE = 'react-native';
|
|
5
|
+
// Reads the installed react-native package's version starting from `fromDir`.
|
|
6
|
+
// Used to decide which autolinking flavor will resolve customerio-reactnative
|
|
7
|
+
// at pod install time, so our :path agrees with what autolinking emits:
|
|
8
|
+
// - RN <0.80 ships @react-native-community/cli, which uses a lexical
|
|
9
|
+
// resolution (no realpath following).
|
|
10
|
+
// - RN >=0.80 routes pod autolinking through expo-modules-autolinking,
|
|
11
|
+
// which realpaths.
|
|
12
|
+
// Returns null if react-native cannot be located or its package.json cannot
|
|
13
|
+
// be read; callers should default to the modern (realpath) behavior in that
|
|
14
|
+
// case since it has been the working path for the last several Expo SDKs.
|
|
15
|
+
export function tryReadRNVersion(fromDir) {
|
|
16
|
+
try {
|
|
17
|
+
const direct = path.join(fromDir, 'node_modules', REACT_NATIVE_PACKAGE, 'package.json');
|
|
18
|
+
if (fs.existsSync(direct)) {
|
|
19
|
+
return readVersion(direct);
|
|
20
|
+
}
|
|
21
|
+
const resolveFrom = require('resolve-from');
|
|
22
|
+
const fallback = resolveFrom.silent(fromDir, `${REACT_NATIVE_PACKAGE}/package.json`);
|
|
23
|
+
if (fallback) {
|
|
24
|
+
return readVersion(fallback);
|
|
25
|
+
}
|
|
26
|
+
} catch {
|
|
27
|
+
// Fall through to null.
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function readVersion(pkgJsonPath) {
|
|
32
|
+
try {
|
|
33
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
34
|
+
return typeof pkg.version === 'string' ? pkg.version : null;
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Resolves the customerio-reactnative SDK location starting from `fromDir`.
|
|
41
|
+
//
|
|
42
|
+
// Probe-then-fallback so the result agrees with React Native autolinking
|
|
43
|
+
// across npm flat, pnpm, and yarn-workspace layouts:
|
|
44
|
+
// 1. `fromDir/node_modules/customerio-reactnative/package.json` — preferred.
|
|
45
|
+
// Works for npm flat, pnpm (the symlinked path; we never realpath it),
|
|
46
|
+
// and yarn workspaces with leaf node_modules. Matches what RN
|
|
47
|
+
// autolinking emits for its pod entry, so CocoaPods sees one
|
|
48
|
+
// consistent :path.
|
|
49
|
+
// 2. `resolve-from` walking up from `fromDir` — only used when (1) misses.
|
|
50
|
+
// Handles yarn classic workspaces where the dep is hoisted to a parent
|
|
51
|
+
// node_modules. yarn classic has no symlinks, so the realpath is fine.
|
|
52
|
+
//
|
|
53
|
+
// Returns null if neither finds the package, including the case where
|
|
54
|
+
// `resolve-from` itself can't be required (mirrors tryReadRNVersion's
|
|
55
|
+
// graceful-failure shape so callers can rely on the documented contract).
|
|
56
|
+
export function tryResolveRNSDK(fromDir) {
|
|
57
|
+
try {
|
|
58
|
+
const directPkgJson = path.join(fromDir, 'node_modules', RN_SDK_PACKAGE, 'package.json');
|
|
59
|
+
if (fs.existsSync(directPkgJson)) {
|
|
60
|
+
return {
|
|
61
|
+
packageDir: path.dirname(directPkgJson),
|
|
62
|
+
packageJsonPath: directPkgJson
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const resolveFrom = require('resolve-from');
|
|
66
|
+
const fallbackPkgJson = resolveFrom.silent(fromDir, `${RN_SDK_PACKAGE}/package.json`);
|
|
67
|
+
if (fallbackPkgJson) {
|
|
68
|
+
return {
|
|
69
|
+
packageDir: path.dirname(fallbackPkgJson),
|
|
70
|
+
packageJsonPath: fallbackPkgJson
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
// Fall through to null. resolveRNSDK() turns this into a clear
|
|
75
|
+
// "customerio-reactnative was not found" error for the caller.
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Same as tryResolveRNSDK but throws a clear error when the package is missing.
|
|
81
|
+
export function resolveRNSDK(fromDir) {
|
|
82
|
+
const resolved = tryResolveRNSDK(fromDir);
|
|
83
|
+
if (!resolved) {
|
|
84
|
+
throw new Error(`${RN_SDK_PACKAGE} was not found relative to ${fromDir}. ` + `Ensure it is installed in your project (or in a parent workspace's node_modules).`);
|
|
85
|
+
}
|
|
86
|
+
return resolved;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=resolveRNSDK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fs","path","RN_SDK_PACKAGE","REACT_NATIVE_PACKAGE","tryReadRNVersion","fromDir","direct","join","existsSync","readVersion","resolveFrom","require","fallback","silent","pkgJsonPath","pkg","JSON","parse","readFileSync","version","tryResolveRNSDK","directPkgJson","packageDir","dirname","packageJsonPath","fallbackPkgJson","resolveRNSDK","resolved","Error"],"sources":["resolveRNSDK.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nconst RN_SDK_PACKAGE = 'customerio-reactnative';\nconst REACT_NATIVE_PACKAGE = 'react-native';\n\nexport type ResolvedRNSDK = {\n // Absolute path to the package directory.\n packageDir: string;\n // Absolute path to package.json inside that directory.\n packageJsonPath: string;\n};\n\n// Reads the installed react-native package's version starting from `fromDir`.\n// Used to decide which autolinking flavor will resolve customerio-reactnative\n// at pod install time, so our :path agrees with what autolinking emits:\n// - RN <0.80 ships @react-native-community/cli, which uses a lexical\n// resolution (no realpath following).\n// - RN >=0.80 routes pod autolinking through expo-modules-autolinking,\n// which realpaths.\n// Returns null if react-native cannot be located or its package.json cannot\n// be read; callers should default to the modern (realpath) behavior in that\n// case since it has been the working path for the last several Expo SDKs.\nexport function tryReadRNVersion(fromDir: string): string | null {\n try {\n const direct = path.join(\n fromDir,\n 'node_modules',\n REACT_NATIVE_PACKAGE,\n 'package.json'\n );\n if (fs.existsSync(direct)) {\n return readVersion(direct);\n }\n const resolveFrom = require('resolve-from');\n const fallback = resolveFrom.silent(\n fromDir,\n `${REACT_NATIVE_PACKAGE}/package.json`\n );\n if (fallback) {\n return readVersion(fallback);\n }\n } catch {\n // Fall through to null.\n }\n return null;\n}\n\nfunction readVersion(pkgJsonPath: string): string | null {\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));\n return typeof pkg.version === 'string' ? pkg.version : null;\n } catch {\n return null;\n }\n}\n\n// Resolves the customerio-reactnative SDK location starting from `fromDir`.\n//\n// Probe-then-fallback so the result agrees with React Native autolinking\n// across npm flat, pnpm, and yarn-workspace layouts:\n// 1. `fromDir/node_modules/customerio-reactnative/package.json` — preferred.\n// Works for npm flat, pnpm (the symlinked path; we never realpath it),\n// and yarn workspaces with leaf node_modules. Matches what RN\n// autolinking emits for its pod entry, so CocoaPods sees one\n// consistent :path.\n// 2. `resolve-from` walking up from `fromDir` — only used when (1) misses.\n// Handles yarn classic workspaces where the dep is hoisted to a parent\n// node_modules. yarn classic has no symlinks, so the realpath is fine.\n//\n// Returns null if neither finds the package, including the case where\n// `resolve-from` itself can't be required (mirrors tryReadRNVersion's\n// graceful-failure shape so callers can rely on the documented contract).\nexport function tryResolveRNSDK(fromDir: string): ResolvedRNSDK | null {\n try {\n const directPkgJson = path.join(\n fromDir,\n 'node_modules',\n RN_SDK_PACKAGE,\n 'package.json'\n );\n if (fs.existsSync(directPkgJson)) {\n return {\n packageDir: path.dirname(directPkgJson),\n packageJsonPath: directPkgJson,\n };\n }\n\n const resolveFrom = require('resolve-from');\n const fallbackPkgJson = resolveFrom.silent(\n fromDir,\n `${RN_SDK_PACKAGE}/package.json`\n );\n if (fallbackPkgJson) {\n return {\n packageDir: path.dirname(fallbackPkgJson),\n packageJsonPath: fallbackPkgJson,\n };\n }\n } catch {\n // Fall through to null. resolveRNSDK() turns this into a clear\n // \"customerio-reactnative was not found\" error for the caller.\n }\n\n return null;\n}\n\n// Same as tryResolveRNSDK but throws a clear error when the package is missing.\nexport function resolveRNSDK(fromDir: string): ResolvedRNSDK {\n const resolved = tryResolveRNSDK(fromDir);\n if (!resolved) {\n throw new Error(\n `${RN_SDK_PACKAGE} was not found relative to ${fromDir}. ` +\n `Ensure it is installed in your project (or in a parent workspace's node_modules).`\n );\n }\n return resolved;\n}\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AAEvB,MAAMC,cAAc,GAAG,wBAAwB;AAC/C,MAAMC,oBAAoB,GAAG,cAAc;AAS3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,OAAe,EAAiB;EAC/D,IAAI;IACF,MAAMC,MAAM,GAAGL,IAAI,CAACM,IAAI,CACtBF,OAAO,EACP,cAAc,EACdF,oBAAoB,EACpB,cACF,CAAC;IACD,IAAIH,EAAE,CAACQ,UAAU,CAACF,MAAM,CAAC,EAAE;MACzB,OAAOG,WAAW,CAACH,MAAM,CAAC;IAC5B;IACA,MAAMI,WAAW,GAAGC,OAAO,CAAC,cAAc,CAAC;IAC3C,MAAMC,QAAQ,GAAGF,WAAW,CAACG,MAAM,CACjCR,OAAO,EACP,GAAGF,oBAAoB,eACzB,CAAC;IACD,IAAIS,QAAQ,EAAE;MACZ,OAAOH,WAAW,CAACG,QAAQ,CAAC;IAC9B;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAEF,OAAO,IAAI;AACb;AAEA,SAASH,WAAWA,CAACK,WAAmB,EAAiB;EACvD,IAAI;IACF,MAAMC,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACjB,EAAE,CAACkB,YAAY,CAACJ,WAAW,EAAE,OAAO,CAAC,CAAC;IAC7D,OAAO,OAAOC,GAAG,CAACI,OAAO,KAAK,QAAQ,GAAGJ,GAAG,CAACI,OAAO,GAAG,IAAI;EAC7D,CAAC,CAAC,MAAM;IACN,OAAO,IAAI;EACb;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACf,OAAe,EAAwB;EACrE,IAAI;IACF,MAAMgB,aAAa,GAAGpB,IAAI,CAACM,IAAI,CAC7BF,OAAO,EACP,cAAc,EACdH,cAAc,EACd,cACF,CAAC;IACD,IAAIF,EAAE,CAACQ,UAAU,CAACa,aAAa,CAAC,EAAE;MAChC,OAAO;QACLC,UAAU,EAAErB,IAAI,CAACsB,OAAO,CAACF,aAAa,CAAC;QACvCG,eAAe,EAAEH;MACnB,CAAC;IACH;IAEA,MAAMX,WAAW,GAAGC,OAAO,CAAC,cAAc,CAAC;IAC3C,MAAMc,eAAe,GAAGf,WAAW,CAACG,MAAM,CACxCR,OAAO,EACP,GAAGH,cAAc,eACnB,CAAC;IACD,IAAIuB,eAAe,EAAE;MACnB,OAAO;QACLH,UAAU,EAAErB,IAAI,CAACsB,OAAO,CAACE,eAAe,CAAC;QACzCD,eAAe,EAAEC;MACnB,CAAC;IACH;EACF,CAAC,CAAC,MAAM;IACN;IACA;EAAA;EAGF,OAAO,IAAI;AACb;;AAEA;AACA,OAAO,SAASC,YAAYA,CAACrB,OAAe,EAAiB;EAC3D,MAAMsB,QAAQ,GAAGP,eAAe,CAACf,OAAO,CAAC;EACzC,IAAI,CAACsB,QAAQ,EAAE;IACb,MAAM,IAAIC,KAAK,CACb,GAAG1B,cAAc,8BAA8BG,OAAO,IAAI,GAC1D,mFACF,CAAC;EACH;EACA,OAAOsB,QAAQ;AACjB","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { logger } from './logger';
|
|
3
|
+
import { getPluginVersion } from './plugin';
|
|
4
|
+
import { tryResolveRNSDK } from './resolveRNSDK';
|
|
5
|
+
|
|
6
|
+
// Writes the plugin's version into customerio-reactnative/package.json under
|
|
7
|
+
// the `expoVersion` key. The RN SDK reads this at runtime (customerio-cdp.ts)
|
|
8
|
+
// to set its User-Agent `packageSource` to "Expo" instead of "ReactNative".
|
|
9
|
+
//
|
|
10
|
+
// We rely on the postinstall hook (postInstallHelper.js) for the same write
|
|
11
|
+
// at install time, but call this from the plugin entry as a fallback for
|
|
12
|
+
// installs where postinstall does not run cleanly — most notably pnpm
|
|
13
|
+
// monorepos and any CI that uses --ignore-scripts.
|
|
14
|
+
//
|
|
15
|
+
// The write is idempotent: we no-op when the value is already correct.
|
|
16
|
+
export function writeExpoVersion(projectRoot) {
|
|
17
|
+
let resolved;
|
|
18
|
+
try {
|
|
19
|
+
resolved = tryResolveRNSDK(projectRoot);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
logger.warn(`Could not locate customerio-reactnative to write expoVersion. ` + `User-Agent attribution may be incorrect. Original error: ${error}`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!resolved) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const pluginVersion = getPluginVersion();
|
|
29
|
+
const pkg = JSON.parse(fs.readFileSync(resolved.packageJsonPath, 'utf8'));
|
|
30
|
+
if (pkg.expoVersion === pluginVersion) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
pkg.expoVersion = pluginVersion;
|
|
34
|
+
fs.writeFileSync(resolved.packageJsonPath, JSON.stringify(pkg, null, 2));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logger.warn(`Failed to write expoVersion into ${resolved.packageJsonPath}. ` + `User-Agent attribution may be incorrect. Original error: ${error}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export const withExpoVersion = config => {
|
|
40
|
+
var _internal;
|
|
41
|
+
// _internal.projectRoot is set by Expo when running through prebuild;
|
|
42
|
+
// fall back to process.cwd() for any path that calls the plugin in
|
|
43
|
+
// a non-prebuild context.
|
|
44
|
+
const projectRoot = ((_internal = config._internal) === null || _internal === void 0 ? void 0 : _internal.projectRoot) || process.cwd();
|
|
45
|
+
writeExpoVersion(projectRoot);
|
|
46
|
+
return config;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=writeExpoVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fs","logger","getPluginVersion","tryResolveRNSDK","writeExpoVersion","projectRoot","resolved","error","warn","pluginVersion","pkg","JSON","parse","readFileSync","packageJsonPath","expoVersion","writeFileSync","stringify","withExpoVersion","config","_internal","process","cwd"],"sources":["writeExpoVersion.ts"],"sourcesContent":["import fs from 'fs';\nimport type { ConfigPlugin } from '@expo/config-plugins';\n\nimport { logger } from './logger';\nimport { getPluginVersion } from './plugin';\nimport { tryResolveRNSDK } from './resolveRNSDK';\n\n// Writes the plugin's version into customerio-reactnative/package.json under\n// the `expoVersion` key. The RN SDK reads this at runtime (customerio-cdp.ts)\n// to set its User-Agent `packageSource` to \"Expo\" instead of \"ReactNative\".\n//\n// We rely on the postinstall hook (postInstallHelper.js) for the same write\n// at install time, but call this from the plugin entry as a fallback for\n// installs where postinstall does not run cleanly — most notably pnpm\n// monorepos and any CI that uses --ignore-scripts.\n//\n// The write is idempotent: we no-op when the value is already correct.\nexport function writeExpoVersion(projectRoot: string): void {\n let resolved;\n try {\n resolved = tryResolveRNSDK(projectRoot);\n } catch (error) {\n logger.warn(\n `Could not locate customerio-reactnative to write expoVersion. ` +\n `User-Agent attribution may be incorrect. Original error: ${error}`\n );\n return;\n }\n\n if (!resolved) {\n return;\n }\n\n try {\n const pluginVersion = getPluginVersion();\n const pkg = JSON.parse(fs.readFileSync(resolved.packageJsonPath, 'utf8'));\n if (pkg.expoVersion === pluginVersion) {\n return;\n }\n pkg.expoVersion = pluginVersion;\n fs.writeFileSync(\n resolved.packageJsonPath,\n JSON.stringify(pkg, null, 2)\n );\n } catch (error) {\n logger.warn(\n `Failed to write expoVersion into ${resolved.packageJsonPath}. ` +\n `User-Agent attribution may be incorrect. Original error: ${error}`\n );\n }\n}\n\nexport const withExpoVersion: ConfigPlugin = (config) => {\n // _internal.projectRoot is set by Expo when running through prebuild;\n // fall back to process.cwd() for any path that calls the plugin in\n // a non-prebuild context.\n const projectRoot =\n (config as unknown as { _internal?: { projectRoot?: string } })._internal?.projectRoot ||\n process.cwd();\n writeExpoVersion(projectRoot);\n return config;\n};\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AAGnB,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,gBAAgB,QAAQ,UAAU;AAC3C,SAASC,eAAe,QAAQ,gBAAgB;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,WAAmB,EAAQ;EAC1D,IAAIC,QAAQ;EACZ,IAAI;IACFA,QAAQ,GAAGH,eAAe,CAACE,WAAW,CAAC;EACzC,CAAC,CAAC,OAAOE,KAAK,EAAE;IACdN,MAAM,CAACO,IAAI,CACT,gEAAgE,GAChE,4DAA4DD,KAAK,EACnE,CAAC;IACD;EACF;EAEA,IAAI,CAACD,QAAQ,EAAE;IACb;EACF;EAEA,IAAI;IACF,MAAMG,aAAa,GAAGP,gBAAgB,CAAC,CAAC;IACxC,MAAMQ,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACZ,EAAE,CAACa,YAAY,CAACP,QAAQ,CAACQ,eAAe,EAAE,MAAM,CAAC,CAAC;IACzE,IAAIJ,GAAG,CAACK,WAAW,KAAKN,aAAa,EAAE;MACrC;IACF;IACAC,GAAG,CAACK,WAAW,GAAGN,aAAa;IAC/BT,EAAE,CAACgB,aAAa,CACdV,QAAQ,CAACQ,eAAe,EACxBH,IAAI,CAACM,SAAS,CAACP,GAAG,EAAE,IAAI,EAAE,CAAC,CAC7B,CAAC;EACH,CAAC,CAAC,OAAOH,KAAK,EAAE;IACdN,MAAM,CAACO,IAAI,CACT,oCAAoCF,QAAQ,CAACQ,eAAe,IAAI,GAChE,4DAA4DP,KAAK,EACnE,CAAC;EACH;AACF;AAEA,OAAO,MAAMW,eAA6B,GAAIC,MAAM,IAAK;EAAA,IAAAC,SAAA;EACvD;EACA;EACA;EACA,MAAMf,WAAW,GACf,EAAAe,SAAA,GAACD,MAAM,CAAyDC,SAAS,cAAAA,SAAA,uBAAzEA,SAAA,CAA2Ef,WAAW,KACtFgB,OAAO,CAACC,GAAG,CAAC,CAAC;EACflB,gBAAgB,CAACC,WAAW,CAAC;EAC7B,OAAOc,MAAM;AACf,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the relative path from the iOS project dir to the installed
|
|
3
|
+
* customerio-reactnative directory, in the exact form React Native pod
|
|
4
|
+
* autolinking will emit for the same package. The two autolinking
|
|
5
|
+
* flavors disagree on path shape under pnpm/yarn symlinks:
|
|
6
|
+
*
|
|
7
|
+
* - RN <0.80 (`@react-native-community/cli`): walks node_modules
|
|
8
|
+
* lexically, preserves symlinks. We keep the symlink path too —
|
|
9
|
+
* `tryResolveRNSDK` already does this without calling realpath.
|
|
10
|
+
*
|
|
11
|
+
* - RN >=0.80 (`expo-modules-autolinking`): realpaths the package
|
|
12
|
+
* via Node, emitting the underlying `.pnpm/...` (or yarn-classic)
|
|
13
|
+
* path. We match by realpath'ing the resolved directory.
|
|
14
|
+
*
|
|
15
|
+
* Decision points are logged so a customer's prebuild output is enough
|
|
16
|
+
* to triage path-resolution issues without a follow-up "set
|
|
17
|
+
* CUSTOMERIO_DEBUG_MODE and rerun" round-trip.
|
|
18
|
+
*/
|
|
1
19
|
export declare function getRelativePathToRNSDK(iosPath: string): any;
|
|
2
20
|
export declare const IOS_DEPLOYMENT_TARGET = "13.0";
|
|
3
21
|
export declare const GROUP_IDENTIFIER_TEMPLATE_REGEX: RegExp;
|
|
@@ -5,7 +5,17 @@ export type InjectCIOPodfileOptions = {
|
|
|
5
5
|
/** When false and locationEnabled, inject only :subspecs => ['location']. When true, use push + location. */
|
|
6
6
|
hasPush?: boolean;
|
|
7
7
|
};
|
|
8
|
-
/** Builds the host
|
|
8
|
+
/** Builds the host-app pod snippet for the Podfile.
|
|
9
|
+
*
|
|
10
|
+
* The :path is resolved at prebuild time by `getRelativePathToRNSDK`,
|
|
11
|
+
* which dispatches on the installed React Native version so the path
|
|
12
|
+
* matches what RN pod autolinking will emit (lexical for RN <0.80,
|
|
13
|
+
* realpath for RN >=0.80). Baking the resolved string directly avoids
|
|
14
|
+
* any Ruby/install-time logic in the Podfile and keeps the snippet
|
|
15
|
+
* trivially diff-able.
|
|
16
|
+
*
|
|
17
|
+
* Exported for tests.
|
|
18
|
+
*/
|
|
9
19
|
export declare function buildHostAppPodSnippet(iosPath: string, isFcmPushProvider: boolean, options?: InjectCIOPodfileOptions): string;
|
|
10
20
|
export declare function injectCIOPodfileCode(iosPath: string, isFcmPushProvider: boolean, options?: InjectCIOPodfileOptions): Promise<void>;
|
|
11
21
|
export declare function injectCIONotificationPodfileCode(iosPath: string, useFrameworks: CustomerIOPluginOptionsIOS['useFrameworks'], isFcmPushProvider: boolean): Promise<void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ResolvedRNSDK = {
|
|
2
|
+
packageDir: string;
|
|
3
|
+
packageJsonPath: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function tryReadRNVersion(fromDir: string): string | null;
|
|
6
|
+
export declare function tryResolveRNSDK(fromDir: string): ResolvedRNSDK | null;
|
|
7
|
+
export declare function resolveRNSDK(fromDir: string): ResolvedRNSDK;
|