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