-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (37 loc) · 1.28 KB
/
index.js
File metadata and controls
43 lines (37 loc) · 1.28 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
const { existsSync } = require("fs");
const { join } = require("path");
const { platform, arch } = process;
let nativeBinding = null;
function getPlatformSpecificBinary() {
// Map platform and architecture to binary name
if (platform === "linux") {
if (arch === "x64") {
return "node-enigo-linux-x64.node";
} else if (arch === "arm64") {
return "node-enigo-linux-arm64.node";
}
} else if (platform === "darwin") {
if (arch === "arm64") {
return "node-enigo-macos-arm64.node";
}
}
// Instead of falling back to a default binary, throw an error for unsupported platforms
throw new Error(
`Unsupported platform or architecture: ${platform}-${arch}. Supported combinations are: linux-x64, linux-arm64, darwin-arm64`
);
}
try {
// Try to load the platform-specific binary
const platformSpecificPath = join(__dirname, getPlatformSpecificBinary());
if (existsSync(platformSpecificPath)) {
nativeBinding = require(platformSpecificPath);
} else {
throw new Error(`Native binding not found at ${platformSpecificPath}`);
}
} catch (error) {
throw new Error(
`Failed to load native binding: ${error.message}. Platform: ${platform}, Architecture: ${arch}`
);
}
// Export the native binding directly
module.exports = nativeBinding;