1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.getAppVersion = getAppVersion;
7exports.getExpoUpdatesPackageVersion = getExpoUpdatesPackageVersion;
8exports.getNativeVersion = getNativeVersion;
9exports.getRuntimeVersionAsync = getRuntimeVersionAsync;
10exports.getRuntimeVersionNullableAsync = getRuntimeVersionNullableAsync;
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;
21function Fingerprint() {
22  const data = _interopRequireWildcard(require("@expo/fingerprint"));
23  Fingerprint = function () {
24    return data;
25  };
26  return data;
27}
28function _sdkRuntimeVersions() {
29  const data = require("@expo/sdk-runtime-versions");
30  _sdkRuntimeVersions = function () {
31    return data;
32  };
33  return data;
34}
35function _fs() {
36  const data = _interopRequireDefault(require("fs"));
37  _fs = function () {
38    return data;
39  };
40  return data;
41}
42function _getenv() {
43  const data = require("getenv");
44  _getenv = function () {
45    return data;
46  };
47  return data;
48}
49function _path() {
50  const data = _interopRequireDefault(require("path"));
51  _path = function () {
52    return data;
53  };
54  return data;
55}
56function _resolveFrom() {
57  const data = _interopRequireDefault(require("resolve-from"));
58  _resolveFrom = function () {
59    return data;
60  };
61  return data;
62}
63function _semver() {
64  const data = _interopRequireDefault(require("semver"));
65  _semver = function () {
66    return data;
67  };
68  return data;
69}
70function _() {
71  const data = require("..");
72  _ = function () {
73    return data;
74  };
75  return data;
76}
77function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
78function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
79function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
80function getExpoUpdatesPackageVersion(projectRoot) {
81  const expoUpdatesPackageJsonPath = _resolveFrom().default.silent(projectRoot, 'expo-updates/package.json');
82  if (!expoUpdatesPackageJsonPath || !_fs().default.existsSync(expoUpdatesPackageJsonPath)) {
83    return null;
84  }
85  const packageJson = JSON.parse(_fs().default.readFileSync(expoUpdatesPackageJsonPath, 'utf8'));
86  return packageJson.version;
87}
88function getUpdateUrl(config) {
89  var _config$updates$url, _config$updates;
90  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;
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}
115async function getRuntimeVersionNullableAsync(...[projectRoot, config, platform]) {
116  try {
117    return await getRuntimeVersionAsync(projectRoot, config, platform);
118  } catch (e) {
119    if ((0, _getenv().boolish)('EXPO_DEBUG', false)) {
120      console.log(e);
121    }
122    return null;
123  }
124}
125async function getRuntimeVersionAsync(projectRoot, config, platform) {
126  var _config$platform$runt, _config$platform;
127  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;
128  if (!runtimeVersion) {
129    return null;
130  }
131  if (typeof runtimeVersion === 'string') {
132    return runtimeVersion;
133  } else if (runtimeVersion.policy === 'appVersion') {
134    return getAppVersion(config);
135  } else if (runtimeVersion.policy === 'nativeVersion') {
136    return getNativeVersion(config, platform);
137  } else if (runtimeVersion.policy === 'sdkVersion') {
138    if (!config.sdkVersion) {
139      throw new Error("An SDK version must be defined when using the 'sdkVersion' runtime policy.");
140    }
141    return (0, _sdkRuntimeVersions().getRuntimeVersionForSDKVersion)(config.sdkVersion);
142  } else if (runtimeVersion.policy === 'fingerprintExperimental') {
143    console.warn("Use of the experimental 'fingerprintExperimental' runtime policy may result in unexpected system behavior.");
144    return await Fingerprint().createProjectHashAsync(projectRoot);
145  }
146  throw new Error(`"${typeof runtimeVersion === 'object' ? JSON.stringify(runtimeVersion) : runtimeVersion}" is not a valid runtime version. getRuntimeVersionAsync only supports a string, "sdkVersion", "appVersion", "nativeVersion" or "fingerprintExperimental" policy.`);
147}
148function getSDKVersion(config) {
149  return typeof config.sdkVersion === 'string' ? config.sdkVersion : null;
150}
151function getUpdatesEnabled(config) {
152  var _config$updates2;
153  // allow override of enabled property
154  if (((_config$updates2 = config.updates) === null || _config$updates2 === void 0 ? void 0 : _config$updates2.enabled) !== undefined) {
155    return config.updates.enabled;
156  }
157  return getUpdateUrl(config) !== null;
158}
159function getUpdatesTimeout(config) {
160  var _config$updates$fallb, _config$updates3;
161  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;
162}
163function getUpdatesCheckOnLaunch(config, expoUpdatesPackageVersion) {
164  var _config$updates4, _config$updates5, _config$updates6, _config$updates7;
165  if (((_config$updates4 = config.updates) === null || _config$updates4 === void 0 ? void 0 : _config$updates4.checkAutomatically) === 'ON_ERROR_RECOVERY') {
166    // native 'ERROR_RECOVERY_ONLY' option was only introduced in 0.11.x
167    if (expoUpdatesPackageVersion && _semver().default.gte(expoUpdatesPackageVersion, '0.11.0')) {
168      return 'ERROR_RECOVERY_ONLY';
169    }
170    return 'NEVER';
171  } else if (((_config$updates5 = config.updates) === null || _config$updates5 === void 0 ? void 0 : _config$updates5.checkAutomatically) === 'ON_LOAD') {
172    return 'ALWAYS';
173  } else if (((_config$updates6 = config.updates) === null || _config$updates6 === void 0 ? void 0 : _config$updates6.checkAutomatically) === 'WIFI_ONLY') {
174    return 'WIFI_ONLY';
175  } else if (((_config$updates7 = config.updates) === null || _config$updates7 === void 0 ? void 0 : _config$updates7.checkAutomatically) === 'NEVER') {
176    return 'NEVER';
177  }
178  return 'ALWAYS';
179}
180function getUpdatesCodeSigningCertificate(projectRoot, config) {
181  var _config$updates8;
182  const codeSigningCertificatePath = (_config$updates8 = config.updates) === null || _config$updates8 === void 0 ? void 0 : _config$updates8.codeSigningCertificate;
183  if (!codeSigningCertificatePath) {
184    return undefined;
185  }
186  const finalPath = _path().default.join(projectRoot, codeSigningCertificatePath);
187  if (!_fs().default.existsSync(finalPath)) {
188    throw new Error(`File not found at \`updates.codeSigningCertificate\` path: ${finalPath}`);
189  }
190  return _fs().default.readFileSync(finalPath, 'utf8');
191}
192function getUpdatesCodeSigningMetadata(config) {
193  var _config$updates9;
194  return (_config$updates9 = config.updates) === null || _config$updates9 === void 0 ? void 0 : _config$updates9.codeSigningMetadata;
195}
196function getUpdatesCodeSigningMetadataStringified(config) {
197  const metadata = getUpdatesCodeSigningMetadata(config);
198  if (!metadata) {
199    return undefined;
200  }
201  return JSON.stringify(metadata);
202}
203function getUpdatesRequestHeaders(config) {
204  var _config$updates10;
205  return (_config$updates10 = config.updates) === null || _config$updates10 === void 0 ? void 0 : _config$updates10.requestHeaders;
206}
207function getUpdatesRequestHeadersStringified(config) {
208  const metadata = getUpdatesRequestHeaders(config);
209  if (!metadata) {
210    return undefined;
211  }
212  return JSON.stringify(metadata);
213}
214//# sourceMappingURL=Updates.js.map