@@ -198,25 +198,38 @@ export async function linkFlatFramework({
198198 */
199199export async function restoreFrameworkLinks ( frameworkPath : string ) {
200200 // Reconstruct missing symbolic links if needed
201- const versionAPath = path . join ( frameworkPath , "Versions" , "A" ) ;
202- const versionCurrentPath = path . join ( frameworkPath , "Versions" , "Current" ) ;
203- if ( fs . existsSync ( versionAPath ) && ! fs . existsSync ( versionCurrentPath ) ) {
201+ const versionsPath = path . join ( frameworkPath , "Versions" ) ;
202+ const versionCurrentPath = path . join ( versionsPath , "Current" ) ;
203+
204+ assert (
205+ fs . existsSync ( versionsPath ) ,
206+ `Expected "Versions" directory inside versioned framework '${ frameworkPath } '` ,
207+ ) ;
208+
209+ if ( ! fs . existsSync ( versionCurrentPath ) ) {
210+ const versionDirectoryEntries = await fs . promises . readdir ( versionsPath , {
211+ withFileTypes : true ,
212+ } ) ;
213+ const versionDirectoryPaths = versionDirectoryEntries
214+ . filter ( ( dirent ) => dirent . isDirectory ( ) )
215+ . map ( ( dirent ) => path . join ( dirent . parentPath , dirent . name ) ) ;
216+ assert . equal (
217+ versionDirectoryPaths . length ,
218+ 1 ,
219+ `Expected a single directory in ${ versionsPath } , found ${ JSON . stringify ( versionDirectoryPaths ) } ` ,
220+ ) ;
221+ const [ versionDirectoryPath ] = versionDirectoryPaths ;
204222 await fs . promises . symlink (
205- path . relative ( path . dirname ( versionCurrentPath ) , versionAPath ) ,
223+ path . relative ( path . dirname ( versionCurrentPath ) , versionDirectoryPath ) ,
206224 versionCurrentPath ,
207225 ) ;
208226 }
209227
210228 const { CFBundleExecutable } = await readFrameworkInfo (
211- path . join ( frameworkPath , "Versions" , "Current" , "Resources" , "Info.plist" ) ,
229+ path . join ( versionCurrentPath , "Resources" , "Info.plist" ) ,
212230 ) ;
213231
214- const libraryRealPath = path . join (
215- frameworkPath ,
216- "Versions" ,
217- "Current" ,
218- CFBundleExecutable ,
219- ) ;
232+ const libraryRealPath = path . join ( versionCurrentPath , CFBundleExecutable ) ;
220233 const libraryLinkPath = path . join ( frameworkPath , CFBundleExecutable ) ;
221234 // Reconstruct missing symbolic links if needed
222235 if ( fs . existsSync ( libraryRealPath ) && ! fs . existsSync ( libraryLinkPath ) ) {
0 commit comments