1{"version":3,"file":"Swift.js","names":["_fs","data","_interopRequireDefault","require","_path","_Paths","_XcodeProjectFile","_Xcodeproj","_iosPlugins","obj","__esModule","default","templateBridgingHeader","withSwiftBridgingHeader","config","withXcodeProject","modResults","ensureSwiftBridgingHeaderSetup","project","projectRoot","modRequest","exports","shouldCreateSwiftBridgingHeader","projectName","getProjectName","bridgingHeader","createBridgingHeaderFileName","createBridgingHeaderFile","linkBridgingHeaderFile","path","join","isObjc","getAppDelegate","language","getDesignatedSwiftBridgingHeaderFileReference","configurations","pbxXCBuildConfigurationSection","buildSettings","Object","values","PRODUCT_NAME","SWIFT_OBJC_BRIDGING_HEADER","bridgingHeaderProjectPath","getSourceRoot","fs","existsSync","writeFileSync","filePath","hasFile","addResourceFileToGroup","filepath","groupName","isBuildFile","verbose","withNoopSwiftFile","withBuildSourceFile","contents"],"sources":["../../src/ios/Swift.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport { getAppDelegate, getSourceRoot } from './Paths';\nimport { withBuildSourceFile } from './XcodeProjectFile';\nimport { addResourceFileToGroup, getProjectName } from './utils/Xcodeproj';\nimport { ConfigPlugin, XcodeProject } from '../Plugin.types';\nimport { withXcodeProject } from '../plugins/ios-plugins';\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 !== 'swift';\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      verbose: false,\n    });\n  }\n  return project;\n}\n\nexport const withNoopSwiftFile: ConfigPlugin = (config) => {\n  return withBuildSourceFile(config, {\n    filePath: 'noop-file.swift',\n    contents: [\n      '//',\n      '// @generated',\n      '// A blank Swift file must be created for native modules with Swift files to work correctly.',\n      '//',\n      '',\n    ].join('\\n'),\n  });\n};\n"],"mappings":";;;;;;;;;;AAAA,SAAAA,IAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,GAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,MAAA;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