This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.
2021-04-02 02:24:13 +03:00

1 line
10 KiB
Plaintext

{"version":3,"file":"BundleIdentifier.js","sourceRoot":"","sources":["../../src/ios/BundleIdentifier.ts"],"names":[],"mappings":";;;;;AACA,wDAAiD;AACjD,oDAA4B;AAC5B,wDAA0B;AAC1B,kDAA0B;AAG1B,0DAA2D;AAE3D,mCAAyF;AACzF,iDAI2B;AAEd,QAAA,oBAAoB,GAAgD,CAC/E,MAAM,EACN,EAAE,gBAAgB,EAAE,EACpB,EAAE;IACF,OAAO,+BAAgB,CAAC,MAAM,EAAE;QAC9B,KAAK;QACL,KAAK,EAAC,MAAM,EAAC,EAAE;;YACb,MAAM,QAAQ,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,SAAI,MAAM,CAAC,GAAG,0CAAE,gBAAgB,CAAC;YAClE,gBAAM,CACJ,QAAQ,EACR,oIAAoI,CACrI,CAAC;YACF,MAAM,6BAA6B,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,QAAS,CAAC,CAAC;YAC9E,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,SAAS,mBAAmB,CAAC,MAAkB;;IAC7C,mBAAO,MAAM,CAAC,GAAG,0CAAE,gBAAgB,mCAAI,IAAI,CAAC;AAC9C,CAAC;AAiKC,kDAAmB;AA/JrB;;;GAGG;AACH,SAAS,mBAAmB,CAAC,MAAkB,EAAE,SAAoB;IACnE,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAErD,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,SAAS,CAAC;KAClB;IAED,uCACK,SAAS,KACZ,kBAAkB,EAAE,gBAAgB,IACpC;AACJ,CAAC;AAiJC,kDAAmB;AA/IrB;;;;;;;GAOG;AACH,SAAS,8BAA8B,CAAC,WAAmB;IACzD,IAAI,WAAmB,CAAC;IACx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;AA6CC,sEAA6B;AA3C/B;;GAEG;AAEH,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAEvD,SAAS,8BAA8B,CAAC,WAAmB;IACzD,MAAM,cAAc,GAAG,4BAAoB,CAAC,WAAW,CAAC,CAAC;IAEzD,KAAK,MAAM,SAAS,IAAI,cAAc,EAAE;QACtC,0BAA0B,CAAC,SAAS,CAAC,CAAC;KACvC;AACH,CAAC;AAgCC,wEAA8B;AA9BhC,SAAS,0BAA0B,CAAC,SAAiB;IACnD,MAAM,QAAQ,GAAG,kBAAE,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,WAAW,GAAG,eAAK,CAAC,KAAK,CAAC,QAAQ,CAAgB,CAAC;IAEzD,IAAI,WAAW,CAAC,kBAAkB,EAAE;QAClC,IAAI,WAAW,CAAC,kBAAkB,KAAK,eAAe;YAAE,OAAO;QAE/D,6CAA6C;QAC7C,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAE9C,MAAM,GAAG,GAAG,eAAK,CAAC,KAAK,iCAEhB,WAAW,KACd,kBAAkB,EAAE,eAAe,KAErC,MAAM,CACP,CAAC;QAEF,IAAI,GAAG,KAAK,QAAQ,EAAE;YACpB,kBAAE,CAAC,aAAa,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;SAClC;KACF;AACH,CAAC;AASC,gEAA0B","sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport plist, { PlistObject } from '@expo/plist';\nimport assert from 'assert';\nimport fs from 'fs-extra';\nimport xcode from 'xcode';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withDangerousMod } from '../plugins/core-plugins';\nimport { InfoPlist } from './IosConfig.types';\nimport { getAllInfoPlistPaths, getAllPBXProjectPaths, getPBXProjectPath } from './Paths';\nimport {\n ConfigurationSectionEntry,\n findFirstNativeTarget,\n getBuildConfigurationForId,\n} from './utils/Xcodeproj';\n\nexport const withBundleIdentifier: ConfigPlugin<{ bundleIdentifier?: string }> = (\n config,\n { bundleIdentifier }\n) => {\n return withDangerousMod(config, [\n 'ios',\n async config => {\n const bundleId = bundleIdentifier ?? config.ios?.bundleIdentifier;\n assert(\n bundleId,\n '`bundleIdentifier` must be defined in the app config (`expo.ios.bundleIdentifier`) or passed to the plugin `withBundleIdentifier`.'\n );\n await setBundleIdentifierForPbxproj(config.modRequest.projectRoot, bundleId!);\n return config;\n },\n ]);\n};\n\nfunction getBundleIdentifier(config: ExpoConfig): string | null {\n return config.ios?.bundleIdentifier ?? null;\n}\n\n/**\n * In Turtle v1 we set the bundleIdentifier directly on Info.plist rather\n * than in pbxproj\n */\nfunction setBundleIdentifier(config: ExpoConfig, infoPlist: InfoPlist): InfoPlist {\n const bundleIdentifier = getBundleIdentifier(config);\n\n if (!bundleIdentifier) {\n return infoPlist;\n }\n\n return {\n ...infoPlist,\n CFBundleIdentifier: bundleIdentifier,\n };\n}\n\n/**\n * Gets the bundle identifier of the Xcode project found in the project directory.\n * If either the Xcode project doesn't exist or the project is not configured\n * this function returns null.\n *\n * @param {string} projectRoot Path to project root containing the ios directory\n * @returns {string | null} bundle identifier of the Xcode project or null if the project is not configured\n */\nfunction getBundleIdentifierFromPbxproj(projectRoot: string): string | null {\n let pbxprojPath: string;\n try {\n pbxprojPath = getPBXProjectPath(projectRoot);\n } catch {\n return null;\n }\n const project = xcode.project(pbxprojPath);\n project.parseSync();\n\n const [, nativeTarget] = findFirstNativeTarget(project);\n for (const [, item] of getBuildConfigurationForId(project, nativeTarget.buildConfigurationList)) {\n const bundleIdentifierRaw = item.buildSettings.PRODUCT_BUNDLE_IDENTIFIER;\n if (bundleIdentifierRaw) {\n const bundleIdentifier =\n bundleIdentifierRaw[0] === '\"' ? bundleIdentifierRaw.slice(1, -1) : bundleIdentifierRaw;\n // it's possible to use interpolation for the bundle identifier\n // the most common case is when the last part of the id is set to `$(PRODUCT_NAME:rfc1034identifier)`\n // in this case, PRODUCT_NAME should be replaced with its value\n // the `rfc1034identifier` modifier replaces all non-alphanumeric characters with dashes\n const bundleIdentifierParts = bundleIdentifier.split('.');\n if (\n bundleIdentifierParts[bundleIdentifierParts.length - 1] ===\n '$(PRODUCT_NAME:rfc1034identifier)' &&\n item.buildSettings.PRODUCT_NAME\n ) {\n bundleIdentifierParts[\n bundleIdentifierParts.length - 1\n ] = item.buildSettings.PRODUCT_NAME.replace(/[^a-zA-Z0-9]/g, '-');\n }\n return bundleIdentifierParts.join('.');\n }\n }\n return null;\n}\n\n/**\n * Updates the bundle identifier for a given pbxproj\n *\n * @param {string} pbxprojPath Path to pbxproj file\n * @param {string} bundleIdentifier Bundle identifier to set in the pbxproj\n * @param {boolean} [updateProductName=true] Whether to update PRODUCT_NAME\n */\nfunction updateBundleIdentifierForPbxproj(\n pbxprojPath: string,\n bundleIdentifier: string,\n updateProductName: boolean = true\n): void {\n const project = xcode.project(pbxprojPath);\n project.parseSync();\n\n const [, nativeTarget] = findFirstNativeTarget(project);\n\n getBuildConfigurationForId(project, nativeTarget.buildConfigurationList).forEach(\n ([, item]: ConfigurationSectionEntry) => {\n if (item.buildSettings.PRODUCT_BUNDLE_IDENTIFIER === bundleIdentifier) {\n return;\n }\n\n item.buildSettings.PRODUCT_BUNDLE_IDENTIFIER = `\"${bundleIdentifier}\"`;\n\n if (updateProductName) {\n const productName = bundleIdentifier.split('.').pop();\n if (!productName?.includes('$')) {\n item.buildSettings.PRODUCT_NAME = productName;\n }\n }\n }\n );\n fs.writeFileSync(pbxprojPath, project.writeSync());\n}\n\n/**\n * Updates the bundle identifier for pbx projects inside the ios directory of the given project root\n *\n * @param {string} projectRoot Path to project root containing the ios directory\n * @param {string} bundleIdentifier Desired bundle identifier\n * @param {boolean} [updateProductName=true] Whether to update PRODUCT_NAME\n */\nfunction setBundleIdentifierForPbxproj(\n projectRoot: string,\n bundleIdentifier: string,\n updateProductName: boolean = true\n): void {\n // Get all pbx projects in the ${projectRoot}/ios directory\n let pbxprojPaths: string[] = [];\n try {\n pbxprojPaths = getAllPBXProjectPaths(projectRoot);\n } catch {}\n\n for (const pbxprojPath of pbxprojPaths) {\n updateBundleIdentifierForPbxproj(pbxprojPath, bundleIdentifier, updateProductName);\n }\n}\n\n/**\n * Reset bundle identifier field in Info.plist to use PRODUCT_BUNDLE_IDENTIFIER, as recommended by Apple.\n */\n\nconst defaultBundleId = '$(PRODUCT_BUNDLE_IDENTIFIER)';\n\nfunction resetAllPlistBundleIdentifiers(projectRoot: string): void {\n const infoPlistPaths = getAllInfoPlistPaths(projectRoot);\n\n for (const plistPath of infoPlistPaths) {\n resetPlistBundleIdentifier(plistPath);\n }\n}\n\nfunction resetPlistBundleIdentifier(plistPath: string): void {\n const rawPlist = fs.readFileSync(plistPath, 'utf8');\n const plistObject = plist.parse(rawPlist) as PlistObject;\n\n if (plistObject.CFBundleIdentifier) {\n if (plistObject.CFBundleIdentifier === defaultBundleId) return;\n\n // attempt to match default Info.plist format\n const format = { pretty: true, indent: `\\t` };\n\n const xml = plist.build(\n {\n ...plistObject,\n CFBundleIdentifier: defaultBundleId,\n },\n format\n );\n\n if (xml !== rawPlist) {\n fs.writeFileSync(plistPath, xml);\n }\n }\n}\n\nexport {\n getBundleIdentifier,\n setBundleIdentifier,\n getBundleIdentifierFromPbxproj,\n updateBundleIdentifierForPbxproj,\n setBundleIdentifierForPbxproj,\n resetAllPlistBundleIdentifiers,\n resetPlistBundleIdentifier,\n};\n"]}