-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrestore-xcframework-symlinks.ts
More file actions
67 lines (59 loc) · 1.82 KB
/
restore-xcframework-symlinks.ts
File metadata and controls
67 lines (59 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { applePrebuildPath } from "./weak-node-api.js";
async function restoreSymlink(target: string, path: string) {
if (!fs.existsSync(path)) {
await fs.promises.symlink(target, path);
}
}
async function guessCurrentFrameworkVersion(frameworkPath: string) {
const versionsPath = path.join(frameworkPath, "Versions");
assert(fs.existsSync(versionsPath));
const versionDirectoryEntries = await fs.promises.readdir(versionsPath, {
withFileTypes: true,
});
const versions = versionDirectoryEntries
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
assert.equal(
versions.length,
1,
`Expected exactly one directory in ${versionsPath}, found ${JSON.stringify(versions)}`,
);
const [version] = versions;
return version;
}
async function restoreVersionedFrameworkSymlinks(frameworkPath: string) {
const currentVersionName = await guessCurrentFrameworkVersion(frameworkPath);
await restoreSymlink(
currentVersionName,
path.join(frameworkPath, "Versions", "Current"),
);
await restoreSymlink(
"Versions/Current/weak-node-api",
path.join(frameworkPath, "weak-node-api"),
);
await restoreSymlink(
"Versions/Current/Resources",
path.join(frameworkPath, "Resources"),
);
await restoreSymlink(
"Versions/Current/Headers",
path.join(frameworkPath, "Headers"),
);
}
if (process.platform === "darwin") {
assert(
fs.existsSync(applePrebuildPath),
`Expected an Xcframework at ${applePrebuildPath}`,
);
const macosFrameworkPath = path.join(
applePrebuildPath,
"macos-arm64_x86_64",
"weak-node-api.framework",
);
if (fs.existsSync(macosFrameworkPath)) {
await restoreVersionedFrameworkSymlinks(macosFrameworkPath);
}
}