xref: /expo/packages/@expo/config/build/getConfig.js (revision b7576b8a)
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.getDynamicConfig = getDynamicConfig;
7exports.getStaticConfig = getStaticConfig;
8function _jsonFile() {
9  const data = _interopRequireDefault(require("@expo/json-file"));
10  _jsonFile = function () {
11    return data;
12  };
13  return data;
14}
15function _fs() {
16  const data = require("fs");
17  _fs = function () {
18    return data;
19  };
20  return data;
21}
22function _Errors() {
23  const data = require("./Errors");
24  _Errors = function () {
25    return data;
26  };
27  return data;
28}
29function _evalConfig() {
30  const data = require("./evalConfig");
31  _evalConfig = function () {
32    return data;
33  };
34  return data;
35}
36function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37// We cannot use async config resolution right now because Next.js doesn't support async configs.
38// If they don't add support for async Webpack configs then we may need to pull support for Next.js.
39function readConfigFile(configFile, context) {
40  // If the file doesn't exist then we should skip it and continue searching.
41  if (!(0, _fs().existsSync)(configFile)) {
42    return null;
43  }
44  try {
45    return (0, _evalConfig().evalConfig)(configFile, context);
46  } catch (error) {
47    // @ts-ignore
48    error.isConfigError = true;
49    error.message = `Error reading Expo config at ${configFile}:\n\n${error.message}`;
50    throw error;
51  }
52}
53function getDynamicConfig(configPath, request) {
54  const config = readConfigFile(configPath, request);
55  if (config) {
56    // The config must be serialized and evaluated ahead of time so the spawned process can send it over.
57    return config;
58  }
59  // TODO: It seems this is only thrown if the file cannot be found (which may never happen).
60  // If so we should throw a more helpful error.
61  throw new (_Errors().ConfigError)(`Failed to read config at: ${configPath}`, 'INVALID_CONFIG');
62}
63function getStaticConfig(configPath) {
64  const config = _jsonFile().default.read(configPath, {
65    json5: true
66  });
67  if (config) {
68    return config;
69  }
70  throw new (_Errors().ConfigError)(`Failed to read config at: ${configPath}`, 'INVALID_CONFIG');
71}
72//# sourceMappingURL=getConfig.js.map