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P,cAAc,GAMf;IACC,MAAM,yBAAyB,GAAG,cAAI,CAAC,IAAI,CAAC,qBAAa,CAAC,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC;IACxF,IAAI,CAAC,kBAAE,CAAC,UAAU,CAAC,yBAAyB,CAAC,EAAE;QAC7C,kBAAkB;QAClB,kBAAE,CAAC,aAAa,CAAC,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,CAAC,CAAC;KAC7E;IAED,+FAA+F;IAC/F,iGAAiG;IACjG,MAAM,QAAQ,GAAG,GAAG,WAAW,IAAI,cAAc,EAAE,CAAC;IACpD,sDAAsD;IACtD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC9B,OAAO,GAAG,kCAAsB,CAAC;YAC/B,QAAQ,EAAE,QAAQ;YAClB,SAAS,EAAE,WAAW;YACtB,OAAO;YACP,oDAAoD;YACpD,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;KACJ;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AA/BD,4DA+BC","sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\n\nimport { ConfigPlugin, XcodeProject } from '../Plugin.types';\nimport { withXcodeProject } from '../plugins/ios-plugins';\nimport { getAppDelegate, getSourceRoot } from './Paths';\nimport { addResourceFileToGroup, getProjectName } from './utils/Xcodeproj';\n\nconst templateBridgingHeader = `//\n// Use this file to import your target's public headers that you would like to expose to Swift.\n//\n`;\n\n/**\n * Ensure a Swift bridging header is created for the project.\n * This helps fix problems related to using modules that are written in Swift (lottie, FBSDK).\n *\n * 1. Ensures the file exists given the project path.\n * 2. Writes the file and links to Xcode as a resource file.\n * 3. Sets the build configuration `SWIFT_OBJC_BRIDGING_HEADER = [PROJECT_NAME]-Bridging-Header.h`\n */\nexport const withSwiftBridgingHeader: ConfigPlugin = config => {\n return withXcodeProject(config, config => {\n config.modResults = ensureSwiftBridgingHeaderSetup({\n project: config.modResults,\n projectRoot: config.modRequest.projectRoot,\n });\n return config;\n });\n};\n\nexport function ensureSwiftBridgingHeaderSetup({\n projectRoot,\n project,\n}: {\n projectRoot: string;\n project: XcodeProject;\n}) {\n // Only create a bridging header if using objective-c\n if (shouldCreateSwiftBridgingHeader({ projectRoot, project })) {\n const projectName = getProjectName(projectRoot);\n const bridgingHeader = createBridgingHeaderFileName(projectName);\n // Ensure a bridging header is created in the Xcode project.\n project = createBridgingHeaderFile({\n project,\n projectName,\n projectRoot,\n bridgingHeader,\n });\n // Designate the newly created file as the Swift bridging header in the Xcode project.\n project = linkBridgingHeaderFile({\n project,\n bridgingHeader: path.join(projectName, bridgingHeader),\n });\n }\n return project;\n}\n\nfunction shouldCreateSwiftBridgingHeader({\n projectRoot,\n project,\n}: {\n projectRoot: string;\n project: XcodeProject;\n}): boolean {\n // Only create a bridging header if the project is using in Objective C (AppDelegate is written in Objc).\n const isObjc = getAppDelegate(projectRoot).language === 'objc';\n return isObjc && !getDesignatedSwiftBridgingHeaderFileReference({ project });\n}\n\n/**\n * @returns String matching the default name used when Xcode automatically creates a bridging header file.\n */\nfunction createBridgingHeaderFileName(projectName: string): string {\n return `${projectName}-Bridging-Header.h`;\n}\n\nexport function getDesignatedSwiftBridgingHeaderFileReference({\n project,\n}: {\n project: XcodeProject;\n}): string | null {\n const configurations = project.pbxXCBuildConfigurationSection();\n // @ts-ignore\n for (const { buildSettings } of Object.values(configurations || {})) {\n // Guessing that this is the best way to emulate Xcode.\n // Using `project.addToBuildSettings` modifies too many targets.\n if (typeof buildSettings?.PRODUCT_NAME !== 'undefined') {\n if (\n typeof buildSettings.SWIFT_OBJC_BRIDGING_HEADER === 'string' &&\n buildSettings.SWIFT_OBJC_BRIDGING_HEADER\n ) {\n return buildSettings.SWIFT_OBJC_BRIDGING_HEADER;\n }\n }\n }\n return null;\n}\n\n/**\n *\n * @param bridgingHeader The bridging header filename ex: `ExpoAPIs-Bridging-Header.h`\n * @returns\n */\nexport function linkBridgingHeaderFile({\n project,\n bridgingHeader,\n}: {\n project: XcodeProject;\n bridgingHeader: string;\n}): XcodeProject {\n const configurations = project.pbxXCBuildConfigurationSection();\n // @ts-ignore\n for (const { buildSettings } of Object.values(configurations || {})) {\n // Guessing that this is the best way to emulate Xcode.\n // Using `project.addToBuildSettings` modifies too many targets.\n if (typeof buildSettings?.PRODUCT_NAME !== 'undefined') {\n buildSettings.SWIFT_OBJC_BRIDGING_HEADER = bridgingHeader;\n }\n }\n\n return project;\n}\n\nexport function createBridgingHeaderFile({\n projectRoot,\n projectName,\n project,\n bridgingHeader,\n}: {\n project: XcodeProject;\n projectName: string;\n projectRoot: string;\n bridgingHeader: string;\n}): XcodeProject {\n const bridgingHeaderProjectPath = path.join(getSourceRoot(projectRoot), bridgingHeader);\n if (!fs.existsSync(bridgingHeaderProjectPath)) {\n // Create the file\n fs.writeFileSync(bridgingHeaderProjectPath, templateBridgingHeader, 'utf8');\n }\n\n // This is non-standard, Xcode generates the bridging header in `/ios` which is kinda annoying.\n // Instead, this'll generate the default header in the application code folder `/ios/myproject/`.\n const filePath = `${projectName}/${bridgingHeader}`;\n // Ensure the file is linked with Xcode resource files\n if (!project.hasFile(filePath)) {\n project = addResourceFileToGroup({\n filepath: filePath,\n groupName: projectName,\n project,\n // Not sure why, but this is how Xcode generates it.\n isBuildFile: false,\n });\n }\n return project;\n}\n"]}