customerio-expo-plugin 3.3.0 → 3.5.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.
Files changed (107) hide show
  1. package/package.json +8 -1
  2. package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js +64 -59
  3. package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js.map +1 -1
  4. package/plugin/lib/commonjs/android/withAppGoogleServices.js +10 -7
  5. package/plugin/lib/commonjs/android/withAppGoogleServices.js.map +1 -1
  6. package/plugin/lib/commonjs/android/withGoogleServicesJSON.js +18 -21
  7. package/plugin/lib/commonjs/android/withGoogleServicesJSON.js.map +1 -1
  8. package/plugin/lib/commonjs/android/withLocationGradleProperties.js +16 -12
  9. package/plugin/lib/commonjs/android/withLocationGradleProperties.js.map +1 -1
  10. package/plugin/lib/commonjs/android/withMainApplicationModifications.js +19 -12
  11. package/plugin/lib/commonjs/android/withMainApplicationModifications.js.map +1 -1
  12. package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js +2 -1
  13. package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js.map +1 -1
  14. package/plugin/lib/commonjs/android/withProjectBuildGradle.js +29 -25
  15. package/plugin/lib/commonjs/android/withProjectBuildGradle.js.map +1 -1
  16. package/plugin/lib/commonjs/android/withProjectGoogleServices.js +9 -5
  17. package/plugin/lib/commonjs/android/withProjectGoogleServices.js.map +1 -1
  18. package/plugin/lib/commonjs/helpers/constants/ios.js +76 -8
  19. package/plugin/lib/commonjs/helpers/constants/ios.js.map +1 -1
  20. package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js +76 -31
  21. package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  22. package/plugin/lib/commonjs/index.js +7 -0
  23. package/plugin/lib/commonjs/index.js.map +1 -1
  24. package/plugin/lib/commonjs/ios/withAppDelegateModifications.js +47 -33
  25. package/plugin/lib/commonjs/ios/withAppDelegateModifications.js.map +1 -1
  26. package/plugin/lib/commonjs/ios/withCIOIosSwift.js +44 -54
  27. package/plugin/lib/commonjs/ios/withCIOIosSwift.js.map +1 -1
  28. package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js +46 -30
  29. package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js.map +1 -1
  30. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js +192 -122
  31. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js.map +1 -1
  32. package/plugin/lib/commonjs/postInstallHelper.js +58 -11
  33. package/plugin/lib/commonjs/postInstallHelper.js.map +1 -1
  34. package/plugin/lib/commonjs/utils/resolveRNSDK.js +97 -0
  35. package/plugin/lib/commonjs/utils/resolveRNSDK.js.map +1 -0
  36. package/plugin/lib/commonjs/utils/writeExpoVersion.js +56 -0
  37. package/plugin/lib/commonjs/utils/writeExpoVersion.js.map +1 -0
  38. package/plugin/lib/module/android/withAndroidManifestUpdates.js +61 -58
  39. package/plugin/lib/module/android/withAndroidManifestUpdates.js.map +1 -1
  40. package/plugin/lib/module/android/withAppGoogleServices.js +9 -7
  41. package/plugin/lib/module/android/withAppGoogleServices.js.map +1 -1
  42. package/plugin/lib/module/android/withGoogleServicesJSON.js +17 -21
  43. package/plugin/lib/module/android/withGoogleServicesJSON.js.map +1 -1
  44. package/plugin/lib/module/android/withLocationGradleProperties.js +15 -12
  45. package/plugin/lib/module/android/withLocationGradleProperties.js.map +1 -1
  46. package/plugin/lib/module/android/withMainApplicationModifications.js +18 -12
  47. package/plugin/lib/module/android/withMainApplicationModifications.js.map +1 -1
  48. package/plugin/lib/module/android/withNotificationChannelMetadata.js +1 -1
  49. package/plugin/lib/module/android/withNotificationChannelMetadata.js.map +1 -1
  50. package/plugin/lib/module/android/withProjectBuildGradle.js +28 -25
  51. package/plugin/lib/module/android/withProjectBuildGradle.js.map +1 -1
  52. package/plugin/lib/module/android/withProjectGoogleServices.js +8 -5
  53. package/plugin/lib/module/android/withProjectGoogleServices.js.map +1 -1
  54. package/plugin/lib/module/helpers/constants/ios.js +75 -8
  55. package/plugin/lib/module/helpers/constants/ios.js.map +1 -1
  56. package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js +74 -31
  57. package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  58. package/plugin/lib/module/index.js +7 -0
  59. package/plugin/lib/module/index.js.map +1 -1
  60. package/plugin/lib/module/ios/withAppDelegateModifications.js +45 -33
  61. package/plugin/lib/module/ios/withAppDelegateModifications.js.map +1 -1
  62. package/plugin/lib/module/ios/withCIOIosSwift.js +42 -54
  63. package/plugin/lib/module/ios/withCIOIosSwift.js.map +1 -1
  64. package/plugin/lib/module/ios/withGoogleServicesJsonFile.js +45 -30
  65. package/plugin/lib/module/ios/withGoogleServicesJsonFile.js.map +1 -1
  66. package/plugin/lib/module/ios/withNotificationsXcodeProject.js +187 -122
  67. package/plugin/lib/module/ios/withNotificationsXcodeProject.js.map +1 -1
  68. package/plugin/lib/module/postInstallHelper.js +58 -11
  69. package/plugin/lib/module/postInstallHelper.js.map +1 -1
  70. package/plugin/lib/module/utils/resolveRNSDK.js +88 -0
  71. package/plugin/lib/module/utils/resolveRNSDK.js.map +1 -0
  72. package/plugin/lib/module/utils/writeExpoVersion.js +48 -0
  73. package/plugin/lib/module/utils/writeExpoVersion.js.map +1 -0
  74. package/plugin/lib/typescript/android/withAndroidManifestUpdates.d.ts +2 -0
  75. package/plugin/lib/typescript/android/withAppGoogleServices.d.ts +1 -0
  76. package/plugin/lib/typescript/android/withGoogleServicesJSON.d.ts +1 -0
  77. package/plugin/lib/typescript/android/withLocationGradleProperties.d.ts +2 -0
  78. package/plugin/lib/typescript/android/withMainApplicationModifications.d.ts +6 -0
  79. package/plugin/lib/typescript/android/withNotificationChannelMetadata.d.ts +5 -0
  80. package/plugin/lib/typescript/android/withProjectBuildGradle.d.ts +9 -0
  81. package/plugin/lib/typescript/android/withProjectGoogleServices.d.ts +1 -0
  82. package/plugin/lib/typescript/helpers/constants/ios.d.ts +18 -0
  83. package/plugin/lib/typescript/helpers/utils/injectCIOPodfileCode.d.ts +25 -1
  84. package/plugin/lib/typescript/ios/withAppDelegateModifications.d.ts +13 -0
  85. package/plugin/lib/typescript/ios/withCIOIosSwift.d.ts +11 -0
  86. package/plugin/lib/typescript/ios/withGoogleServicesJsonFile.d.ts +14 -1
  87. package/plugin/lib/typescript/ios/withNotificationsXcodeProject.d.ts +53 -2
  88. package/plugin/lib/typescript/utils/resolveRNSDK.d.ts +7 -0
  89. package/plugin/lib/typescript/utils/writeExpoVersion.d.ts +3 -0
  90. package/plugin/src/android/withAndroidManifestUpdates.ts +83 -73
  91. package/plugin/src/android/withAppGoogleServices.ts +13 -11
  92. package/plugin/src/android/withGoogleServicesJSON.ts +30 -28
  93. package/plugin/src/android/withLocationGradleProperties.ts +23 -17
  94. package/plugin/src/android/withMainApplicationModifications.ts +25 -15
  95. package/plugin/src/android/withNotificationChannelMetadata.ts +1 -1
  96. package/plugin/src/android/withProjectBuildGradle.ts +37 -27
  97. package/plugin/src/android/withProjectGoogleServices.ts +14 -9
  98. package/plugin/src/helpers/constants/ios.ts +87 -8
  99. package/plugin/src/helpers/utils/injectCIOPodfileCode.ts +97 -50
  100. package/plugin/src/index.ts +7 -0
  101. package/plugin/src/ios/withAppDelegateModifications.ts +61 -48
  102. package/plugin/src/ios/withCIOIosSwift.ts +58 -62
  103. package/plugin/src/ios/withGoogleServicesJsonFile.ts +66 -48
  104. package/plugin/src/ios/withNotificationsXcodeProject.ts +257 -207
  105. package/plugin/src/postInstallHelper.js +75 -17
  106. package/plugin/src/utils/resolveRNSDK.ts +118 -0
  107. package/plugin/src/utils/writeExpoVersion.ts +62 -0
