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 shouldDefaultToClassicUpdates(config) {
81  var _config$updates;
82  return !!((_config$updates = config.updates) !== null && _config$updates !== void 0 && _config$updates.useClassicUpdates);
83}
84function getUpdateUrl(config, username) {
85  var _config$updates2;
86  if ((_config$updates2 = config.updates) !== null && _config$updates2 !== void 0 && _config$updates2.url) {
87    var _config$updates3;
88    return (_config$updates3 = config.updates) === null || _config$updates3 === void 0 ? void 0 : _config$updates3.url;
89  }
90  if (!shouldDefaultToClassicUpdates(config)) {
91    return null;
92  }
93  const user = typeof config.owner === 'string' ? config.owner : username;
94  if (!user) {
95    return null;
96  }
97  return `https://exp.host/@${user}/${config.slug}`;
98}
99function getAppVersion(config) {
100  var _config$version;
101  return (_config$version = config.version) !== null && _config$version !== void 0 ? _config$version : '1.0.0';
102}
103function getNativeVersion(config, platform) {
104  const version = _().IOSConfig.Version.getVersion(config);
105  switch (platform) {
106    case 'ios':
107      {
108        const buildNumber = _().IOSConfig.Version.getBuildNumber(config);
109        return `${version}(${buildNumber})`;
110      }
111    case 'android':
112      {
113        const versionCode = _().AndroidConfig.Version.getVersionCode(config);
114        return `${version}(${versionCode})`;
115      }
116    default:
117      {
118        throw new Error(`"${platform}" is not a supported platform. Choose either "ios" or "android".`);
119      }
120  }
121}
122
123/**
124 * Compute runtime version policies.
125 * @return an expoConfig with only string valued platform specific runtime versions.
126 */
127const withRuntimeVersion = config => {
128  var _config$ios, _config$android;
129  if ((_config$ios = config.ios) !== null && _config$ios !== void 0 && _config$ios.runtimeVersion || config.runtimeVersion) {
130    const runtimeVersion = getRuntimeVersion(config, 'ios');
131    if (runtimeVersion) {
132      config.ios = {
133        ...config.ios,
134        runtimeVersion
135      };
136    }
137  }
138  if ((_config$android = config.android) !== null && _config$android !== void 0 && _config$android.runtimeVersion || config.runtimeVersion) {
139    const runtimeVersion = getRuntimeVersion(config, 'android');
140    if (runtimeVersion) {
141      config.android = {
142        ...config.android,
143        runtimeVersion
144      };
145    }
146  }
147  delete config.runtimeVersion;
148  return config;
149};
150exports.withRuntimeVersion = withRuntimeVersion;
151function getRuntimeVersionNullable(...[config, platform]) {
152  try {
153    return getRuntimeVersion(config, platform);
154  } catch (e) {
155    if ((0, _getenv().boolish)('EXPO_DEBUG', false)) {
156      console.log(e);
157    }
158    return null;
159  }
160}
161function getRuntimeVersion(config, platform) {
162  var _config$platform$runt, _config$platform;
163  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;
164  if (!runtimeVersion) {
165    return null;
166  }
167  if (typeof runtimeVersion === 'string') {
168    return runtimeVersion;
169  } else if (runtimeVersion.policy === 'appVersion') {
170    return getAppVersion(config);
171  } else if (runtimeVersion.policy === 'nativeVersion') {
172    return getNativeVersion(config, platform);
173  } else if (runtimeVersion.policy === 'sdkVersion') {
174    if (!config.sdkVersion) {
175      throw new Error("An SDK version must be defined when using the 'sdkVersion' runtime policy.");
176    }
177    return (0, _sdkRuntimeVersions().getRuntimeVersionForSDKVersion)(config.sdkVersion);
178  }
179  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.`);
180}
181function getSDKVersion(config) {
182  return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;
183}
184function getUpdatesEnabled(config, username) {
185  var _config$updates4;
186  // allow override of enabled property
187  if (((_config$updates4 = config.updates) === null || _config$updates4 === void 0 ? void 0 : _config$updates4.enabled) !== undefined) {
188    return config.updates.enabled;
189  }
190
191  // enable if URL is set (which respects shouldDefaultToClassicUpdates)
192  return getUpdateUrl(config, username) !== null;
193}
194function getUpdatesTimeout(config) {
195  var _config$updates$fallb, _config$updates5;
196  return (_config$updates$fallb = (_config$updates5 = config.updates) === null || _config$updates5 === void 0 ? void 0 : _config$updates5.fallbackToCacheTimeout) !== null && _config$updates$fallb !== void 0 ? _config$updates$fallb : 0;
197}
198function getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion) {
199  var _config$updates6, _config$updates7, _config$updates8, _config$updates9;
200  if (((_config$updates6 = config.updates) === null || _config$updates6 === void 0 ? void 0 : _config$updates6.checkAutomatically) === 'ON_ERROR_RECOVERY') {
201    // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x
202    if (expoUpdatesPackageVersion && _semver().default.gte(expoUpdatesPackageVersion, '0.11.0')) {
203      return 'ERROR_RECOVERY_ONLY';
204    }
205    return 'NEVER';
206  } else if (((_config$updates7 = config.updates) === null || _config$updates7 === void 0 ? void 0 : _config$updates7.checkAutomatically) === 'ON_LOAD') {
207    return 'ALWAYS';
208  } else if (((_config$updates8 = config.updates) === null || _config$updates8 === void 0 ? void 0 : _config$updates8.checkAutomatically) === 'WIFI_ONLY') {
209    return 'WIFI_ONLY';
210  } else if (((_config$updates9 = config.updates) === null || _config$updates9 === void 0 ? void 0 : _config$updates9.checkAutomatically) === 'NEVER') {
211    return 'NEVER';
212  }
213  return 'ALWAYS';
214}
215function getUpdatesCodeSigningCertificate(projectRoot, config) {
216  var _config$updates10;
217  const codeSigningCertificatePath = (_config$updates10 = config.updates) === null || _config$updates10 === void 0 ? void 0 : _config$updates10.codeSigningCertificate;
218  if (!codeSigningCertificatePath) {
219    return undefined;
220  }
221  const finalPath = _path().default.join(projectRoot, codeSigningCertificatePath);
222  if (!_fs().default.existsSync(finalPath)) {
223    throw new Error(`File not found at \`updates.codeSigningCertificate\` path: ${finalPath}`);
224  }
225  return _fs().default.readFileSync(finalPath, 'utf8');
226}
227function getUpdatesCodeSigningMetadata(config) {
228  var _config$updates11;
229  return (_config$updates11 = config.updates) === null || _config$updates11 === void 0 ? void 0 : _config$updates11.codeSigningMetadata;
230}
231function getUpdatesCodeSigningMetadataStringified(config) {
232  const metadata = getUpdatesCodeSigningMetadata(config);
233  if (!metadata) {
234    return undefined;
235  }
236  return JSON.stringify(metadata);
237}
238function getUpdatesRequestHeaders(config) {
239  var _config$updates12;
240  return (_config$updates12 = config.updates) === null || _config$updates12 === void 0 ? void 0 : _config$updates12.requestHeaders;
241}
242function getUpdatesRequestHeadersStringified(config) {
243  const metadata = getUpdatesRequestHeaders(config);
244  if (!metadata) {
245    return undefined;
246  }
247  return JSON.stringify(metadata);
248}
249//# sourceMappingURL=Updates.js.map