1*7c10e2d9SEvan Baconconst { withDangerousMod, IOSConfig } = require('@expo/config-plugins'); 2*7c10e2d9SEvan Baconconst fs = require('fs-extra'); 3*7c10e2d9SEvan Bacon 4*7c10e2d9SEvan Bacon// Append this block to the AppDelegate to fix https://stackoverflow.com/a/56160671/4047926 5*7c10e2d9SEvan Baconconst customBlockObjc = `// [Custom]: Fixes \`Unable to find module for DevMenu\` 6*7c10e2d9SEvan Bacon#if RCT_DEV 7*7c10e2d9SEvan Bacon- (BOOL)bridge:(RCTBridge *)bridge didNotFindModule:(NSString *)moduleName { 8*7c10e2d9SEvan Bacon return YES; 9*7c10e2d9SEvan Bacon} 10*7c10e2d9SEvan Bacon#endif 11*7c10e2d9SEvan Bacon 12*7c10e2d9SEvan Bacon`; 13*7c10e2d9SEvan Bacon 14*7c10e2d9SEvan Baconmodule.exports = config => { 15*7c10e2d9SEvan Bacon return withDangerousMod(config, [ 16*7c10e2d9SEvan Bacon 'ios', 17*7c10e2d9SEvan Bacon async config => { 18*7c10e2d9SEvan Bacon const fileInfo = IOSConfig.Paths.getAppDelegate(config.modRequest.projectRoot); 19*7c10e2d9SEvan Bacon let contents = await fs.readFile(fileInfo.path, 'utf-8'); 20*7c10e2d9SEvan Bacon if (fileInfo.language === 'objc') { 21*7c10e2d9SEvan Bacon if (!contents.match(/didNotFindModule:\(NSString\s?\*\)moduleName/)) { 22*7c10e2d9SEvan Bacon const sections = contents.split('@end'); 23*7c10e2d9SEvan Bacon sections[sections.length - 2] += customBlockObjc; 24*7c10e2d9SEvan Bacon contents = sections.join('@end'); 25*7c10e2d9SEvan Bacon } 26*7c10e2d9SEvan Bacon } else { 27*7c10e2d9SEvan Bacon throw new Error( 28*7c10e2d9SEvan Bacon `Cannot append didNotFindModule method to AppDelegate of language "${fileInfo.language}"` 29*7c10e2d9SEvan Bacon ); 30*7c10e2d9SEvan Bacon } 31*7c10e2d9SEvan Bacon await fs.writeFile(fileInfo.path, contents); 32*7c10e2d9SEvan Bacon 33*7c10e2d9SEvan Bacon return config; 34*7c10e2d9SEvan Bacon }, 35*7c10e2d9SEvan Bacon ]); 36*7c10e2d9SEvan Bacon}; 37