@@ -1,32 +1,90 @@
1
1
  const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const RN_SDK_PACKAGE = 'customerio-reactnative';
5
+
6
+ // Locate customerio-reactnative/package.json from a postinstall context.
7
+ //
8
+ // `INIT_CWD` is set by npm, pnpm, and yarn during lifecycle scripts to point
9
+ // at the consumer's project root. That makes it the most reliable starting
10
+ // point — the plugin's own __dirname can be deep inside `.pnpm/...` under pnpm.
11
+ //
12
+ // We probe `${INIT_CWD}/node_modules/customerio-reactnative/package.json` first
13
+ // so we agree with the symlinked layout React Native autolinking expects, then
14
+ // fall back to resolve-from from the consumer root, then to the legacy
15
+ // __dirname-relative walk-up for environments where INIT_CWD is missing.
16
+ function findRNSDKPackageJson() {
17
+ const candidates = [];
18
+
19
+ if (process.env.INIT_CWD) {
20
+ candidates.push(
21
+ path.join(process.env.INIT_CWD, 'node_modules', RN_SDK_PACKAGE, 'package.json')
22
+ );
23
+ }
24
+
25
+ // Legacy flat-npm layout fallback: plugin lives at
26
+ // <consumer>/node_modules/customerio-expo-plugin/plugin/src and the SDK at
27
+ // <consumer>/node_modules/customerio-reactnative.
28
+ candidates.push(path.join(__dirname, '..', '..', '..', RN_SDK_PACKAGE, 'package.json'));
29
+
30
+ for (const candidate of candidates) {
31
+ if (fs.existsSync(candidate)) {
32
+ return candidate;
33
+ }
34
+ }
35
+
36
+ // Final fallback: resolve-from from INIT_CWD. This walks up node_modules
37
+ // and handles yarn classic workspaces where the dep is hoisted.
38
+ if (process.env.INIT_CWD) {
39
+ try {
40
+ const resolveFrom = require('resolve-from');
41
+ const resolved = resolveFrom.silent(
42
+ process.env.INIT_CWD,
43
+ `${RN_SDK_PACKAGE}/package.json`
44
+ );
45
+ if (resolved) return resolved;
46
+ } catch (_) {
47
+ // resolve-from missing or unable to resolve — fall through to null.
48
+ }
49
+ }
50
+
51
+ return null;
52
+ }
2
53
 
