1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.getIosModFileProviders = getIosModFileProviders; 7exports.withIosBaseMods = withIosBaseMods; 8function _jsonFile() { 9 const data = _interopRequireDefault(require("@expo/json-file")); 10 _jsonFile = function () { 11 return data; 12 }; 13 return data; 14} 15function _plist() { 16 const data = _interopRequireDefault(require("@expo/plist")); 17 _plist = function () { 18 return data; 19 }; 20 return data; 21} 22function _assert() { 23 const data = _interopRequireDefault(require("assert")); 24 _assert = function () { 25 return data; 26 }; 27 return data; 28} 29function _fs() { 30 const data = _interopRequireWildcard(require("fs")); 31 _fs = function () { 32 return data; 33 }; 34 return data; 35} 36function _path() { 37 const data = _interopRequireDefault(require("path")); 38 _path = function () { 39 return data; 40 }; 41 return data; 42} 43function _xcode() { 44 const data = _interopRequireDefault(require("xcode")); 45 _xcode = function () { 46 return data; 47 }; 48 return data; 49} 50function _ios() { 51 const data = require("../ios"); 52 _ios = function () { 53 return data; 54 }; 55 return data; 56} 57function _Entitlements() { 58 const data = require("../ios/Entitlements"); 59 _Entitlements = function () { 60 return data; 61 }; 62 return data; 63} 64function _Xcodeproj() { 65 const data = require("../ios/utils/Xcodeproj"); 66 _Xcodeproj = function () { 67 return data; 68 }; 69 return data; 70} 71function _getInfoPlistPath() { 72 const data = require("../ios/utils/getInfoPlistPath"); 73 _getInfoPlistPath = function () { 74 return data; 75 }; 76 return data; 77} 78function _modules() { 79 const data = require("../utils/modules"); 80 _modules = function () { 81 return data; 82 }; 83 return data; 84} 85function _sortObject() { 86 const data = require("../utils/sortObject"); 87 _sortObject = function () { 88 return data; 89 }; 90 return data; 91} 92function _warnings() { 93 const data = require("../utils/warnings"); 94 _warnings = function () { 95 return data; 96 }; 97 return data; 98} 99function _createBaseMod() { 100 const data = require("./createBaseMod"); 101 _createBaseMod = function () { 102 return data; 103 }; 104 return data; 105} 106function _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); } 107function _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; } 108function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 109const { 110 readFile, 111 writeFile 112} = _fs().promises; 113function getEntitlementsPlistTemplate() { 114 // TODO: Fetch the versioned template file if possible 115 return {}; 116} 117function getInfoPlistTemplate() { 118 // TODO: Fetch the versioned template file if possible 119 return { 120 CFBundleDevelopmentRegion: '$(DEVELOPMENT_LANGUAGE)', 121 CFBundleExecutable: '$(EXECUTABLE_NAME)', 122 CFBundleIdentifier: '$(PRODUCT_BUNDLE_IDENTIFIER)', 123 CFBundleName: '$(PRODUCT_NAME)', 124 CFBundlePackageType: '$(PRODUCT_BUNDLE_PACKAGE_TYPE)', 125 CFBundleInfoDictionaryVersion: '6.0', 126 CFBundleSignature: '????', 127 LSRequiresIPhoneOS: true, 128 NSAppTransportSecurity: { 129 NSAllowsArbitraryLoads: true, 130 NSExceptionDomains: { 131 localhost: { 132 NSExceptionAllowsInsecureHTTPLoads: true 133 } 134 } 135 }, 136 UILaunchStoryboardName: 'SplashScreen', 137 UIRequiredDeviceCapabilities: ['armv7'], 138 UIViewControllerBasedStatusBarAppearance: false, 139 UIStatusBarStyle: 'UIStatusBarStyleDefault' 140 }; 141} 142const defaultProviders = { 143 dangerous: (0, _createBaseMod().provider)({ 144 getFilePath() { 145 return ''; 146 }, 147 async read() { 148 return {}; 149 }, 150 async write() {} 151 }), 152 // Append a rule to supply AppDelegate data to mods on `mods.ios.appDelegate` 153 appDelegate: (0, _createBaseMod().provider)({ 154 getFilePath({ 155 modRequest: { 156 projectRoot 157 } 158 }) { 159 // TODO: Get application AppDelegate file from pbxproj. 160 return _ios().Paths.getAppDelegateFilePath(projectRoot); 161 }, 162 async read(filePath) { 163 return _ios().Paths.getFileInfo(filePath); 164 }, 165 async write(filePath, { 166 modResults: { 167 contents 168 } 169 }) { 170 await writeFile(filePath, contents); 171 } 172 }), 173 // Append a rule to supply Expo.plist data to mods on `mods.ios.expoPlist` 174 expoPlist: (0, _createBaseMod().provider)({ 175 isIntrospective: true, 176 getFilePath({ 177 modRequest: { 178 platformProjectRoot, 179 projectName 180 } 181 }) { 182 const supportingDirectory = _path().default.join(platformProjectRoot, projectName, 'Supporting'); 183 return _path().default.resolve(supportingDirectory, 'Expo.plist'); 184 }, 185 async read(filePath, { 186 modRequest: { 187 introspect 188 } 189 }) { 190 try { 191 return _plist().default.parse(await readFile(filePath, 'utf8')); 192 } catch (error) { 193 if (introspect) { 194 return {}; 195 } 196 throw error; 197 } 198 }, 199 async write(filePath, { 200 modResults, 201 modRequest: { 202 introspect 203 } 204 }) { 205 if (introspect) { 206 return; 207 } 208 await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(modResults))); 209 } 210 }), 211 // Append a rule to supply .xcodeproj data to mods on `mods.ios.xcodeproj` 212 xcodeproj: (0, _createBaseMod().provider)({ 213 getFilePath({ 214 modRequest: { 215 projectRoot 216 } 217 }) { 218 return _ios().Paths.getPBXProjectPath(projectRoot); 219 }, 220 async read(filePath) { 221 const project = _xcode().default.project(filePath); 222 project.parseSync(); 223 return project; 224 }, 225 async write(filePath, { 226 modResults 227 }) { 228 await writeFile(filePath, modResults.writeSync()); 229 } 230 }), 231 // Append a rule to supply Info.plist data to mods on `mods.ios.infoPlist` 232 infoPlist: (0, _createBaseMod().provider)({ 233 isIntrospective: true, 234 async getFilePath(config) { 235 let project = null; 236 try { 237 project = (0, _Xcodeproj().getPbxproj)(config.modRequest.projectRoot); 238 } catch { 239 // noop 240 } 241 242 // Only check / warn if a project actually exists, this'll provide 243 // more accurate warning messages for users in managed projects. 244 if (project) { 245 const infoPlistBuildProperty = (0, _getInfoPlistPath().getInfoPlistPathFromPbxproj)(project); 246 if (infoPlistBuildProperty) { 247 //: [root]/myapp/ios/MyApp/Info.plist 248 const infoPlistPath = _path().default.join( 249 //: myapp/ios 250 config.modRequest.platformProjectRoot, 251 //: MyApp/Info.plist 252 infoPlistBuildProperty); 253 if ((0, _modules().fileExists)(infoPlistPath)) { 254 return infoPlistPath; 255 } 256 (0, _warnings().addWarningIOS)('mods.ios.infoPlist', `Info.plist file linked to Xcode project does not exist: ${infoPlistPath}`); 257 } else { 258 (0, _warnings().addWarningIOS)('mods.ios.infoPlist', 'Failed to find Info.plist linked to Xcode project.'); 259 } 260 } 261 try { 262 // Fallback on glob... 263 return await _ios().Paths.getInfoPlistPath(config.modRequest.projectRoot); 264 } catch (error) { 265 if (config.modRequest.introspect) { 266 // fallback to an empty string in introspection mode. 267 return ''; 268 } 269 throw error; 270 } 271 }, 272 async read(filePath, config) { 273 // Apply all of the Info.plist values to the expo.ios.infoPlist object 274 // TODO: Remove this in favor of just overwriting the Info.plist with the Expo object. This will enable people to actually remove values. 275 if (!config.ios) config.ios = {}; 276 if (!config.ios.infoPlist) config.ios.infoPlist = {}; 277 let modResults; 278 try { 279 const contents = await readFile(filePath, 'utf8'); 280 (0, _assert().default)(contents, 'Info.plist is empty'); 281 modResults = _plist().default.parse(contents); 282 } catch (error) { 283 // Throw errors in introspection mode. 284 if (!config.modRequest.introspect) { 285 throw error; 286 } 287 // Fallback to using the infoPlist object from the Expo config. 288 modResults = getInfoPlistTemplate(); 289 } 290 config.ios.infoPlist = { 291 ...(modResults || {}), 292 ...config.ios.infoPlist 293 }; 294 return config.ios.infoPlist; 295 }, 296 async write(filePath, config) { 297 // Update the contents of the static infoPlist object 298 if (!config.ios) { 299 config.ios = {}; 300 } 301 config.ios.infoPlist = config.modResults; 302 303 // Return early without writing, in introspection mode. 304 if (config.modRequest.introspect) { 305 return; 306 } 307 await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(config.modResults))); 308 } 309 }), 310 // Append a rule to supply .entitlements data to mods on `mods.ios.entitlements` 311 entitlements: (0, _createBaseMod().provider)({ 312 isIntrospective: true, 313 async getFilePath(config) { 314 try { 315 var _Entitlements$getEnti; 316 (0, _Entitlements().ensureApplicationTargetEntitlementsFileConfigured)(config.modRequest.projectRoot); 317 return (_Entitlements$getEnti = _ios().Entitlements.getEntitlementsPath(config.modRequest.projectRoot)) !== null && _Entitlements$getEnti !== void 0 ? _Entitlements$getEnti : ''; 318 } catch (error) { 319 if (config.modRequest.introspect) { 320 // fallback to an empty string in introspection mode. 321 return ''; 322 } 323 throw error; 324 } 325 }, 326 async read(filePath, config) { 327 let modResults; 328 try { 329 if (_fs().default.existsSync(filePath)) { 330 const contents = await readFile(filePath, 'utf8'); 331 (0, _assert().default)(contents, 'Entitlements plist is empty'); 332 modResults = _plist().default.parse(contents); 333 } else { 334 modResults = getEntitlementsPlistTemplate(); 335 } 336 } catch (error) { 337 // Throw errors in introspection mode. 338 if (!config.modRequest.introspect) { 339 throw error; 340 } 341 // Fallback to using the template file. 342 modResults = getEntitlementsPlistTemplate(); 343 } 344 345 // Apply all of the .entitlements values to the expo.ios.entitlements object 346 // TODO: Remove this in favor of just overwriting the .entitlements with the Expo object. This will enable people to actually remove values. 347 if (!config.ios) config.ios = {}; 348 if (!config.ios.entitlements) config.ios.entitlements = {}; 349 config.ios.entitlements = { 350 ...(modResults || {}), 351 ...config.ios.entitlements 352 }; 353 return config.ios.entitlements; 354 }, 355 async write(filePath, config) { 356 // Update the contents of the static entitlements object 357 if (!config.ios) { 358 config.ios = {}; 359 } 360 config.ios.entitlements = config.modResults; 361 362 // Return early without writing, in introspection mode. 363 if (config.modRequest.introspect) { 364 return; 365 } 366 await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(config.modResults))); 367 } 368 }), 369 // Append a rule to supply Podfile.properties.json data to mods on `mods.ios.podfileProperties` 370 podfileProperties: (0, _createBaseMod().provider)({ 371 isIntrospective: true, 372 getFilePath({ 373 modRequest: { 374 platformProjectRoot 375 } 376 }) { 377 return _path().default.resolve(platformProjectRoot, 'Podfile.properties.json'); 378 }, 379 async read(filePath) { 380 let results = {}; 381 try { 382 results = await _jsonFile().default.readAsync(filePath); 383 } catch {} 384 return results; 385 }, 386 async write(filePath, { 387 modResults, 388 modRequest: { 389 introspect 390 } 391 }) { 392 if (introspect) { 393 return; 394 } 395 await _jsonFile().default.writeAsync(filePath, modResults); 396 } 397 }) 398}; 399function withIosBaseMods(config, { 400 providers, 401 ...props 402} = {}) { 403 return (0, _createBaseMod().withGeneratedBaseMods)(config, { 404 ...props, 405 platform: 'ios', 406 providers: providers !== null && providers !== void 0 ? providers : getIosModFileProviders() 407 }); 408} 409function getIosModFileProviders() { 410 return defaultProviders; 411} 412//# sourceMappingURL=withIosBaseMods.js.map