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