Skip to content

Commit f9671b0

Browse files
committed
rethrow with context
1 parent 6442d54 commit f9671b0

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

packages/host/src/node/cli/apple.ts

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,62 @@ import {
1212
LinkModuleResult,
1313
} from "./link-modules.js";
1414

15+
function determineInfoPlistPath(frameworkPath: string) {
16+
const checkedPaths = new Array<string>();
17+
18+
// First, assume it is an "unversioned" framework that keeps its Info.plist in
19+
// the root. This is the convention for iOS, tvOS, and friends.
20+
let infoPlistPath = path.join(frameworkPath, "Info.plist");
21+
22+
if (fs.existsSync(infoPlistPath)) {
23+
return infoPlistPath;
24+
}
25+
checkedPaths.push(infoPlistPath);
26+
27+
// Next, assume it is a "versioned" framework that keeps its Info.plist
28+
// under a subdirectory. This is the convention for macOS.
29+
infoPlistPath = path.join(
30+
frameworkPath,
31+
"Versions/Current/Resources/Info.plist",
32+
);
33+
34+
if (fs.existsSync(infoPlistPath)) {
35+
return infoPlistPath;
36+
}
37+
checkedPaths.push(infoPlistPath);
38+
39+
throw new Error(
40+
[
41+
`Unable to locate an Info.plist file within framework. Checked the following paths:`,
42+
...checkedPaths.map((checkedPath) => `- ${checkedPath}`),
43+
].join("\n"),
44+
);
45+
}
46+
1547
/**
1648
* Resolves the Info.plist file within a framework and reads its contents.
1749
*/
1850
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");
51+
let infoPlistPath: string;
52+
try {
53+
infoPlistPath = determineInfoPlistPath(frameworkPath);
54+
} catch (cause) {
55+
throw new Error(
56+
`Unable to read Info.plist for framework at path "${frameworkPath}", as an Info.plist file couldn't be found.`,
57+
{ cause },
58+
);
59+
}
2260

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",
61+
let contents: string;
62+
try {
63+
contents = await fs.promises.readFile(infoPlistPath, "utf-8");
64+
} catch (cause) {
65+
throw new Error(
66+
`Unable to read Info.plist for framework at path "${frameworkPath}", due to a file system error.`,
67+
{ cause },
2968
);
3069
}
3170

32-
const contents = await fs.promises.readFile(infoPlistPath, "utf-8");
3371
return { infoPlistPath, contents };
3472
}
3573

0 commit comments

Comments
 (0)