1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.getAppVersion = getAppVersion; 7exports.getExpoUpdatesPackageVersion = getExpoUpdatesPackageVersion; 8exports.getNativeVersion = getNativeVersion; 9exports.getRuntimeVersion = getRuntimeVersion; 10exports.getRuntimeVersionNullable = getRuntimeVersionNullable; 11exports.getSDKVersion = getSDKVersion; 12exports.getUpdateUrl = getUpdateUrl; 13exports.getUpdatesCheckOnLaunch = getUpdatesCheckOnLaunch; 14exports.getUpdatesCodeSigningCertificate = getUpdatesCodeSigningCertificate; 15exports.getUpdatesCodeSigningMetadata = getUpdatesCodeSigningMetadata; 16exports.getUpdatesCodeSigningMetadataStringified = getUpdatesCodeSigningMetadataStringified; 17exports.getUpdatesEnabled = getUpdatesEnabled; 18exports.getUpdatesTimeout = getUpdatesTimeout; 19exports.withRuntimeVersion = void 0; 20function _sdkRuntimeVersions() { 21 const data = require("@expo/sdk-runtime-versions"); 22 _sdkRuntimeVersions = function () { 23 return data; 24 }; 25 return data; 26} 27function _fs() { 28 const data = _interopRequireDefault(require("fs")); 29 _fs = function () { 30 return data; 31 }; 32 return data; 33} 34function _getenv() { 35 const data = require("getenv"); 36 _getenv = function () { 37 return data; 38 }; 39 return data; 40} 41function _path() { 42 const data = _interopRequireDefault(require("path")); 43 _path = function () { 44 return data; 45 }; 46 return data; 47} 48function _resolveFrom() { 49 const data = _interopRequireDefault(require("resolve-from")); 50 _resolveFrom = function () { 51 return data; 52 }; 53 return data; 54} 55function _semver() { 56 const data = _interopRequireDefault(require("semver")); 57 _semver = function () { 58 return data; 59 }; 60 return data; 61} 62function _() { 63 const data = require(".."); 64 _ = function () { 65 return data; 66 }; 67 return data; 68} 69function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 70function getExpoUpdatesPackageVersion(projectRoot) { 71 const expoUpdatesPackageJsonPath = _resolveFrom().default.silent(projectRoot, 'expo-updates/package.json'); 72 if (!expoUpdatesPackageJsonPath || !_fs().default.existsSync(expoUpdatesPackageJsonPath)) { 73 return null; 74 } 75 const packageJson = JSON.parse(_fs().default.readFileSync(expoUpdatesPackageJsonPath, 'utf8')); 76 return packageJson.version; 77} 78function getUpdateUrl(config, username) { 79 var _config$updates; 80 if ((_config$updates = config.updates) !== null && _config$updates !== void 0 && _config$updates.url) { 81 var _config$updates2; 82 return (_config$updates2 = config.updates) === null || _config$updates2 === void 0 ? void 0 : _config$updates2.url; 83 } 84 const user = typeof config.owner === 'string' ? config.owner : username; 85 if (!user) { 86 return null; 87 } 88 return `https://exp.host/@${user}/${config.slug}`; 89} 90function getAppVersion(config) { 91 var _config$version; 92 return (_config$version = config.version) !== null && _config$version !== void 0 ? _config$version : '1.0.0'; 93} 94function getNativeVersion(config, platform) { 95 const version = _().IOSConfig.Version.getVersion(config); 96 switch (platform) { 97 case 'ios': 98 { 99 const buildNumber = _().IOSConfig.Version.getBuildNumber(config); 100 return `${version}(${buildNumber})`; 101 } 102 case 'android': 103 { 104 const versionCode = _().AndroidConfig.Version.getVersionCode(config); 105 return `${version}(${versionCode})`; 106 } 107 default: 108 { 109 throw new Error(`"${platform}" is not a supported platform. Choose either "ios" or "android".`); 110 } 111 } 112} 113 114/** 115 * Compute runtime version policies. 116 * @return an expoConfig with only string valued platform specific runtime versions. 117 */ 118const withRuntimeVersion = config => { 119 var _config$ios, _config$android; 120 if ((_config$ios = config.ios) !== null && _config$ios !== void 0 && _config$ios.runtimeVersion || config.runtimeVersion) { 121 const runtimeVersion = getRuntimeVersion(config, 'ios'); 122 if (runtimeVersion) { 123 config.ios = { 124 ...config.ios, 125 runtimeVersion 126 }; 127 } 128 } 129 if ((_config$android = config.android) !== null && _config$android !== void 0 && _config$android.runtimeVersion || config.runtimeVersion) { 130 const runtimeVersion = getRuntimeVersion(config, 'android'); 131 if (runtimeVersion) { 132 config.android = { 133 ...config.android, 134 runtimeVersion 135 }; 136 } 137 } 138 delete config.runtimeVersion; 139 return config; 140}; 141exports.withRuntimeVersion = withRuntimeVersion; 142function getRuntimeVersionNullable(...[config, platform]) { 143 try { 144 return getRuntimeVersion(config, platform); 145 } catch (e) { 146 if ((0, _getenv().boolish)('EXPO_DEBUG', false)) { 147 console.log(e); 148 } 149 return null; 150 } 151} 152function getRuntimeVersion(config, platform) { 153 var _config$platform$runt, _config$platform; 154 const runtimeVersion = (_config$platform$runt = (_config$platform = config[platform]) === null || _config$platform === void 0 ? void 0 : _config$platform.runtimeVersion) !== null && _config$platform$runt !== void 0 ? _config$platform$runt : config.runtimeVersion; 155 if (!runtimeVersion) { 156 return null; 157 } 158 if (typeof runtimeVersion === 'string') { 159 return runtimeVersion; 160 } else if (runtimeVersion.policy === 'appVersion') { 161 return getAppVersion(config); 162 } else if (runtimeVersion.policy === 'nativeVersion') { 163 return getNativeVersion(config, platform); 164 } else if (runtimeVersion.policy === 'sdkVersion') { 165 if (!config.sdkVersion) { 166 throw new Error("An SDK version must be defined when using the 'sdkVersion' runtime policy."); 167 } 168 return (0, _sdkRuntimeVersions().getRuntimeVersionForSDKVersion)(config.sdkVersion); 169 } 170 throw new Error(`"${typeof runtimeVersion === 'object' ? JSON.stringify(runtimeVersion) : runtimeVersion}" is not a valid runtime version. getRuntimeVersion only supports a string, "sdkVersion", "appVersion", or "nativeVersion" policy.`); 171} 172function getSDKVersion(config) { 173 return typeof config.sdkVersion === 'string' ? config.sdkVersion : null; 174} 175function getUpdatesEnabled(config) { 176 var _config$updates3; 177 return ((_config$updates3 = config.updates) === null || _config$updates3 === void 0 ? void 0 : _config$updates3.enabled) !== false; 178} 179function getUpdatesTimeout(config) { 180 var _config$updates$fallb, _config$updates4; 181 return (_config$updates$fallb = (_config$updates4 = config.updates) === null || _config$updates4 === void 0 ? void 0 : _config$updates4.fallbackToCacheTimeout) !== null && _config$updates$fallb !== void 0 ? _config$updates$fallb : 0; 182} 183function getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion) { 184 var _config$updates5, _config$updates6; 185 if (((_config$updates5 = config.updates) === null || _config$updates5 === void 0 ? void 0 : _config$updates5.checkAutomatically) === 'ON_ERROR_RECOVERY') { 186 // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x 187 if (expoUpdatesPackageVersion && _semver().default.gte(expoUpdatesPackageVersion, '0.11.0')) { 188 return 'ERROR_RECOVERY_ONLY'; 189 } 190 return 'NEVER'; 191 } else if (((_config$updates6 = config.updates) === null || _config$updates6 === void 0 ? void 0 : _config$updates6.checkAutomatically) === 'ON_LOAD') { 192 return 'ALWAYS'; 193 } 194 return 'ALWAYS'; 195} 196function getUpdatesCodeSigningCertificate(projectRoot, config) { 197 var _config$updates7; 198 const codeSigningCertificatePath = (_config$updates7 = config.updates) === null || _config$updates7 === void 0 ? void 0 : _config$updates7.codeSigningCertificate; 199 if (!codeSigningCertificatePath) { 200 return undefined; 201 } 202 const finalPath = _path().default.join(projectRoot, codeSigningCertificatePath); 203 if (!_fs().default.existsSync(finalPath)) { 204 throw new Error(`File not found at \`updates.codeSigningCertificate\` path: ${finalPath}`); 205 } 206 return _fs().default.readFileSync(finalPath, 'utf8'); 207} 208function getUpdatesCodeSigningMetadata(config) { 209 var _config$updates8; 210 return (_config$updates8 = config.updates) === null || _config$updates8 === void 0 ? void 0 : _config$updates8.codeSigningMetadata; 211} 212function getUpdatesCodeSigningMetadataStringified(config) { 213 const metadata = getUpdatesCodeSigningMetadata(config); 214 if (!metadata) { 215 return undefined; 216 } 217 return JSON.stringify(metadata); 218} 219//# sourceMappingURL=Updates.js.map