@@ -13,7 +13,7 @@ import {
1313} from "./link-modules.js" ;
1414
1515type UpdateInfoPlistOptions = {
16- filePath : string ;
16+ frameworkPath : string ;
1717 oldLibraryName : string ;
1818 newLibraryName : string ;
1919} ;
@@ -22,17 +22,37 @@ type UpdateInfoPlistOptions = {
2222 * Update the Info.plist file of an xcframework to use the new library name.
2323 */
2424export async function updateInfoPlist ( {
25- filePath ,
25+ frameworkPath ,
2626 oldLibraryName,
2727 newLibraryName,
2828} : UpdateInfoPlistOptions ) {
29- const infoPlistContents = await fs . promises . readFile ( filePath , "utf-8" ) ;
29+ // First, assume it is an "unversioned" framework that keeps its Info.plist in
30+ // the root. This is the convention for iOS, tvOS, and friends.
31+ let infoPlistPath = path . join ( frameworkPath , "Info.plist" ) ;
32+
33+ let infoPlistContents : string ;
34+ try {
35+ infoPlistContents = await fs . promises . readFile ( infoPlistPath , "utf-8" ) ;
36+ } catch ( error ) {
37+ if ( error instanceof Error && "code" in error && error . code === "ENOENT" ) {
38+ // Next, assume it is a "versioned" framework that keeps its Info.plist
39+ // under a subdirectory. This is the convention for macOS.
40+ infoPlistPath = path . join (
41+ frameworkPath ,
42+ "Versions/Current/Resources/Info.plist" ,
43+ ) ;
44+ infoPlistContents = await fs . promises . readFile ( infoPlistPath , "utf-8" ) ;
45+ }
46+
47+ throw error ;
48+ }
49+
3050 // TODO: Use a proper plist parser
3151 const updatedContents = infoPlistContents . replaceAll (
3252 oldLibraryName ,
3353 newLibraryName ,
3454 ) ;
35- await fs . promises . writeFile ( filePath , updatedContents , "utf-8" ) ;
55+ await fs . promises . writeFile ( infoPlistPath , updatedContents , "utf-8" ) ;
3656}
3757
3858export async function linkXcframework ( {
@@ -126,7 +146,7 @@ export async function linkXcframework({
126146 ) ;
127147 // Update the Info.plist file for the framework
128148 await updateInfoPlist ( {
129- filePath : path . join ( newFrameworkPath , "Info.plist" ) ,
149+ frameworkPath : newFrameworkPath ,
130150 oldLibraryName,
131151 newLibraryName,
132152 } ) ;
0 commit comments