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