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