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CAAC,CAAC;AACrF,CAAC;AAND,0CAMC;AAED,iGAAiG;AACjG,oGAAoG;AACpG,SAAS,UAAU,CAAC,UAAkB,EAAE,OAAsB;IAC5D,MAAM,YAAY,GAAG,yBAAS,CAC5B,MAAM,EACN;QACE,OAAO,CAAC,OAAO,CAAC,2CAA2C,CAAC;QAC5D,UAAU;QACV,UAAU;QACV,IAAI,CAAC,SAAS,iCAAM,OAAO,KAAE,MAAM,EAAE,gCAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAG;KAC7E,EACD,EAAE,CACH,CAAC;IAEF,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7B,MAAM,iBAAiB,GAAG,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QACtE,MAAM,IAAI,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3C,6EAA6E;QAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAG,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,mCAAmC;YACnC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAClB;QACD,0FAA0F;QAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpC,OAAO,OAAO,CAAC;KAChB;SAAM;QACL,gDAAgD;QAChD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,MAAM,sBAAa,CAAC,SAAS,CAAC,CAAC;KAChC;AACH,CAAC","sourcesContent":["import JsonFile from '@expo/json-file';\nimport { spawnSync } from 'child_process';\n\nimport { AppJSONConfig, ConfigContext, ExpoConfig } from './Config.types';\nimport { ConfigError, errorFromJSON } from './Errors';\nimport { fileExists } from './Modules';\nimport { serializeAndEvaluate } from './Serialize';\n\ntype RawDynamicConfig = AppJSONConfig | Partial<ExpoConfig> | null;\n\ntype DynamicConfigResults = { config: RawDynamicConfig; exportedObjectType: string };\n\nfunction isMissingFileCode(code: string): boolean {\n return ['ENOENT', 'MODULE_NOT_FOUND', 'ENOTDIR'].includes(code);\n}\n\nfunction readConfigFile(\n configFilePath: string,\n context: ConfigContext\n): null | DynamicConfigResults {\n if (!fileExists(configFilePath)) return null;\n\n try {\n return evalConfig(configFilePath, context);\n } catch (error) {\n // If the file doesn't exist then we should skip it and continue searching.\n if (!isMissingFileCode(error.code)) {\n throw error;\n }\n }\n return null;\n}\n\nexport function getDynamicConfig(configPath: string, request: ConfigContext): DynamicConfigResults {\n const config = readConfigFile(configPath, request);\n if (config) {\n return serializeAndEvaluate(config);\n }\n throw new ConfigError(`Failed to read config at: ${configPath}`, 'INVALID_CONFIG');\n}\n\nexport function getStaticConfig(configPath: string): AppJSONConfig | ExpoConfig | null {\n const config = JsonFile.read(configPath, { json5: true });\n if (config) {\n return serializeAndEvaluate(config);\n }\n throw new ConfigError(`Failed to read config at: ${configPath}`, 'INVALID_CONFIG');\n}\n\n// We cannot use async config resolution right now because Next.js doesn't support async configs.\n// If they don't add support for async Webpack configs then we may need to pull support for Next.js.\nfunction evalConfig(configFile: string, request: ConfigContext): DynamicConfigResults {\n const spawnResults = spawnSync(\n 'node',\n [\n require.resolve('@expo/config/build/scripts/read-config.js'),\n '--colors',\n configFile,\n JSON.stringify({ ...request, config: serializeAndEvaluate(request.config) }),\n ],\n {}\n );\n\n if (spawnResults.status === 0) {\n const spawnResultString = spawnResults.stdout.toString('utf8').trim();\n const logs = spawnResultString.split('\\n');\n // Get the last console log to prevent parsing anything logged in the config.\n const lastLog = logs.pop()!;\n for (const log of logs) {\n // Log out the logs from the config\n console.log(log);\n }\n // Parse the final log of the script, it's the serialized config and exported object type.\n const results = JSON.parse(lastLog);\n return results;\n } else {\n // Parse the error data and throw it as expected\n const errorData = JSON.parse(spawnResults.stderr.toString('utf8'));\n throw errorFromJSON(errorData);\n }\n}\n"]}
\No newline at end of file