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