expo-iap 2.2.11 → 2.3.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.
@@ -41,8 +41,3 @@ android {
41
41
  abortOnError false
42
42
  }
43
43
  }
44
-
45
- dependencies {
46
- implementation "com.android.billingclient:billing-ktx:7.0.0"
47
- implementation "com.google.android.gms:play-services-base:18.1.0"
48
- }
package/bun.lockb CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-iap",
3
- "version": "2.2.11",
3
+ "version": "2.3.0",
4
4
  "description": "In App Purchase module in Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,6 +1,3 @@
1
1
  import { ConfigPlugin } from 'expo/config-plugins';
2
- export declare const modifyProjectBuildGradle: (buildGradle: string) => string;
3
- interface Props {
4
- }
5
- declare const _default: ConfigPlugin<Props | undefined>;
2
+ declare const _default: ConfigPlugin<void>;
6
3
  export default _default;
@@ -1,65 +1,70 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.modifyProjectBuildGradle = void 0;
4
3
  const config_plugins_1 = require("expo/config-plugins");
5
- const config_plugins_2 = require("expo/config-plugins");
6
4
  const pkg = require('../../package.json');
7
- const addToBuildGradle = (newLine, anchor, offset, buildGradle) => {
8
- const lines = buildGradle.split('\n');
9
- const lineIndex = lines.findIndex((line) => line.match(anchor));
10
- if (lineIndex === -1) {
11
- console.warn('Anchor "ext" not found in build.gradle, appending to end');
12
- lines.push(newLine);
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);
13
11
  }
14
12
  else {
15
- lines.splice(lineIndex + offset, 0, newLine);
13
+ lines.splice(index + offset, 0, lineToAdd);
16
14
  }
17
15
  return lines.join('\n');
18
16
  };
