-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathvendor-keyring.mjs
More file actions
61 lines (55 loc) · 1.85 KB
/
vendor-keyring.mjs
File metadata and controls
61 lines (55 loc) · 1.85 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
/**
* Vendor @napi-rs/keyring into dist/node_modules/ for VSIX packaging.
*
* pnpm uses symlinks that vsce can't follow. This script resolves them and
* copies the JS wrapper plus macOS/Windows .node binaries into dist/, where
* Node's require() resolution finds them from dist/extension.js.
*/
import {
cpSync,
existsSync,
mkdirSync,
readdirSync,
realpathSync,
rmSync,
} from "node:fs";
import { join, resolve } from "node:path";
const keyringPkg = resolve("node_modules/@napi-rs/keyring");
const outputDir = resolve("dist/node_modules/@napi-rs/keyring");
if (!existsSync(keyringPkg)) {
console.error("@napi-rs/keyring not found — run pnpm install first");
process.exit(1);
}
// Copy the JS wrapper package (resolving pnpm symlinks)
const resolvedPkg = realpathSync(keyringPkg);
rmSync(outputDir, { recursive: true, force: true });
mkdirSync(outputDir, { recursive: true });
cpSync(resolvedPkg, outputDir, { recursive: true });
// Native binary packages live as siblings of the resolved keyring package in
// pnpm's content-addressable store (they aren't hoisted to node_modules).
const siblingsDir = resolve(resolvedPkg, "..");
const nativePackages = [
"keyring-darwin-arm64",
"keyring-darwin-x64",
"keyring-win32-arm64-msvc",
"keyring-win32-x64-msvc",
];
for (const pkg of nativePackages) {
const pkgDir = join(siblingsDir, pkg);
if (!existsSync(pkgDir)) {
console.error(
`Missing native package: ${pkg}\n` +
"Ensure supportedArchitectures in pnpm-workspace.yaml includes all target platforms.",
);
process.exit(1);
}
const nodeFile = readdirSync(pkgDir).find((f) => f.endsWith(".node"));
if (!nodeFile) {
console.error(`No .node binary found in ${pkg}`);
process.exit(1);
}
cpSync(join(pkgDir, nodeFile), join(outputDir, nodeFile));
}
console.log(
`Vendored @napi-rs/keyring with ${nativePackages.length} platform binaries into dist/`,
);