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      return _ios().Paths.getAppDelegateFilePath(projectRoot);
212    },
213
214    async read(filePath) {
215      return _ios().Paths.getFileInfo(filePath);
216    },
217
218    async write(filePath, {
219      modResults: {
220        contents
221      }
222    }) {
223      await writeFile(filePath, contents);
224    }
225
226  }),
227  // Append a rule to supply Expo.plist data to mods on `mods.ios.expoPlist`
228  expoPlist: (0, _createBaseMod().provider)({
229    isIntrospective: true,
230
231    getFilePath({
232      modRequest: {
233        platformProjectRoot,
234        projectName
235      }
236    }) {
237      const supportingDirectory = _path().default.join(platformProjectRoot, projectName, 'Supporting');
238
239      return _path().default.resolve(supportingDirectory, 'Expo.plist');
240    },
241
242    async read(filePath, {
243      modRequest: {
244        introspect
245      }
246    }) {
247      try {
248        return _plist().default.parse(await readFile(filePath, 'utf8'));
249      } catch (error) {
250        if (introspect) {
251          return {};
252        }
253
254        throw error;
255      }
256    },
257
258    async write(filePath, {
259      modResults,
260      modRequest: {
261        introspect
262      }
263    }) {
264      if (introspect) {
265        return;
266      }
267
268      await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(modResults)));
269    }
270
271  }),
272  // Append a rule to supply .xcodeproj data to mods on `mods.ios.xcodeproj`
273  xcodeproj: (0, _createBaseMod().provider)({
274    getFilePath({
275      modRequest: {
276        projectRoot
277      }
278    }) {
279      return _ios().Paths.getPBXProjectPath(projectRoot);
280    },
281
282    async read(filePath) {
283      const project = _xcode().default.project(filePath);
284
285      project.parseSync();
286      return project;
287    },
288
289    async write(filePath, {
290      modResults
291    }) {
292      await writeFile(filePath, modResults.writeSync());
293    }
294
295  }),
296  // Append a rule to supply Info.plist data to mods on `mods.ios.infoPlist`
297  infoPlist: (0, _createBaseMod().provider)({
298    isIntrospective: true,
299
300    async getFilePath(config) {
301      let project = null;
302
303      try {
304        project = (0, _Xcodeproj().getPbxproj)(config.modRequest.projectRoot);
305      } catch {// noop
306      } // Only check / warn if a project actually exists, this'll provide
307      // more accurate warning messages for users in managed projects.
308
309
310      if (project) {
311        const infoPlistBuildProperty = (0, _getInfoPlistPath().getInfoPlistPathFromPbxproj)(project);
312
313        if (infoPlistBuildProperty) {
314          //: [root]/myapp/ios/MyApp/Info.plist
315          const infoPlistPath = _path().default.join( //: myapp/ios
316          config.modRequest.platformProjectRoot, //: MyApp/Info.plist
317          infoPlistBuildProperty);
318
319          if ((0, _modules().fileExists)(infoPlistPath)) {
320            return infoPlistPath;
321          }
322
323          (0, _warnings().addWarningIOS)('mods.ios.infoPlist', `Info.plist file linked to Xcode project does not exist: ${infoPlistPath}`);
324        } else {
325          (0, _warnings().addWarningIOS)('mods.ios.infoPlist', 'Failed to find Info.plist linked to Xcode project.');
326        }
327      }
328
329      try {
330        // Fallback on glob...
331        return await _ios().Paths.getInfoPlistPath(config.modRequest.projectRoot);
332      } catch (error) {
333        if (config.modRequest.introspect) {
334          // fallback to an empty string in introspection mode.
335          return '';
336        }
337
338        throw error;
339      }
340    },
341
342    async read(filePath, config) {
343      // Apply all of the Info.plist values to the expo.ios.infoPlist object
344      // TODO: Remove this in favor of just overwriting the Info.plist with the Expo object. This will enable people to actually remove values.
345      if (!config.ios) config.ios = {};
346      if (!config.ios.infoPlist) config.ios.infoPlist = {};
347      let modResults;
348
349      try {
350        const contents = await readFile(filePath, 'utf8');
351        (0, _assert().default)(contents, 'Info.plist is empty');
352        modResults = _plist().default.parse(contents);
353      } catch (error) {
354        // Throw errors in introspection mode.
355        if (!config.modRequest.introspect) {
356          throw error;
357        } // Fallback to using the infoPlist object from the Expo config.
358
359
360        modResults = getInfoPlistTemplate();
361      }
362
363      config.ios.infoPlist = { ...(modResults || {}),
364        ...config.ios.infoPlist
365      };
366      return config.ios.infoPlist;
367    },
368
369    async write(filePath, config) {
370      // Update the contents of the static infoPlist object
371      if (!config.ios) {
372        config.ios = {};
373      }
374
375      config.ios.infoPlist = config.modResults; // Return early without writing, in introspection mode.
376
377      if (config.modRequest.introspect) {
378        return;
379      }
380
381      await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(config.modResults)));
382    }
383
384  }),
385  // Append a rule to supply .entitlements data to mods on `mods.ios.entitlements`
386  entitlements: (0, _createBaseMod().provider)({
387    isIntrospective: true,
388
389    async getFilePath(config) {
390      try {
391        var _Entitlements$getEnti;
392
393        (0, _Entitlements().ensureApplicationTargetEntitlementsFileConfigured)(config.modRequest.projectRoot);
394        return (_Entitlements$getEnti = _ios().Entitlements.getEntitlementsPath(config.modRequest.projectRoot)) !== null && _Entitlements$getEnti !== void 0 ? _Entitlements$getEnti : '';
395      } catch (error) {
396        if (config.modRequest.introspect) {
397          // fallback to an empty string in introspection mode.
398          return '';
399        }
400
401        throw error;
402      }
403    },
404
405    async read(filePath, config) {
406      let modResults;
407
408      try {
409        if (_fs().default.existsSync(filePath)) {
410          const contents = await readFile(filePath, 'utf8');
411          (0, _assert().default)(contents, 'Entitlements plist is empty');
412          modResults = _plist().default.parse(contents);
413        } else {
414          modResults = getEntitlementsPlistTemplate();
415        }
416      } catch (error) {
417        // Throw errors in introspection mode.
418        if (!config.modRequest.introspect) {
419          throw error;
420        } // Fallback to using the template file.
421
422
423        modResults = getEntitlementsPlistTemplate();
424      } // Apply all of the .entitlements values to the expo.ios.entitlements object
425      // TODO: Remove this in favor of just overwriting the .entitlements with the Expo object. This will enable people to actually remove values.
426
427
428      if (!config.ios) config.ios = {};
429      if (!config.ios.entitlements) config.ios.entitlements = {};
430      config.ios.entitlements = { ...(modResults || {}),
431        ...config.ios.entitlements
432      };
433      return config.ios.entitlements;
434    },
435
436    async write(filePath, config) {
437      // Update the contents of the static entitlements object
438      if (!config.ios) {
439        config.ios = {};
440      }
441
442      config.ios.entitlements = config.modResults; // Return early without writing, in introspection mode.
443
444      if (config.modRequest.introspect) {
445        return;
446      }
447
448      await writeFile(filePath, _plist().default.build((0, _sortObject().sortObject)(config.modResults)));
449    }
450
451  }),
452  // Append a rule to supply Podfile.properties.json data to mods on `mods.ios.podfileProperties`
453  podfileProperties: (0, _createBaseMod().provider)({
454    isIntrospective: true,
455
456    getFilePath({
457      modRequest: {
458        platformProjectRoot
459      }
460    }) {
461      return _path().default.resolve(platformProjectRoot, 'Podfile.properties.json');
462    },
463
464    async read(filePath) {
465      let results = {};
466
467      try {
468        results = await _jsonFile().default.readAsync(filePath);
469      } catch {}
470
471      return results;
472    },
473
474    async write(filePath, {
475      modResults,
476      modRequest: {
477        introspect
478      }
479    }) {
480      if (introspect) {
481        return;
482      }
483
484      await _jsonFile().default.writeAsync(filePath, modResults);
485    }
486
487  })
488};
489
490function withIosBaseMods(config, {
491  providers,
492  ...props
493} = {}) {
494  return (0, _createBaseMod().withGeneratedBaseMods)(config, { ...props,
495    platform: 'ios',
496    providers: providers !== null && providers !== void 0 ? providers : getIosModFileProviders()
497  });
498}
499
500function getIosModFileProviders() {
501  return defaultProviders;
502}
503//# sourceMappingURL=withIosBaseMods.js.map