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