Skip to content

Commit f174f19

Browse files
Refactor helper functions to use object arguments instead of positional strings
Co-authored-by: Kræn Hansen <mail@kraenhansen.dk>
1 parent c75f551 commit f174f19

File tree

1 file changed

+55
-37
lines changed
  • packages/host/src/node/prebuilds

1 file changed

+55
-37
lines changed

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

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,54 @@ export function escapeBundleIdentifier(input: string) {
2323
}
2424

2525
/** Serialize a plist object and write it to the given path. */
26-
async function writeInfoPlist(
27-
infoPlistPath: string,
28-
plistDict: Record<string, unknown>,
29-
) {
26+
async function writeInfoPlist({
27+
path: infoPlistPath,
28+
plist: plistDict,
29+
}: {
30+
path: string;
31+
plist: Record<string, unknown>;
32+
}) {
3033
await fs.promises.writeFile(infoPlistPath, plist.build(plistDict), "utf8");
3134
}
3235

3336
/** Build and write the framework Info.plist to the given path. */
34-
async function writeFrameworkInfoPlist(
35-
infoPlistPath: string,
36-
libraryName: string,
37-
bundleIdentifier?: string,
38-
) {
39-
await writeInfoPlist(infoPlistPath, {
40-
CFBundleDevelopmentRegion: "en",
41-
CFBundleExecutable: libraryName,
42-
CFBundleIdentifier: escapeBundleIdentifier(
43-
bundleIdentifier ?? `com.callstackincubator.node-api.${libraryName}`,
44-
),
45-
CFBundleInfoDictionaryVersion: "6.0",
46-
CFBundleName: libraryName,
47-
CFBundlePackageType: "FMWK",
48-
CFBundleShortVersionString: "1.0",
49-
CFBundleVersion: "1",
50-
NSPrincipalClass: "",
37+
async function writeFrameworkInfoPlist({
38+
path: infoPlistPath,
39+
libraryName,
40+
bundleIdentifier,
41+
}: {
42+
path: string;
43+
libraryName: string;
44+
bundleIdentifier?: string;
45+
}) {
46+
await writeInfoPlist({
47+
path: infoPlistPath,
48+
plist: {
49+
CFBundleDevelopmentRegion: "en",
50+
CFBundleExecutable: libraryName,
51+
CFBundleIdentifier: escapeBundleIdentifier(
52+
bundleIdentifier ?? `com.callstackincubator.node-api.${libraryName}`,
53+
),
54+
CFBundleInfoDictionaryVersion: "6.0",
55+
CFBundleName: libraryName,
56+
CFBundlePackageType: "FMWK",
57+
CFBundleShortVersionString: "1.0",
58+
CFBundleVersion: "1",
59+
NSPrincipalClass: "",
60+
},
5161
});
5262
}
5363

5464
/** Update the library binary’s install name so it resolves correctly at load time. */
55-
async function updateLibraryInstallName(
56-
binaryPath: string,
57-
libraryName: string,
58-
cwd: string,
59-
) {
65+
async function updateLibraryInstallName({
66+
binaryPath,
67+
libraryName,
68+
cwd,
69+
}: {
70+
binaryPath: string;
71+
libraryName: string;
72+
cwd: string;
73+
}) {
6074
await spawn(
6175
"install_name_tool",
6276
["-id", `@rpath/${libraryName}.framework/${libraryName}`, binaryPath],
@@ -87,15 +101,19 @@ async function createFlatFramework({
87101
}): Promise<string> {
88102
await fs.promises.mkdir(frameworkPath);
89103
await fs.promises.mkdir(path.join(frameworkPath, "Headers"));
90-
await writeFrameworkInfoPlist(
91-
path.join(frameworkPath, "Info.plist"),
104+
await writeFrameworkInfoPlist({
105+
path: path.join(frameworkPath, "Info.plist"),
92106
libraryName,
93107
bundleIdentifier,
94-
);
108+
});
95109
const newLibraryPath = path.join(frameworkPath, libraryName);
96110
// TODO: Consider copying the library instead of renaming it
97111
await fs.promises.rename(libraryPath, newLibraryPath);
98-
await updateLibraryInstallName(libraryName, libraryName, frameworkPath);
112+
await updateLibraryInstallName({
113+
binaryPath: libraryName,
114+
libraryName,
115+
cwd: frameworkPath,
116+
});
99117
return frameworkPath;
100118
}
101119

@@ -135,19 +153,19 @@ async function createVersionedFramework({
135153
await fs.promises.mkdir(versionResourcesDir, { recursive: true });
136154
await fs.promises.mkdir(versionHeadersDir, { recursive: true });
137155

138-
await writeFrameworkInfoPlist(
139-
path.join(versionResourcesDir, "Info.plist"),
156+
await writeFrameworkInfoPlist({
157+
path: path.join(versionResourcesDir, "Info.plist"),
140158
libraryName,
141159
bundleIdentifier,
142-
);
160+
});
143161

144162
const versionBinaryPath = path.join(versionDir, libraryName);
145163
await fs.promises.rename(libraryPath, versionBinaryPath);
146-
await updateLibraryInstallName(
147-
path.join("Versions", VERSIONED_FRAMEWORK_VERSION, libraryName),
164+
await updateLibraryInstallName({
165+
binaryPath: path.join("Versions", VERSIONED_FRAMEWORK_VERSION, libraryName),
148166
libraryName,
149-
frameworkPath,
150-
);
167+
cwd: frameworkPath,
168+
});
151169

152170
const currentLink = path.join(versionsDir, "Current");
153171
await fs.promises.symlink(VERSIONED_FRAMEWORK_VERSION, currentLink);

0 commit comments

Comments
 (0)