Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions packages/host/src/node/cli/apple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "./link-modules.js";

type UpdateInfoPlistOptions = {
filePath: string;
frameworkPath: string;
oldLibraryName: string;
newLibraryName: string;
};
Expand All @@ -22,17 +22,37 @@ type UpdateInfoPlistOptions = {
* Update the Info.plist file of an xcframework to use the new library name.
*/
export async function updateInfoPlist({
filePath,
frameworkPath,
oldLibraryName,
newLibraryName,
}: UpdateInfoPlistOptions) {
const infoPlistContents = await fs.promises.readFile(filePath, "utf-8");
// First, assume it is an "unversioned" framework that keeps its Info.plist in
// the root. This is the convention for iOS, tvOS, and friends.
let infoPlistPath = path.join(frameworkPath, "Info.plist");

let infoPlistContents: string;
try {
infoPlistContents = await fs.promises.readFile(infoPlistPath, "utf-8");
} catch (error) {
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
// Next, assume it is a "versioned" framework that keeps its Info.plist
// under a subdirectory. This is the convention for macOS.
infoPlistPath = path.join(
frameworkPath,
"Versions/Current/Resources/Info.plist",
);
infoPlistContents = await fs.promises.readFile(infoPlistPath, "utf-8");
} else {
throw error;
}
}

// TODO: Use a proper plist parser
const updatedContents = infoPlistContents.replaceAll(
oldLibraryName,
newLibraryName,
);
await fs.promises.writeFile(filePath, updatedContents, "utf-8");
await fs.promises.writeFile(infoPlistPath, updatedContents, "utf-8");
}

export async function linkXcframework({
Expand Down Expand Up @@ -126,7 +146,7 @@ export async function linkXcframework({
);
// Update the Info.plist file for the framework
await updateInfoPlist({
filePath: path.join(newFrameworkPath, "Info.plist"),
frameworkPath: newFrameworkPath,
oldLibraryName,
newLibraryName,
});
Expand Down
Loading