109bb6093SEvan Baconimport { ExpoConfig, modifyConfigAsync } from '@expo/config'; 209bb6093SEvan Bacon 309bb6093SEvan Baconimport { warnAboutConfigAndThrow } from './modifyConfigAsync'; 4*8a424bebSJames Ideimport * as Log from '../log'; 509bb6093SEvan Bacon 609bb6093SEvan Baconexport async function attemptAddingPluginsAsync( 709bb6093SEvan Bacon projectRoot: string, 809bb6093SEvan Bacon exp: Pick<ExpoConfig, 'plugins'>, 909bb6093SEvan Bacon plugins: string[] 1009bb6093SEvan Bacon): Promise<void> { 1109bb6093SEvan Bacon if (!plugins.length) return; 1209bb6093SEvan Bacon 1309bb6093SEvan Bacon const edits = { 1409bb6093SEvan Bacon plugins: [...new Set((exp.plugins || []).concat(plugins))], 1509bb6093SEvan Bacon }; 1609bb6093SEvan Bacon const modification = await modifyConfigAsync(projectRoot, edits, { 1709bb6093SEvan Bacon skipSDKVersionRequirement: true, 1809bb6093SEvan Bacon skipPlugins: true, 1909bb6093SEvan Bacon }); 2009bb6093SEvan Bacon if (modification.type === 'success') { 2109bb6093SEvan Bacon Log.log(`\u203A Added config plugin${plugins.length === 1 ? '' : 's'}: ${plugins.join(', ')}`); 2209bb6093SEvan Bacon } else { 2309bb6093SEvan Bacon const exactEdits = { 2409bb6093SEvan Bacon plugins, 2509bb6093SEvan Bacon }; 2609bb6093SEvan Bacon warnAboutConfigAndThrow(modification.type, modification.message!, exactEdits); 2709bb6093SEvan Bacon } 2809bb6093SEvan Bacon} 29