@@ -64,73 +64,73 @@ export async function linkXcframework({
6464 await fs . promises . rm ( outputPath , { recursive : true , force : true } ) ;
6565 await fs . promises . cp ( modulePath , tempPath , { recursive : true } ) ;
6666
67- const frameworkPaths = await Promise . all (
68- fs
69- . readdirSync ( tempPath , {
70- withFileTypes : true ,
71- } )
67+ // Following extracted function mimics `glob("*/*.framework/")`
68+ function globFrameworkDirs < T > (
69+ startPath : string ,
70+ fn : ( parentPath : string , name : string ) => Promise < T >
71+ ) {
72+ return fs
73+ . readdirSync ( startPath , { withFileTypes : true } )
7274 . filter ( ( tripletEntry ) => tripletEntry . isDirectory ( ) )
7375 . flatMap ( ( tripletEntry ) => {
74- const tripletPath = path . join ( tempPath , tripletEntry . name ) ;
76+ const tripletPath = path . join ( startPath , tripletEntry . name ) ;
7577 return fs
76- . readdirSync ( tripletPath , {
77- withFileTypes : true ,
78- } )
78+ . readdirSync ( tripletPath , { withFileTypes : true } )
7979 . filter (
8080 ( frameworkEntry ) =>
8181 frameworkEntry . isDirectory ( ) &&
8282 path . extname ( frameworkEntry . name ) === ".framework"
8383 )
84- . flatMap ( async ( frameworkEntry ) => {
85- const frameworkPath = path . join ( tripletPath , frameworkEntry . name ) ;
86- const oldLibraryName = path . basename (
87- frameworkEntry . name ,
88- ".framework"
89- ) ;
90- const oldLibraryPath = path . join ( frameworkPath , oldLibraryName ) ;
91- const newFrameworkPath = path . join (
92- tripletPath ,
93- ` ${ newLibraryName } .framework`
94- ) ;
95- const newLibraryPath = path . join (
96- newFrameworkPath ,
97- newLibraryName
98- ) ;
99- assert (
100- fs . existsSync ( oldLibraryPath ) ,
101- `Expected a library at ' ${ oldLibraryPath } '`
102- ) ;
103- // Rename the library
104- await fs . promises . rename (
105- oldLibraryPath ,
106- // Cannot use newLibraryPath here, because the framework isn't renamed yet
107- path . join ( frameworkPath , newLibraryName )
108- ) ;
109- // Rename the framework
110- await fs . promises . rename ( frameworkPath , newFrameworkPath ) ;
111- // Expect the library in the new location
112- assert ( fs . existsSync ( newLibraryPath ) ) ;
113- // Update the binary
114- await spawn (
115- "install_name_tool" ,
116- [
117- "-id" ,
118- `@rpath/ ${ newLibraryName } .framework/ ${ newLibraryName } ` ,
119- newLibraryPath ,
120- ] ,
121- {
122- outputMode : "buffered" ,
123- }
124- ) ;
125- // Update the Info.plist file for the framework
126- await updateInfoPlist ( {
127- filePath : path . join ( newFrameworkPath , "Info.plist" ) ,
128- oldLibraryName ,
129- newLibraryName ,
130- } ) ;
131- return newFrameworkPath ;
132- } ) ;
133- } )
84+ . flatMap ( async ( frameworkEntry ) =>
85+ await fn ( tripletPath , frameworkEntry . name )
86+ ) ;
87+ } ) ;
88+ }
89+
90+ const frameworkPaths = await Promise . all (
91+ globFrameworkDirs ( tempPath , async ( tripletPath , frameworkEntryName ) => {
92+ const frameworkPath = path . join ( tripletPath , frameworkEntryName ) ;
93+ const oldLibraryName = path . basename ( frameworkEntryName , " .framework" ) ;
94+ const oldLibraryPath = path . join ( frameworkPath , oldLibraryName ) ;
95+ const newFrameworkPath = path . join (
96+ tripletPath ,
97+ ` ${ newLibraryName } .framework`
98+ ) ;
99+ const newLibraryPath = path . join ( newFrameworkPath , newLibraryName ) ;
100+ assert (
101+ fs . existsSync ( oldLibraryPath ) ,
102+ `Expected a library at ' ${ oldLibraryPath } '`
103+ ) ;
104+ // Rename the library
105+ await fs . promises . rename (
106+ oldLibraryPath ,
107+ // Cannot use newLibraryPath here, because the framework isn't renamed yet
108+ path . join ( frameworkPath , newLibraryName )
109+ ) ;
110+ // Rename the framework
111+ await fs . promises . rename ( frameworkPath , newFrameworkPath ) ;
112+ // Expect the library in the new location
113+ assert ( fs . existsSync ( newLibraryPath ) ) ;
114+ // Update the binary
115+ await spawn (
116+ "install_name_tool" ,
117+ [
118+ "-id" ,
119+ `@rpath/ ${ newLibraryName } .framework/ ${ newLibraryName } ` ,
120+ newLibraryPath ,
121+ ] ,
122+ {
123+ outputMode : "buffered" ,
124+ }
125+ ) ;
126+ // Update the Info.plist file for the framework
127+ await updateInfoPlist ( {
128+ filePath : path . join ( newFrameworkPath , "Info.plist" ) ,
129+ oldLibraryName ,
130+ newLibraryName ,
131+ } ) ;
132+ return newFrameworkPath ;
133+ } )
134134 ) ;
135135
136136 // Create a new xcframework from the renamed frameworks
0 commit comments