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 newArchEnabled: { type: 'boolean', nullable: true }, 31 minSdkVersion: { type: 'integer', nullable: true }, 32 compileSdkVersion: { type: 'integer', nullable: true }, 33 targetSdkVersion: { type: 'integer', nullable: true }, 34 buildToolsVersion: { type: 'string', nullable: true }, 35 kotlinVersion: { type: 'string', nullable: true }, 36 enableProguardInReleaseBuilds: { type: 'boolean', nullable: true }, 37 enableShrinkResourcesInReleaseBuilds: { type: 'boolean', nullable: true }, 38 extraProguardRules: { type: 'string', nullable: true }, 39 flipper: { 40 type: 'string', 41 nullable: true, 42 }, 43 packagingOptions: { 44 type: 'object', 45 properties: { 46 pickFirst: { type: 'array', items: { type: 'string' }, nullable: true }, 47 exclude: { type: 'array', items: { type: 'string' }, nullable: true }, 48 merge: { type: 'array', items: { type: 'string' }, nullable: true }, 49 doNotStrip: { type: 'array', items: { type: 'string' }, nullable: true }, 50 }, 51 nullable: true, 52 }, 53 unstable_networkInspector: { type: 'boolean', nullable: true }, 54 }, 55 nullable: true, 56 }, 57 ios: { 58 type: 'object', 59 properties: { 60 newArchEnabled: { type: 'boolean', nullable: true }, 61 deploymentTarget: { type: 'string', pattern: '\\d+\\.\\d+', nullable: true }, 62 useFrameworks: { type: 'string', enum: ['static', 'dynamic'], nullable: true }, 63 flipper: { 64 type: ['boolean', 'string'], 65 nullable: true, 66 }, 67 unstable_networkInspector: { type: 'boolean', nullable: true }, 68 }, 69 nullable: true, 70 }, 71 }, 72}; 73// note(Kudo): For the implementation, we check items one by one because Ajv does not well support custom error message. 74/** 75 * Checks if specified versions meets Expo minimal supported versions. 76 * Will throw error message whenever there are invalid versions. 77 * 78 * @param config The validated config passed from Ajv. 79 * @ignore 80 */ 81function maybeThrowInvalidVersions(config) { 82 const checkItems = [ 83 { 84 name: 'android.minSdkVersion', 85 configVersion: config.android?.minSdkVersion, 86 minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.minSdkVersion, 87 }, 88 { 89 name: 'android.compileSdkVersion', 90 configVersion: config.android?.compileSdkVersion, 91 minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.compileSdkVersion, 92 }, 93 { 94 name: 'android.targetSdkVersion', 95 configVersion: config.android?.targetSdkVersion, 96 minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.targetSdkVersion, 97 }, 98 { 99 name: 'android.kotlinVersion', 100 configVersion: config.android?.kotlinVersion, 101 minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.android.kotlinVersion, 102 }, 103 { 104 name: 'ios.deploymentTarget', 105 configVersion: config.ios?.deploymentTarget, 106 minimalVersion: EXPO_SDK_MINIMAL_SUPPORTED_VERSIONS.ios.deploymentTarget, 107 }, 108 ]; 109 for (const { name, configVersion, minimalVersion } of checkItems) { 110 if (typeof configVersion === 'number' && 111 typeof minimalVersion === 'number' && 112 configVersion < minimalVersion) { 113 throw new Error(`\`${name}\` needs to be at least version ${minimalVersion}.`); 114 } 115 if (typeof configVersion === 'string' && 116 typeof minimalVersion === 'string' && 117 semver_1.default.lt(semver_1.default.coerce(configVersion) ?? '0.0.0', semver_1.default.coerce(minimalVersion) ?? '0.0.0')) { 118 throw new Error(`\`${name}\` needs to be at least version ${minimalVersion}.`); 119 } 120 } 121} 122/** 123 * @ignore 124 */ 125function validateConfig(config) { 126 const validate = new ajv_1.default({ allowUnionTypes: true }).compile(schema); 127 if (!validate(config)) { 128 throw new Error('Invalid expo-build-properties config: ' + JSON.stringify(validate.errors)); 129 } 130 maybeThrowInvalidVersions(config); 131 // explicitly block using use_frameworks and Flipper in iOS 132 // https://github.com/facebook/flipper/issues/2414 133 if (Boolean(config.ios?.flipper) && config.ios?.useFrameworks !== undefined) { 134 throw new Error('`ios.flipper` cannot be enabled when `ios.useFrameworks` is set.'); 135 } 136 if (config.android?.enableShrinkResourcesInReleaseBuilds === true && 137 config.android?.enableProguardInReleaseBuilds !== true) { 138 throw new Error('`android.enableShrinkResourcesInReleaseBuilds` requires `android.enableProguardInReleaseBuilds` to be enabled.'); 139 } 140 return config; 141} 142exports.validateConfig = validateConfig; 143