Skip to content

Commit b3eae41

Browse files
committed
Implement native module loading based on platform and architecture; add error handling for unsupported combinations.
1 parent 69fd4b2 commit b3eae41

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
const native = require('node-gyp-build')(__dirname);
1+
function loadNative() {
2+
const platform = process.platform;
3+
const arch = process.arch;
4+
5+
if (platform === 'darwin' && arch === 'arm64') {
6+
return require('./prebuilds/darwin-arm64/node-hdiffpatch.node');
7+
}
8+
if (platform === 'linux' && arch === 'x64') {
9+
return require('./prebuilds/linux-x64/node-hdiffpatch.node');
10+
}
11+
if (platform === 'linux' && arch === 'arm64') {
12+
return require('./prebuilds/linux-arm64/node-hdiffpatch.node');
13+
}
14+
15+
const combo = `${platform}-${arch}`;
16+
throw new Error(
17+
`Unsupported platform/arch: ${combo}. ` +
18+
'No prebuilt binary is available for this platform.'
19+
);
20+
}
21+
22+
const native = loadNative();
223

324
exports.native = native;
425

0 commit comments

Comments
 (0)