-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
pluginConfig.js
120 lines (120 loc) · 4.61 KB
/
pluginConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateConfig = void 0;
const ajv_1 = __importDefault(require("ajv"));
const semver_1 = __importDefault(require("semver"));
/**
* The minimal supported versions. These values should align to SDK
* @ignore
*/
const EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS = {
android: {
minSdkVersion: 21,
compileSdkVersion: 31,
targetSdkVersion: 31,
kotlinVersion: '1.6.10',
},
ios: {
deploymentTarget: '12.0',
},
};
const schema = {
type: 'object',
properties: {
android: {
type: 'object',
properties: {
minSdkVersion: { type: 'integer', nullable: true },
compileSdkVersion: { type: 'integer', nullable: true },
targetSdkVersion: { type: 'integer', nullable: true },
buildToolsVersion: { type: 'string', nullable: true },
kotlinVersion: { type: 'string', nullable: true },
enableProguardInReleaseBuilds: { type: 'boolean', nullable: true },
extraProguardRules: { type: 'string', nullable: true },
packagingOptions: {
type: 'object',
properties: {
pickFirst: { type: 'array', items: { type: 'string' }, nullable: true },
exclude: { type: 'array', items: { type: 'string' }, nullable: true },
merge: { type: 'array', items: { type: 'string' }, nullable: true },
doNotStrip: { type: 'array', items: { type: 'string' }, nullable: true },
},
nullable: true,
},
},
nullable: true,
},
ios: {
type: 'object',
properties: {
deploymentTarget: { type: 'string', pattern: '\\d+\\.\\d+', nullable: true },
useFrameworks: { type: 'string', enum: ['static', 'dynamic'], nullable: true },
},
nullable: true,
},
},
};
/**
* Check versions to meet expo minimal supported versions.
* Will throw error message whenever there are invalid versions.
* For the implementation, we check items one by one because ajv does not well support custom error message.
*
* @param config the validated config passed from ajv
* @ignore
*/
function maybeThrowInvalidVersions(config) {
const checkItems = [
{
name: 'android.minSdkVersion',
configVersion: config.android?.minSdkVersion,
minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.minSdkVersion,
},
{
name: 'android.compileSdkVersion',
configVersion: config.android?.compileSdkVersion,
minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.compileSdkVersion,
},
{
name: 'android.targetSdkVersion',
configVersion: config.android?.targetSdkVersion,
minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.targetSdkVersion,
},
{
name: 'android.kotlinVersion',
configVersion: config.android?.kotlinVersion,
minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.kotlinVersion,
},
{
name: 'ios.deploymentTarget',
configVersion: config.ios?.deploymentTarget,
minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.ios.deploymentTarget,
},
];
for (const { name, configVersion, minimalVersion } of checkItems) {
if (typeof configVersion === 'number' &&
typeof minimalVersion === 'number' &&
configVersion < minimalVersion) {
throw new Error(`\`${name}\` needs to be at least version ${minimalVersion}.`);
}
if (typeof configVersion === 'string' &&
typeof minimalVersion === 'string' &&
semver_1.default.lt(semver_1.default.coerce(configVersion) ?? '0.0.0', semver_1.default.coerce(minimalVersion) ?? '0.0.0')) {
throw new Error(`\`${name}\` needs to be at least version ${minimalVersion}.`);
}
}
}
/**
* @ignore
*/
function validateConfig(config) {
const validate = new ajv_1.default().compile(schema);
if (!validate(config)) {
throw new Error('Invalid expo-build-properties config: ' + JSON.stringify(validate.errors));
}
maybeThrowInvalidVersions(config);
return config;
}
exports.validateConfig = validateConfig;