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) {
81  var _config$updates$url, _config$updates;
82  return (_config$updates$url = (_config$updates = config.updates) === null || _config$updates === void 0 ? void 0 : _config$updates.url) !== null && _config$updates$url !== void 0 ? _config$updates$url : null;
83}
84function getAppVersion(config) {
85  var _config$version;
86  return (_config$version = config.version) !== null && _config$version !== void 0 ? _config$version : '1.0.0';
87}
88function getNativeVersion(config, platform) {
89  const version = _().IOSConfig.Version.getVersion(config);
90  switch (platform) {
91    case 'ios':
92      {
93        const buildNumber = _().IOSConfig.Version.getBuildNumber(config);
94        return `${version}(${buildNumber})`;
95      }
96    case 'android':
97      {
98        const versionCode = _().AndroidConfig.Version.getVersionCode(config);
99        return `${version}(${versionCode})`;
100      }
101    default:
102      {
103        throw new Error(`"${platform}" is not a supported platform. Choose either "ios" or "android".`);
104      }
105  }
106}
107
108/**
109 * Compute runtime version policies.
110 * @return an expoConfig with only string valued platform specific runtime versions.
111 */
112const withRuntimeVersion = config => {
113  var _config$ios, _config$android;
114  if ((_config$ios = config.ios) !== null && _config$ios !== void 0 && _config$ios.runtimeVersion || config.runtimeVersion) {
115    const runtimeVersion = getRuntimeVersion(config, 'ios');
116    if (runtimeVersion) {
117      config.ios = {
118        ...config.ios,
119        runtimeVersion
120      };
121    }
122  }
123  if ((_config$android = config.android) !== null && _config$android !== void 0 && _config$android.runtimeVersion || config.runtimeVersion) {
124    const runtimeVersion = getRuntimeVersion(config, 'android');
125    if (runtimeVersion) {
126      config.android = {
127        ...config.android,
128        runtimeVersion
129      };
130    }
131  }
132  delete config.runtimeVersion;
133  return config;
134};
135exports.withRuntimeVersion = withRuntimeVersion;
136function getRuntimeVersionNullable(...[config, platform]) {
137  try {
138    return getRuntimeVersion(config, platform);
139  } catch (e) {
140    if ((0, _getenv().boolish)('EXPO_DEBUG', false)) {
141      console.log(e);
142    }
143    return null;
144  }
145}
146function getRuntimeVersion(config, platform) {
147  var _config$platform$runt, _config$platform;
148  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;
149  if (!runtimeVersion) {
150    return null;
151  }
152  if (typeof runtimeVersion === 'string') {
153    return runtimeVersion;
154  } else if (runtimeVersion.policy === 'appVersion') {
155    return getAppVersion(config);
156  } else if (runtimeVersion.policy === 'nativeVersion') {
157    return getNativeVersion(config, platform);
158  } else if (runtimeVersion.policy === 'sdkVersion') {
159    if (!config.sdkVersion) {
160      throw new Error("An SDK version must be defined when using the 'sdkVersion' runtime policy.");
161    }
162    return (0, _sdkRuntimeVersions().getRuntimeVersionForSDKVersion)(config.sdkVersion);
163  }
164  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.`);
165}
166function getSDKVersion(config) {
167  return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;
168}
169function getUpdatesEnabled(config) {
170  var _config$updates2;
171  // allow override of enabled property
172  if (((_config$updates2 = config.updates) === null || _config$updates2 === void 0 ? void 0 : _config$updates2.enabled) !== undefined) {
173    return config.updates.enabled;
174  }
175  return getUpdateUrl(config) !== null;
176}
177function getUpdatesTimeout(config) {
178  var _config$updates$fallb, _config$updates3;
179  return (_config$updates$fallb = (_config$updates3 = config.updates) === null || _config$updates3 === void 0 ? void 0 : _config$updates3.fallbackToCacheTimeout) !== null && _config$updates$fallb !== void 0 ? _config$updates$fallb : 0;
180}
181function getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion) {
182  var _config$updates4, _config$updates5, _config$updates6, _config$updates7;
183  if (((_config$updates4 = config.updates) === null || _config$updates4 === void 0 ? void 0 : _config$updates4.checkAutomatically) === 'ON_ERROR_RECOVERY') {
184    // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x
185    if (expoUpdatesPackageVersion && _semver().default.gte(expoUpdatesPackageVersion, '0.11.0')) {
186      return 'ERROR_RECOVERY_ONLY';
187    }
188    return 'NEVER';
189  } else if (((_config$updates5 = config.updates) === null || _config$updates5 === void 0 ? void 0 : _config$updates5.checkAutomatically) === 'ON_LOAD') {
190    return 'ALWAYS';
191  } else if (((_config$updates6 = config.updates) === null || _config$updates6 === void 0 ? void 0 : _config$updates6.checkAutomatically) === 'WIFI_ONLY') {
192    return 'WIFI_ONLY';
193  } else if (((_config$updates7 = config.updates) === null || _config$updates7 === void 0 ? void 0 : _config$updates7.checkAutomatically) === 'NEVER') {
194    return 'NEVER';
195  }
196  return 'ALWAYS';
197}
198function getUpdatesCodeSigningCertificate(projectRoot, config) {
199  var _config$updates8;
200  const codeSigningCertificatePath = (_config$updates8 = config.updates) === null || _config$updates8 === void 0 ? void 0 : _config$updates8.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$updates9;
212  return (_config$updates9 = config.updates) === null || _config$updates9 === void 0 ? void 0 : _config$updates9.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$updates10;
223  return (_config$updates10 = config.updates) === null || _config$updates10 === void 0 ? void 0 : _config$updates10.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