19
- const modifyProjectBuildGradle = (buildGradle) => {
20
- const supportLibVersion = `supportLibVersion = "28.0.0"`;
21
- if (buildGradle.includes(supportLibVersion)) {
22
- return buildGradle;
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
23
  }
24
- return addToBuildGradle(supportLibVersion, 'ext', 1, buildGradle);
24
+ // 2. billing library
25
+ const billingDep = ` implementation "com.android.billingclient:billing-ktx:7.0.0"`;
26
+ const gmsDep = ` implementation "com.google.android.gms:play-services-base:18.1.0"`;
27
+ if (!modified.includes(billingDep)) {
28
+ modified = addLineToGradle(modified, /dependencies\s*{/, billingDep);
29
+ }
30
+ if (!modified.includes(gmsDep)) {
31
+ modified = addLineToGradle(modified, /dependencies\s*{/, gmsDep, 1);
32
+ }
33
+ return modified;
25
34
  };
26
- exports.modifyProjectBuildGradle = modifyProjectBuildGradle;
27
35
  const withIAPAndroid = (config) => {
28
36
  config = (0, config_plugins_1.withProjectBuildGradle)(config, (config) => {
29
- config.modResults.contents = (0, exports.modifyProjectBuildGradle)(config.modResults.contents);
37
+ config.modResults.contents = modifyProjectBuildGradle(config.modResults.contents);
30
38
  return config;
31
39
  });
32
- // Adding BILLING permission to AndroidManifest.xml
33
40
  config = (0, config_plugins_1.withAndroidManifest)(config, (config) => {
34
- console.log('Modifying AndroidManifest.xml...');
35
41
  const manifest = config.modResults;
36
42
  if (!manifest.manifest['uses-permission']) {
37
43
  manifest.manifest['uses-permission'] = [];
38
44
  }
39
45
  const permissions = manifest.manifest['uses-permission'];
40
- const billingPermission = {
41
- $: { 'android:name': 'com.android.vending.BILLING' },
42
- };
43
- if (!permissions.some((perm) => perm.$['android:name'] === 'com.android.vending.BILLING')) {
44
- permissions.push(billingPermission);
45
- console.log('Added com.android.vending.BILLING to permissions');
46
+ const billingPerm = { $: { 'android:name': 'com.android.vending.BILLING' } };
47
+ const alreadyExists = permissions.some((p) => p.$['android:name'] === 'com.android.vending.BILLING');
48
+ if (!alreadyExists) {
49
+ permissions.push(billingPerm);
50
+ console.log('✅ Added com.android.vending.BILLING to AndroidManifest.xml');
46
51
  }
47
52
  else {
48
- console.log('com.android.vending.BILLING already exists in manifest');
53
+ console.log('ℹ️ com.android.vending.BILLING already exists in AndroidManifest.xml');
49
54
  }
50
55
  return config;
51
56
  });
52
57
  return config;
53
58
  };
54
- const withIAP = (config, props) => {
59
+ const withIAP = (config, _props) => {
55
60
  try {
56
- console.log('Applying expo-iap plugin...');
57
- config = withIAPAndroid(config);
61
+ console.log('🛠️ Applying expo-iap config plugin...');
62
+ return withIAPAndroid(config);
58
63
  }
59
64
  catch (error) {
60
- config_plugins_1.WarningAggregator.addWarningAndroid('expo-iap', `There was a problem configuring expo-iap in your native Android project: ${error}`);
61
- console.error('Error in expo-iap plugin:', error);
65
+ config_plugins_1.WarningAggregator.addWarningAndroid('expo-iap', `expo-iap plugin encountered an error: ${error}`);
66
+ console.error('expo-iap plugin error:', error);
67
+ return config;
62
68
  }
63
- return config;
64
69
  };
65
- exports.default = (0, config_plugins_2.createRunOncePlugin)(withIAP, pkg.name, pkg.version);
70
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withIAP, pkg.name, pkg.version);
@@ -2,34 +2,51 @@ import {
2
2
  WarningAggregator,
3
3
  withAndroidManifest,
4
4
  withProjectBuildGradle,
5
+ ConfigPlugin,
6
+ createRunOncePlugin,
5
7
  } from 'expo/config-plugins';
6
- import {ConfigPlugin, createRunOncePlugin} from 'expo/config-plugins';
7
8
 
8
9
  const pkg = require('../../package.json');
9
10
 
10
- const addToBuildGradle = (
11
- newLine: string,
11
+ const addLineToGradle = (
12
+ content: string,
12
13
  anchor: RegExp | string,
13
- offset: number,
14
- buildGradle: string,
15
- ) => {
16
- const lines = buildGradle.split('\n');
17
- const lineIndex = lines.findIndex((line) => line.match(anchor));
18
- if (lineIndex === -1) {
19
- console.warn('Anchor "ext" not found in build.gradle, appending to end');
20
- lines.push(newLine);
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);
21
24
  } else {
22
- lines.splice(lineIndex + offset, 0, newLine);
25
+ lines.splice(index + offset, 0, lineToAdd);
23
26
  }
24
27
  return lines.join('\n');
25
28
  };
26
29
 
27
- export const modifyProjectBuildGradle = (buildGradle: string) => {
28
- const supportLibVersion = `supportLibVersion = "28.0.0"`;
29
- if (buildGradle.includes(supportLibVersion)) {
30
- return buildGradle;
30
+ const modifyProjectBuildGradle = (gradle: string): string => {
31
+ let modified = gradle;
32
+
33
+ // 1. supportLibVersion
34
+ const supportLib = `supportLibVersion = "28.0.0"`;
35
+ if (!modified.includes(supportLib)) {
36
+ modified = addLineToGradle(modified, /ext\s*{/, supportLib);
37
+ }
38
+
39
+ // 2. billing library
40
+ const billingDep = ` implementation "com.android.billingclient:billing-ktx:7.0.0"`;
41
+ const gmsDep = ` implementation "com.google.android.gms:play-services-base:18.1.0"`;
42
+ if (!modified.includes(billingDep)) {
43
+ modified = addLineToGradle(modified, /dependencies\s*{/, billingDep);
44
+ }
45
+ if (!modified.includes(gmsDep)) {
46
+ modified = addLineToGradle(modified, /dependencies\s*{/, gmsDep, 1);
31
47
  }
32
- return addToBuildGradle(supportLibVersion, 'ext', 1, buildGradle);
48
+
49
+ return modified;
33
50
  };
34
51
 
35
52
  const withIAPAndroid: ConfigPlugin = (config) => {
@@ -40,28 +57,27 @@ const withIAPAndroid: ConfigPlugin = (config) => {
40
57
  return config;
41
58
  });
42
59
 
43
- // Adding BILLING permission to AndroidManifest.xml
44
60
  config = withAndroidManifest(config, (config) => {
45
- console.log('Modifying AndroidManifest.xml...');
46
61
  const manifest = config.modResults;
47
-
48
62
  if (!manifest.manifest['uses-permission']) {
49
63
  manifest.manifest['uses-permission'] = [];
50
64
  }
51
65
 
52
66
  const permissions = manifest.manifest['uses-permission'];
53
- const billingPermission = {
54
- $: {'android:name': 'com.android.vending.BILLING'},
55
- };
56
- if (
57
- !permissions.some(
58
- (perm: any) => perm.$['android:name'] === 'com.android.vending.BILLING',
59
- )
60
- ) {
61
- permissions.push(billingPermission);
62
- console.log('Added com.android.vending.BILLING to permissions');
67
+ const billingPerm = {$: {'android:name': 'com.android.vending.BILLING'}};
68
+
69
+ const alreadyExists = permissions.some(
70
+ (p) => p.$['android:name'] === 'com.android.vending.BILLING',
71
+ );
72
+ if (!alreadyExists) {
73
+ permissions.push(billingPerm);
74
+ console.log(
75
+ '✅ Added com.android.vending.BILLING to AndroidManifest.xml',
76
+ );
63
77
  } else {
64
- console.log('com.android.vending.BILLING already exists in manifest');
78
+ console.log(
79
+ 'ℹ️ com.android.vending.BILLING already exists in AndroidManifest.xml',
80
+ );
65
81
  }
66
82
 
67
83
  return config;
@@ -70,20 +86,18 @@ const withIAPAndroid: ConfigPlugin = (config) => {
70
86
  return config;
71
87
  };
72
88
 
73
- interface Props {}
74
-
75
- const withIAP: ConfigPlugin<Props | undefined> = (config, props) => {
89
+ const withIAP: ConfigPlugin = (config, _props) => {
76
90
  try {
77
- console.log('Applying expo-iap plugin...');
78
- config = withIAPAndroid(config);
91
+ console.log('🛠️ Applying expo-iap config plugin...');
92
+ return withIAPAndroid(config);
79
93
  } catch (error) {
80
94
  WarningAggregator.addWarningAndroid(
81
95
  'expo-iap',
82
- `There was a problem configuring expo-iap in your native Android project: ${error}`,
96
+ `expo-iap plugin encountered an error: ${error}`,
83
97
  );
84
- console.error('Error in expo-iap plugin:', error);
98
+ console.error('expo-iap plugin error:', error);
99
+ return config;
85
100
  }
86
- return config;
87
101
  };
88
102
 
89
103
  export default createRunOncePlugin(withIAP, pkg.name, pkg.version);