@@ -12,6 +12,27 @@ import {
1212 LinkModuleResult ,
1313} from "./link-modules.js" ;
1414
15+ /**
16+ * Resolves the Info.plist file within a framework and reads its contents.
17+ */
18+ export async function readInfoPlist ( frameworkPath : string ) {
19+ // First, assume it is an "unversioned" framework that keeps its Info.plist in
20+ // the root. This is the convention for iOS, tvOS, and friends.
21+ let infoPlistPath = path . join ( frameworkPath , "Info.plist" ) ;
22+
23+ if ( ! fs . existsSync ( infoPlistPath ) ) {
24+ // Next, assume it is a "versioned" framework that keeps its Info.plist
25+ // under a subdirectory. This is the convention for macOS.
26+ infoPlistPath = path . join (
27+ frameworkPath ,
28+ "Versions/Current/Resources/Info.plist" ,
29+ ) ;
30+ }
31+
32+ const contents = await fs . promises . readFile ( infoPlistPath , "utf-8" ) ;
33+ return { infoPlistPath, contents } ;
34+ }
35+
1536type UpdateInfoPlistOptions = {
1637 frameworkPath : string ;
1738 oldLibraryName : string ;
@@ -26,32 +47,10 @@ export async function updateInfoPlist({
2647 oldLibraryName,
2748 newLibraryName,
2849} : UpdateInfoPlistOptions ) {
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- } else {
46- throw error ;
47- }
48- }
50+ const { infoPlistPath, contents } = await readInfoPlist ( frameworkPath ) ;
4951
5052 // TODO: Use a proper plist parser
51- const updatedContents = infoPlistContents . replaceAll (
52- oldLibraryName ,
53- newLibraryName ,
54- ) ;
53+ const updatedContents = contents . replaceAll ( oldLibraryName , newLibraryName ) ;
5554 await fs . promises . writeFile ( infoPlistPath , updatedContents , "utf-8" ) ;
5655}
5756
0 commit comments