3
54
  function runPostInstall() {
4
- // react native SDK package.json path
5
- const reactNativePackageJsonFile = `${__dirname}/../../../customerio-reactnative/package.json`;
6
- const expoPackageJsonFile = `${__dirname}/../../package.json`;
55
+ const expoPackageJsonFile = path.join(__dirname, '..', '..', 'package.json');
56
+
7
57
  try {
8
- // if react native SDK is installed
9
- if (fs.existsSync(reactNativePackageJsonFile)) {
10
- const reactNativePackageJson = fs.readFileSync(
11
- reactNativePackageJsonFile,
12
- 'utf8'
13
- );
14
- const expoPackageJson = require(expoPackageJsonFile);
58
+ const reactNativePackageJsonFile = findRNSDKPackageJson();
59
+ if (!reactNativePackageJsonFile) {
60
+ // Not necessarily an error: the plugin may be installed without the RN
61
+ // SDK (e.g., during a tooling-only install). The prebuild-time write
62
+ // covers the common case anyway.
63
+ return;
64
+ }
15
65
 
16
- const reactNativePackage = JSON.parse(reactNativePackageJson);
17
- reactNativePackage.expoVersion = expoPackageJson.version;
66
+ const expoPackageJson = require(expoPackageJsonFile);
67
+ const reactNativePackage = JSON.parse(
68
+ fs.readFileSync(reactNativePackageJsonFile, 'utf8')
69
+ );
18
70
 
19
- fs.writeFileSync(
20
- reactNativePackageJsonFile,
21
- JSON.stringify(reactNativePackage, null, 2)
22
- );
71
+ if (reactNativePackage.expoVersion === expoPackageJson.version) {
72
+ return;
23
73
  }
74
+
75
+ reactNativePackage.expoVersion = expoPackageJson.version;
76
+ fs.writeFileSync(
77
+ reactNativePackageJsonFile,
78
+ JSON.stringify(reactNativePackage, null, 2)
79
+ );
24
80
  } catch (error) {
25
81
  console.warn(
26
- 'Unable to find customerio-reactnative package.json file. Please make sure you have installed the customerio-reactnative package.',
82
+ 'customerio-expo-plugin postinstall: failed to write expoVersion into customerio-reactnative/package.json. ' +
83
+ 'The expo prebuild step will retry this. Original error:',
27
84
  error
28
85
  );
29
86
  }
30
87
  }
31
88
 
32
89
  exports.runPostInstall = runPostInstall;
90
+ exports.findRNSDKPackageJson = findRNSDKPackageJson;
@@ -0,0 +1,118 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ const RN_SDK_PACKAGE = 'customerio-reactnative';
5
+ const REACT_NATIVE_PACKAGE = 'react-native';
6
+
7
+ export type ResolvedRNSDK = {
8
+ // Absolute path to the package directory.
9
+ packageDir: string;
10
+ // Absolute path to package.json inside that directory.
11
+ packageJsonPath: string;
12
+ };
13
+
14
+ // Reads the installed react-native package's version starting from `fromDir`.
15
+ // Used to decide which autolinking flavor will resolve customerio-reactnative
16
+ // at pod install time, so our :path agrees with what autolinking emits:
17
+ // - RN <0.80 ships @react-native-community/cli, which uses a lexical
18
+ // resolution (no realpath following).
19
+ // - RN >=0.80 routes pod autolinking through expo-modules-autolinking,
20
+ // which realpaths.
21
+ // Returns null if react-native cannot be located or its package.json cannot
22
+ // be read; callers should default to the modern (realpath) behavior in that
23
+ // case since it has been the working path for the last several Expo SDKs.
24
+ export function tryReadRNVersion(fromDir: string): string | null {
25
+ try {
26
+ const direct = path.join(
27
+ fromDir,
28
+ 'node_modules',
29
+ REACT_NATIVE_PACKAGE,
30
+ 'package.json'
31
+ );
32
+ if (fs.existsSync(direct)) {
33
+ return readVersion(direct);
34
+ }
35
+ const resolveFrom = require('resolve-from');
36
+ const fallback = resolveFrom.silent(
37
+ fromDir,
38
+ `${REACT_NATIVE_PACKAGE}/package.json`
39
+ );
40
+ if (fallback) {
41
+ return readVersion(fallback);
42
+ }
43
+ } catch {
44
+ // Fall through to null.
45
+ }
46
+ return null;
47
+ }
48
+
49
+ function readVersion(pkgJsonPath: string): string | null {
50
+ try {
51
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
52
+ return typeof pkg.version === 'string' ? pkg.version : null;
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
57
+
58
+ // Resolves the customerio-reactnative SDK location starting from `fromDir`.
59
+ //
60
+ // Probe-then-fallback so the result agrees with React Native autolinking
61
+ // across npm flat, pnpm, and yarn-workspace layouts:
62
+ // 1. `fromDir/node_modules/customerio-reactnative/package.json` — preferred.
63
+ // Works for npm flat, pnpm (the symlinked path; we never realpath it),
64
+ // and yarn workspaces with leaf node_modules. Matches what RN
65
+ // autolinking emits for its pod entry, so CocoaPods sees one
66
+ // consistent :path.
67
+ // 2. `resolve-from` walking up from `fromDir` — only used when (1) misses.
68
+ // Handles yarn classic workspaces where the dep is hoisted to a parent
69
+ // node_modules. yarn classic has no symlinks, so the realpath is fine.
70
+ //
71
+ // Returns null if neither finds the package, including the case where
72
+ // `resolve-from` itself can't be required (mirrors tryReadRNVersion's
73
+ // graceful-failure shape so callers can rely on the documented contract).
74
+ export function tryResolveRNSDK(fromDir: string): ResolvedRNSDK | null {
75
+ try {
76
+ const directPkgJson = path.join(
77
+ fromDir,
78
+ 'node_modules',
79
+ RN_SDK_PACKAGE,
80
+ 'package.json'
81
+ );
82
+ if (fs.existsSync(directPkgJson)) {
83
+ return {
84
+ packageDir: path.dirname(directPkgJson),
85
+ packageJsonPath: directPkgJson,
86
+ };
87
+ }
88
+
89
+ const resolveFrom = require('resolve-from');
90
+ const fallbackPkgJson = resolveFrom.silent(
91
+ fromDir,
92
+ `${RN_SDK_PACKAGE}/package.json`
93
+ );
94
+ if (fallbackPkgJson) {
95
+ return {
96
+ packageDir: path.dirname(fallbackPkgJson),
97
+ packageJsonPath: fallbackPkgJson,
98
+ };
99
+ }
100
+ } catch {
101
+ // Fall through to null. resolveRNSDK() turns this into a clear
102
+ // "customerio-reactnative was not found" error for the caller.
103
+ }
104
+
105
+ return null;
106
+ }
107
+
108
+ // Same as tryResolveRNSDK but throws a clear error when the package is missing.
109
+ export function resolveRNSDK(fromDir: string): ResolvedRNSDK {
110
+ const resolved = tryResolveRNSDK(fromDir);
111
+ if (!resolved) {
112
+ throw new Error(
113
+ `${RN_SDK_PACKAGE} was not found relative to ${fromDir}. ` +
114
+ `Ensure it is installed in your project (or in a parent workspace's node_modules).`
115
+ );
116
+ }
117
+ return resolved;
118
+ }
@@ -0,0 +1,62 @@
1
+ import fs from 'fs';
2
+ import type { ConfigPlugin } from '@expo/config-plugins';
3
+
4
+ import { logger } from './logger';
5
+ import { getPluginVersion } from './plugin';
6
+ import { tryResolveRNSDK } from './resolveRNSDK';
7
+
8
+ // Writes the plugin's version into customerio-reactnative/package.json under
9
+ // the `expoVersion` key. The RN SDK reads this at runtime (customerio-cdp.ts)
10
+ // to set its User-Agent `packageSource` to "Expo" instead of "ReactNative".
11
+ //
12
+ // We rely on the postinstall hook (postInstallHelper.js) for the same write
13
+ // at install time, but call this from the plugin entry as a fallback for
14
+ // installs where postinstall does not run cleanly — most notably pnpm
15
+ // monorepos and any CI that uses --ignore-scripts.
16
+ //
17
+ // The write is idempotent: we no-op when the value is already correct.
18
+ export function writeExpoVersion(projectRoot: string): void {
19
+ let resolved;
20
+ try {
21
+ resolved = tryResolveRNSDK(projectRoot);
22
+ } catch (error) {
23
+ logger.warn(
24
+ `Could not locate customerio-reactnative to write expoVersion. ` +
25
+ `User-Agent attribution may be incorrect. Original error: ${error}`
26
+ );
27
+ return;
28
+ }
29
+
30
+ if (!resolved) {
31
+ return;
32
+ }
33
+
34
+ try {
35
+ const pluginVersion = getPluginVersion();
36
+ const pkg = JSON.parse(fs.readFileSync(resolved.packageJsonPath, 'utf8'));
37
+ if (pkg.expoVersion === pluginVersion) {
38
+ return;
39
+ }
40
+ pkg.expoVersion = pluginVersion;
41
+ fs.writeFileSync(
42
+ resolved.packageJsonPath,
43
+ JSON.stringify(pkg, null, 2)
44
+ );
45
+ } catch (error) {
46
+ logger.warn(
47
+ `Failed to write expoVersion into ${resolved.packageJsonPath}. ` +
48
+ `User-Agent attribution may be incorrect. Original error: ${error}`
49
+ );
50
+ }
51
+ }
52
+
53
+ export const withExpoVersion: ConfigPlugin = (config) => {
54
+ // _internal.projectRoot is set by Expo when running through prebuild;
55
+ // fall back to process.cwd() for any path that calls the plugin in
56
+ // a non-prebuild context.
57
+ const projectRoot =
58
+ (config as unknown as { _internal?: { projectRoot?: string } })._internal?.projectRoot ||
59
+ process.cwd();
60
+ writeExpoVersion(projectRoot);
61
+ return config;
62
+ };