Skip to content

Commit 012d85f

Browse files
committed
Restore weak-node-api symlinks
1 parent 46e731b commit 012d85f

File tree

2 files changed

+68
-22
lines changed

2 files changed

+68
-22
lines changed

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

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,11 @@ export async function linkFlatFramework({
192192
}
193193
}
194194

195-
export async function linkVersionedFramework({
196-
frameworkPath,
197-
newLibraryName,
198-
}: LinkFrameworkOptions) {
199-
assert.equal(
200-
process.platform,
201-
"darwin",
202-
"Linking Apple addons are only supported on macOS",
203-
);
195+
/**
196+
* NPM packages aren't preserving internal symlinks inside versioned frameworks.
197+
* This function attempts to restore those.
198+
*/
199+
export async function restoreFrameworkLinks(frameworkPath: string) {
204200
// Reconstruct missing symbolic links if needed
205201
const versionAPath = path.join(frameworkPath, "Versions", "A");
206202
const versionCurrentPath = path.join(frameworkPath, "Versions", "Current");
@@ -210,31 +206,47 @@ export async function linkVersionedFramework({
210206
versionCurrentPath,
211207
);
212208
}
213-
const frameworkInfoPath = path.join(
214-
frameworkPath,
215-
"Versions",
216-
"Current",
217-
"Resources",
218-
"Info.plist",
209+
210+
const { CFBundleExecutable } = await readFrameworkInfo(
211+
path.join(frameworkPath, "Versions", "Current", "Resources", "Info.plist"),
219212
);
220-
const frameworkInfo = await readFrameworkInfo(frameworkInfoPath);
213+
221214
const libraryRealPath = path.join(
222215
frameworkPath,
223216
"Versions",
224217
"Current",
225-
frameworkInfo.CFBundleExecutable,
226-
);
227-
const libraryLinkPath = path.join(
228-
frameworkPath,
229-
frameworkInfo.CFBundleExecutable,
218+
CFBundleExecutable,
230219
);
220+
const libraryLinkPath = path.join(frameworkPath, CFBundleExecutable);
231221
// Reconstruct missing symbolic links if needed
232222
if (fs.existsSync(libraryRealPath) && !fs.existsSync(libraryLinkPath)) {
233223
await fs.promises.symlink(
234224
path.relative(path.dirname(libraryLinkPath), libraryRealPath),
235225
libraryLinkPath,
236226
);
237227
}
228+
}
229+
230+
export async function linkVersionedFramework({
231+
frameworkPath,
232+
newLibraryName,
233+
}: LinkFrameworkOptions) {
234+
assert.equal(
235+
process.platform,
236+
"darwin",
237+
"Linking Apple addons are only supported on macOS",
238+
);
239+
240+
await restoreFrameworkLinks(frameworkPath);
241+
242+
const frameworkInfoPath = path.join(
243+
frameworkPath,
244+
"Versions",
245+
"Current",
246+
"Resources",
247+
"Info.plist",
248+
);
249+
const frameworkInfo = await readFrameworkInfo(frameworkInfoPath);
238250
// Update install name
239251
await spawn(
240252
"install_name_tool",

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from "node:assert/strict";
22
import path from "node:path";
33
import { EventEmitter } from "node:stream";
4+
import fs from "node:fs";
45

56
import {
67
Command,
@@ -26,8 +27,9 @@ import {
2627
import { command as vendorHermes } from "./hermes";
2728
import { packageNameOption, pathSuffixOption } from "./options";
2829
import { linkModules, pruneLinkedModules, ModuleLinker } from "./link-modules";
29-
import { linkXcframework } from "./apple";
30+
import { linkXcframework, restoreFrameworkLinks } from "./apple";
3031
import { linkAndroidDir } from "./android";
32+
import { weakNodeApiPath } from "../weak-node-api";
3133

3234
// We're attaching a lot of listeners when spawning in parallel
3335
EventEmitter.defaultMaxListeners = 100;
@@ -169,6 +171,38 @@ program
169171
await pruneLinkedModules(platform, modules);
170172
}
171173
}
174+
175+
if (apple) {
176+
await oraPromise(
177+
async () => {
178+
const xcframeworkPath = path.join(
179+
weakNodeApiPath,
180+
"weak-node-api.xcframework",
181+
);
182+
await Promise.all(
183+
[
184+
path.join(xcframeworkPath, "macos-x86_64"),
185+
path.join(xcframeworkPath, "macos-arm64"),
186+
path.join(xcframeworkPath, "macos-arm64_x86_64"),
187+
].map(async (slicePath) => {
188+
const frameworkPath = path.join(
189+
slicePath,
190+
"weak-node-api.framework",
191+
);
192+
if (fs.existsSync(frameworkPath)) {
193+
await restoreFrameworkLinks(frameworkPath);
194+
}
195+
}),
196+
);
197+
},
198+
{
199+
text: "Restoring weak-node-api symlinks",
200+
successText: "Restored weak-node-api symlinks",
201+
failText: (error) =>
202+
`Failed to restore weak-node-api symlinks: ${error.message}`,
203+
},
204+
);
205+
}
172206
},
173207
),
174208
);

0 commit comments

Comments
 (0)