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