expo-iap 2.3.1-rc.1 → 2.3.1-rc.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-iap",
3
- "version": "2.3.1-rc.1",
3
+ "version": "2.3.1-rc.2",
4
4
  "description": "In App Purchase module in Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -2,59 +2,73 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_plugins_1 = require("expo/config-plugins");
4
4
  const pkg = require('../../package.json');
5
- const BILLING_PERMISSION = 'com.android.vending.BILLING';
6
- const BILLING_DEP = ` implementation "com.android.billingclient:billing-ktx:7.0.0"`;
7
- const GMS_DEP = ` implementation "com.google.android.gms:play-services-base:18.1.0"`;
8
- /**
9
- * Injects implementation lines into app/build.gradle
10
- */
11
- function modifyAppBuildGradle(buildGradle) {
12
- const lines = buildGradle.split('\n');
13
- const anchor = /dependencies\s*{/;
14
- const index = lines.findIndex((line) => anchor.test(line));
15
- if (index !== -1) {
16
- if (!buildGradle.includes(BILLING_DEP)) {
17
- lines.splice(index + 1, 0, BILLING_DEP);
18
- }
19
- if (!buildGradle.includes(GMS_DEP)) {
20
- lines.splice(index + 2, 0, GMS_DEP);
21
- }
5
+ const addLineToGradle = (content, anchor, lineToAdd, offset = 1) => {
6
+ const lines = content.split('\n');
7
+ const index = lines.findIndex((line) => line.match(anchor));
8
+ if (index === -1) {
9
+ console.warn(`Anchor "${anchor}" not found in build.gradle. Appending to end.`);
10
+ lines.push(lineToAdd);
22
11
  }
23
12
  else {
24
- console.warn('Could not find dependencies block in app/build.gradle');
13
+ lines.splice(index + offset, 0, lineToAdd);
25
14
  }
26
15
  return lines.join('\n');
27
- }
28
- /**
29
- * Adds BILLING permission to AndroidManifest.xml
30
- */
16
+ };
17
+ const modifyProjectBuildGradle = (gradle) => {
18
+ let modified = gradle;
19
+ // 1. supportLibVersion
20
+ const supportLib = `supportLibVersion = "28.0.0"`;
21
+ if (!modified.includes(supportLib)) {
22
+ modified = addLineToGradle(modified, /ext\s*{/, supportLib);
23
+ }
24
+ return modified;
25
+ };
26
+ const modifyAppBuildGradle = (gradle) => {
27
+ let modified = gradle;
28
+ // Add billing library dependencies to app-level build.gradle
29
+ const billingDep = ` implementation "com.android.billingclient:billing-ktx:7.0.0"`;
30
+ const gmsDep = ` implementation "com.google.android.gms:play-services-base:18.1.0"`;
31
+ if (!modified.includes(billingDep)) {
32
+ modified = addLineToGradle(modified, /dependencies\s*{/, billingDep);
33
+ }
34
+ if (!modified.includes(gmsDep)) {
35
+ modified = addLineToGradle(modified, /dependencies\s*{/, gmsDep, 1);
36
+ }
37
+ return modified;
38
+ };
31
39
  const withIAPAndroid = (config) => {
40
+ // Add supportLibVersion to project build.gradle
41
+ config = (0, config_plugins_1.withProjectBuildGradle)(config, (config) => {
42
+ config.modResults.contents = modifyProjectBuildGradle(config.modResults.contents);
43
+ return config;
44
+ });
45
+ // Add IAP dependencies to app build.gradle
32
46
  config = (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
33
47
  config.modResults.contents = modifyAppBuildGradle(config.modResults.contents);
34
48
  return config;
35
49
  });
36
50
  config = (0, config_plugins_1.withAndroidManifest)(config, (config) => {
37
51
  const manifest = config.modResults;
38
- const permissions = manifest.manifest['uses-permission'] ?? [];
39
- const alreadyExists = permissions.some((p) => p.$['android:name'] === BILLING_PERMISSION);
52
+ if (!manifest.manifest['uses-permission']) {
53
+ manifest.manifest['uses-permission'] = [];
54
+ }
55
+ const permissions = manifest.manifest['uses-permission'];
56
+ const billingPerm = { $: { 'android:name': 'com.android.vending.BILLING' } };
57
+ const alreadyExists = permissions.some((p) => p.$['android:name'] === 'com.android.vending.BILLING');
40
58
  if (!alreadyExists) {
41
- permissions.push({ $: { 'android:name': BILLING_PERMISSION } });
42
- manifest.manifest['uses-permission'] = permissions;
43
- console.log(`✅ Added ${BILLING_PERMISSION} to AndroidManifest.xml`);
59
+ permissions.push(billingPerm);
60
+ console.log(' Added com.android.vending.BILLING to AndroidManifest.xml');
44
61
  }
45
62
  else {
46
- console.log(`ℹ️ ${BILLING_PERMISSION} already exists in AndroidManifest.xml`);
63
+ console.log('ℹ️ com.android.vending.BILLING already exists in AndroidManifest.xml');
47
64
  }
48
65
  return config;
49
66
  });
50
67
  return config;
51
68
  };
52
- /**
53
- * Main plugin entry
54
- */
55
69
  const withIAP = (config, _props) => {
56
70
  try {
57
- console.log('🛠️ Applying expo-iap plugin...');
71
+ console.log('🛠️ Applying expo-iap config plugin...');
58
72
  return withIAPAndroid(config);
59
73
  }
60
74
  catch (error) {
@@ -1,43 +1,71 @@
1
1
  import {
2
- ConfigPlugin,
3
2
  WarningAggregator,
4
3
  withAndroidManifest,
4
+ withProjectBuildGradle,
5
5
  withAppBuildGradle,
6
+ ConfigPlugin,
6
7
  createRunOncePlugin,
7
8
  } from 'expo/config-plugins';
8
9
 
9
10
  const pkg = require('../../package.json');
10
11
 
11
- const BILLING_PERMISSION = 'com.android.vending.BILLING';
12
- const BILLING_DEP = ` implementation "com.android.billingclient:billing-ktx:7.0.0"`;
13
- const GMS_DEP = ` implementation "com.google.android.gms:play-services-base:18.1.0"`;
14
-
15
- /**
16
- * Injects implementation lines into app/build.gradle
17
- */
18
- function modifyAppBuildGradle(buildGradle: string): string {
19
- const lines = buildGradle.split('\n');
20
- const anchor = /dependencies\s*{/;
21
- const index = lines.findIndex((line) => anchor.test(line));
22
-
23
- if (index !== -1) {
24
- if (!buildGradle.includes(BILLING_DEP)) {
25
- lines.splice(index + 1, 0, BILLING_DEP);
26
- }
27
- if (!buildGradle.includes(GMS_DEP)) {
28
- lines.splice(index + 2, 0, GMS_DEP);
29
- }
12
+ const addLineToGradle = (
13
+ content: string,
14
+ anchor: RegExp | string,
15
+ lineToAdd: string,
16
+ offset: number = 1,
17
+ ): string => {
18
+ const lines = content.split('\n');
19
+ const index = lines.findIndex((line) => line.match(anchor));
20
+ if (index === -1) {
21
+ console.warn(
22
+ `Anchor "${anchor}" not found in build.gradle. Appending to end.`,
23
+ );
24
+ lines.push(lineToAdd);
30
25
  } else {
31
- console.warn('Could not find dependencies block in app/build.gradle');
26
+ lines.splice(index + offset, 0, lineToAdd);
32
27
  }
33
-
34
28
  return lines.join('\n');
35
- }
29
+ };
30
+
31
+ const modifyProjectBuildGradle = (gradle: string): string => {
32
+ let modified = gradle;
33
+
34
+ // 1. supportLibVersion
35
+ const supportLib = `supportLibVersion = "28.0.0"`;
36
+ if (!modified.includes(supportLib)) {
37
+ modified = addLineToGradle(modified, /ext\s*{/, supportLib);
38
+ }
39
+
40
+ return modified;
41
+ };
42
+
43
+ const modifyAppBuildGradle = (gradle: string): string => {
44
+ let modified = gradle;
45
+
46
+ // Add billing library dependencies to app-level build.gradle
47
+ const billingDep = ` implementation "com.android.billingclient:billing-ktx:7.0.0"`;
48
+ const gmsDep = ` implementation "com.google.android.gms:play-services-base:18.1.0"`;
49
+ if (!modified.includes(billingDep)) {
50
+ modified = addLineToGradle(modified, /dependencies\s*{/, billingDep);
51
+ }
52
+ if (!modified.includes(gmsDep)) {
53
+ modified = addLineToGradle(modified, /dependencies\s*{/, gmsDep, 1);
54
+ }
55
+
56
+ return modified;
57
+ };
36
58
 
37
- /**
38
- * Adds BILLING permission to AndroidManifest.xml
39
- */
40
59
  const withIAPAndroid: ConfigPlugin = (config) => {
60
+ // Add supportLibVersion to project build.gradle
61
+ config = withProjectBuildGradle(config, (config) => {
62
+ config.modResults.contents = modifyProjectBuildGradle(
63
+ config.modResults.contents,
64
+ );
65
+ return config;
66
+ });
67
+
68
+ // Add IAP dependencies to app build.gradle
41
69
  config = withAppBuildGradle(config, (config) => {
42
70
  config.modResults.contents = modifyAppBuildGradle(
43
71
  config.modResults.contents,
@@ -47,19 +75,24 @@ const withIAPAndroid: ConfigPlugin = (config) => {
47
75
 
48
76
  config = withAndroidManifest(config, (config) => {
49
77
  const manifest = config.modResults;
50
- const permissions = manifest.manifest['uses-permission'] ?? [];
78
+ if (!manifest.manifest['uses-permission']) {
79
+ manifest.manifest['uses-permission'] = [];
80
+ }
81
+
82
+ const permissions = manifest.manifest['uses-permission'];
83
+ const billingPerm = {$: {'android:name': 'com.android.vending.BILLING'}};
51
84
 
52
85
  const alreadyExists = permissions.some(
53
- (p) => p.$['android:name'] === BILLING_PERMISSION,
86
+ (p) => p.$['android:name'] === 'com.android.vending.BILLING',
54
87
  );
55
-
56
88
  if (!alreadyExists) {
57
- permissions.push({$: {'android:name': BILLING_PERMISSION}});
58
- manifest.manifest['uses-permission'] = permissions;
59
- console.log(`✅ Added ${BILLING_PERMISSION} to AndroidManifest.xml`);
89
+ permissions.push(billingPerm);
90
+ console.log(
91
+ '✅ Added com.android.vending.BILLING to AndroidManifest.xml',
92
+ );
60
93
  } else {
61
94
  console.log(
62
- `ℹ️ ${BILLING_PERMISSION} already exists in AndroidManifest.xml`,
95
+ 'ℹ️ com.android.vending.BILLING already exists in AndroidManifest.xml',
63
96
  );
64
97
  }
65
98
 
@@ -69,12 +102,9 @@ const withIAPAndroid: ConfigPlugin = (config) => {
69
102
  return config;
70
103
  };
71
104
 
72
- /**
73
- * Main plugin entry
74
- */
75
105
  const withIAP: ConfigPlugin = (config, _props) => {
76
106
  try {
77
- console.log('🛠️ Applying expo-iap plugin...');
107
+ console.log('🛠️ Applying expo-iap config plugin...');
78
108
  return withIAPAndroid(config);
79
109
  } catch (error) {
80
110
  WarningAggregator.addWarningAndroid(