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

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