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