1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.Config = void 0;
7exports.ensureBundleReactNativePhaseContainsConfigurationScript = ensureBundleReactNativePhaseContainsConfigurationScript;
8exports.getBundleReactNativePhase = getBundleReactNativePhase;
9exports.isPlistConfigurationSet = isPlistConfigurationSet;
10exports.isPlistConfigurationSynced = isPlistConfigurationSynced;
11exports.isPlistVersionConfigurationSynced = isPlistVersionConfigurationSynced;
12exports.isShellScriptBuildPhaseConfigured = isShellScriptBuildPhaseConfigured;
13exports.setUpdatesConfig = setUpdatesConfig;
14exports.setVersionsConfig = setVersionsConfig;
15exports.withUpdates = void 0;
16
17function path() {
18  const data = _interopRequireWildcard(require("path"));
19
20  path = function () {
21    return data;
22  };
23
24  return data;
25}
26
27function _resolveFrom() {
28  const data = _interopRequireDefault(require("resolve-from"));
29
30  _resolveFrom = function () {
31    return data;
32  };
33
34  return data;
35}
36
37function _iosPlugins() {
38  const data = require("../plugins/ios-plugins");
39
40  _iosPlugins = function () {
41    return data;
42  };
43
44  return data;
45}
46
47function _Updates() {
48  const data = require("../utils/Updates");
49
50  _Updates = function () {
51    return data;
52  };
53
54  return data;
55}
56
57function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
58
59function _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); }
60
61function _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; }
62
63const CREATE_MANIFEST_IOS_PATH = 'expo-updates/scripts/create-manifest-ios.sh';
64let Config;
65exports.Config = Config;
66
67(function (Config) {
68  Config["ENABLED"] = "EXUpdatesEnabled";
69  Config["CHECK_ON_LAUNCH"] = "EXUpdatesCheckOnLaunch";
70  Config["LAUNCH_WAIT_MS"] = "EXUpdatesLaunchWaitMs";
71  Config["RUNTIME_VERSION"] = "EXUpdatesRuntimeVersion";
72  Config["SDK_VERSION"] = "EXUpdatesSDKVersion";
73  Config["UPDATE_URL"] = "EXUpdatesURL";
74  Config["RELEASE_CHANNEL"] = "EXUpdatesReleaseChannel";
75  Config["UPDATES_CONFIGURATION_REQUEST_HEADERS_KEY"] = "EXUpdatesRequestHeaders";
76  Config["CODE_SIGNING_CERTIFICATE"] = "EXUpdatesCodeSigningCertificate";
77  Config["CODE_SIGNING_METADATA"] = "EXUpdatesCodeSigningMetadata";
78})(Config || (exports.Config = Config = {}));
79
80const withUpdates = (config, {
81  expoUsername
82}) => {
83  return (0, _iosPlugins().withExpoPlist)(config, config => {
84    const projectRoot = config.modRequest.projectRoot;
85    const expoUpdatesPackageVersion = (0, _Updates().getExpoUpdatesPackageVersion)(projectRoot);
86    config.modResults = setUpdatesConfig(projectRoot, config, config.modResults, expoUsername, expoUpdatesPackageVersion);
87    return config;
88  });
89};
90
91exports.withUpdates = withUpdates;
92
93function setUpdatesConfig(projectRoot, config, expoPlist, username, expoUpdatesPackageVersion) {
94  const newExpoPlist = { ...expoPlist,
95    [Config.ENABLED]: (0, _Updates().getUpdatesEnabled)(config),
96    [Config.CHECK_ON_LAUNCH]: (0, _Updates().getUpdatesCheckOnLaunch)(config, expoUpdatesPackageVersion),
97    [Config.LAUNCH_WAIT_MS]: (0, _Updates().getUpdatesTimeout)(config)
98  };
99  const updateUrl = (0, _Updates().getUpdateUrl)(config, username);
100
101  if (updateUrl) {
102    newExpoPlist[Config.UPDATE_URL] = updateUrl;
103  } else {
104    delete newExpoPlist[Config.UPDATE_URL];
105  }
106
107  const codeSigningCertificate = (0, _Updates().getUpdatesCodeSigningCertificate)(projectRoot, config);
108
109  if (codeSigningCertificate) {
110    newExpoPlist[Config.CODE_SIGNING_CERTIFICATE] = codeSigningCertificate;
111  } else {
112    delete newExpoPlist[Config.CODE_SIGNING_CERTIFICATE];
113  }
114
115  const codeSigningMetadata = (0, _Updates().getUpdatesCodeSigningMetadata)(config);
116
117  if (codeSigningMetadata) {
118    newExpoPlist[Config.CODE_SIGNING_METADATA] = codeSigningMetadata;
119  } else {
120    delete newExpoPlist[Config.CODE_SIGNING_METADATA];
121  }
122
123  return setVersionsConfig(config, newExpoPlist);
124}
125
126function setVersionsConfig(config, expoPlist) {
127  const newExpoPlist = { ...expoPlist
128  };
129  const runtimeVersion = (0, _Updates().getRuntimeVersionNullable)(config, 'ios');
130
131  if (!runtimeVersion && expoPlist[Config.RUNTIME_VERSION]) {
132    throw new Error('A runtime version is set in your Expo.plist, but is missing from your app.json/app.config.js. Please either set runtimeVersion in your app.json/app.config.js or remove EXUpdatesRuntimeVersion from your Expo.plist.');
133  }
134
135  const sdkVersion = (0, _Updates().getSDKVersion)(config);
136
137  if (runtimeVersion) {
138    delete newExpoPlist[Config.SDK_VERSION];
139    newExpoPlist[Config.RUNTIME_VERSION] = runtimeVersion;
140  } else if (sdkVersion) {
141    /**
142     * runtime version maybe null in projects using classic updates. In that
143     * case we use SDK version
144     */
145    delete newExpoPlist[Config.RUNTIME_VERSION];
146    newExpoPlist[Config.SDK_VERSION] = sdkVersion;
147  } else {
148    delete newExpoPlist[Config.SDK_VERSION];
149    delete newExpoPlist[Config.RUNTIME_VERSION];
150  }
151
152  return newExpoPlist;
153}
154
155function formatConfigurationScriptPath(projectRoot) {
156  const buildScriptPath = _resolveFrom().default.silent(projectRoot, CREATE_MANIFEST_IOS_PATH);
157
158  if (!buildScriptPath) {
159    throw new Error("Could not find the build script for iOS. This could happen in case of outdated 'node_modules'. Run 'npm install' to make sure that it's up-to-date.");
160  }
161
162  const relativePath = path().relative(path().join(projectRoot, 'ios'), buildScriptPath);
163  return process.platform === 'win32' ? relativePath.replace(/\\/g, '/') : relativePath;
164}
165
166function getBundleReactNativePhase(project) {
167  const shellScriptBuildPhase = project.hash.project.objects.PBXShellScriptBuildPhase;
168  const bundleReactNative = Object.values(shellScriptBuildPhase).find(buildPhase => buildPhase.name === '"Bundle React Native code and images"');
169
170  if (!bundleReactNative) {
171    throw new Error(`Couldn't find a build phase "Bundle React Native code and images"`);
172  }
173
174  return bundleReactNative;
175}
176
177function ensureBundleReactNativePhaseContainsConfigurationScript(projectRoot, project) {
178  const bundleReactNative = getBundleReactNativePhase(project);
179  const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);
180
181  if (!isShellScriptBuildPhaseConfigured(projectRoot, project)) {
182    // check if there's already another path to create-manifest-ios.sh
183    // this might be the case for monorepos
184    if (bundleReactNative.shellScript.includes(CREATE_MANIFEST_IOS_PATH)) {
185      bundleReactNative.shellScript = bundleReactNative.shellScript.replace(new RegExp(`(\\\\n)(\\.\\.)+/node_modules/${CREATE_MANIFEST_IOS_PATH}`), '');
186    }
187
188    bundleReactNative.shellScript = `${bundleReactNative.shellScript.replace(/"$/, '')}${buildPhaseShellScriptPath}\\n"`;
189  }
190
191  return project;
192}
193
194function isShellScriptBuildPhaseConfigured(projectRoot, project) {
195  const bundleReactNative = getBundleReactNativePhase(project);
196  const buildPhaseShellScriptPath = formatConfigurationScriptPath(projectRoot);
197  return bundleReactNative.shellScript.includes(buildPhaseShellScriptPath);
198}
199
200function isPlistConfigurationSet(expoPlist) {
201  return Boolean(expoPlist.EXUpdatesURL && (expoPlist.EXUpdatesSDKVersion || expoPlist.EXUpdatesRuntimeVersion));
202}
203
204function isPlistConfigurationSynced(projectRoot, config, expoPlist, username) {
205  return (0, _Updates().getUpdateUrl)(config, username) === expoPlist.EXUpdatesURL && (0, _Updates().getUpdatesEnabled)(config) === expoPlist.EXUpdatesEnabled && (0, _Updates().getUpdatesTimeout)(config) === expoPlist.EXUpdatesLaunchWaitMs && (0, _Updates().getUpdatesCheckOnLaunch)(config) === expoPlist.EXUpdatesCheckOnLaunch && (0, _Updates().getUpdatesCodeSigningCertificate)(projectRoot, config) === expoPlist.EXUpdatesCodeSigningCertificate && (0, _Updates().getUpdatesCodeSigningMetadata)(config) === expoPlist.EXUpdatesCodeSigningMetadata && isPlistVersionConfigurationSynced(config, expoPlist);
206}
207
208function isPlistVersionConfigurationSynced(config, expoPlist) {
209  var _expoPlist$EXUpdatesR, _expoPlist$EXUpdatesS;
210
211  const expectedRuntimeVersion = (0, _Updates().getRuntimeVersionNullable)(config, 'ios');
212  const expectedSdkVersion = (0, _Updates().getSDKVersion)(config);
213  const currentRuntimeVersion = (_expoPlist$EXUpdatesR = expoPlist.EXUpdatesRuntimeVersion) !== null && _expoPlist$EXUpdatesR !== void 0 ? _expoPlist$EXUpdatesR : null;
214  const currentSdkVersion = (_expoPlist$EXUpdatesS = expoPlist.EXUpdatesSDKVersion) !== null && _expoPlist$EXUpdatesS !== void 0 ? _expoPlist$EXUpdatesS : null;
215
216  if (expectedRuntimeVersion !== null) {
217    return currentRuntimeVersion === expectedRuntimeVersion && currentSdkVersion === null;
218  } else if (expectedSdkVersion !== null) {
219    return currentSdkVersion === expectedSdkVersion && currentRuntimeVersion === null;
220  } else {
221    return true;
222  }
223}
224//# sourceMappingURL=Updates.js.map