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.
- package/android/build.gradle +0 -5
- package/bun.lockb +0 -0
- package/package.json +1 -1
- package/plugin/build/withIAP.d.ts +1 -4
- package/plugin/build/withIAP.js +37 -32
- package/plugin/src/withIAP.ts +53 -39
package/android/build.gradle
CHANGED
package/bun.lockb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { ConfigPlugin } from 'expo/config-plugins';
|
|
2
|
-
|
|
3
|
-
interface Props {
|
|
4
|
-
}
|
|
5
|
-
declare const _default: ConfigPlugin<Props | undefined>;
|
|
2
|
+
declare const _default: ConfigPlugin<void>;
|
|
6
3
|
export default _default;
|
package/plugin/build/withIAP.js
CHANGED
|
@@ -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
|
|
8
|
-
const lines =
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
console.warn(
|
|
12
|
-
lines.push(
|
|
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(
|
|
13
|
+
lines.splice(index + offset, 0, lineToAdd);
|
|
16
14
|
}
|
|
17
15
|
return lines.join('\n');
|
|
18
16
|
};
|
|
19
|
-
const modifyProjectBuildGradle = (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
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,
|
|
59
|
+
const withIAP = (config, _props) => {
|
|
55
60
|
try {
|
|
56
|
-
console.log('Applying expo-iap plugin...');
|
|
57
|
-
|
|
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', `
|
|
61
|
-
console.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,
|
|
70
|
+
exports.default = (0, config_plugins_1.createRunOncePlugin)(withIAP, pkg.name, pkg.version);
|
package/plugin/src/withIAP.ts
CHANGED
|
@@ -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
|
|
11
|
-
|
|
11
|
+
const addLineToGradle = (
|
|
12
|
+
content: string,
|
|
12
13
|
anchor: RegExp | string,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
) => {
|
|
16
|
-
const lines =
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
console.warn(
|
|
20
|
-
|
|
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(
|
|
25
|
+
lines.splice(index + offset, 0, lineToAdd);
|
|
23
26
|
}
|
|
24
27
|
return lines.join('\n');
|
|
25
28
|
};
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
`
|
|
96
|
+
`expo-iap plugin encountered an error: ${error}`,
|
|
83
97
|
);
|
|
84
|
-
console.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);
|