@@ -6,13 +6,56 @@ let nativeBinding: {
66 getProfiles : ( ) => string [ ] ;
77} ;
88
9+ function loadNativeBinding ( ) {
10+ const platform = process . platform ;
11+ const arch = process . arch ;
12+
13+ // Map Node.js platform/arch to napi binary naming convention
14+ const platformArchMap : Record < string , Record < string , string > > = {
15+ darwin : {
16+ x64 : 'darwin-x64' ,
17+ arm64 : 'darwin-arm64' ,
18+ } ,
19+ linux : {
20+ x64 : 'linux-x64' ,
21+ arm64 : 'linux-arm64' ,
22+ } ,
23+ win32 : {
24+ x64 : 'win32-x64' ,
25+ } ,
26+ } ;
27+
28+ const platformArch = platformArchMap [ platform ] ?. [ arch ] ;
29+ if ( ! platformArch ) {
30+ throw new Error (
31+ `Unsupported platform: ${ platform } -${ arch } . ` +
32+ `Supported platforms: darwin-x64, darwin-arm64, linux-x64, linux-arm64, win32-x64`
33+ ) ;
34+ }
35+
36+ // Try to load platform-specific binary (napi naming convention)
37+ const binaryName = `index.${ platformArch } .node` ;
38+
39+ try {
40+ return require ( `../rust/${ binaryName } ` ) ;
41+ } catch ( e1 ) {
42+ // Fallback to index.node (for local development)
43+ try {
44+ return require ( '../rust/index.node' ) ;
45+ } catch ( e2 ) {
46+ throw new Error (
47+ `Failed to load native module for ${ platform } -${ arch } . ` +
48+ `Tried: ../rust/${ binaryName } and ../rust/index.node. ` +
49+ `Make sure the package is installed correctly and the native module is built for your platform.`
50+ ) ;
51+ }
52+ }
53+ }
54+
955try {
10- nativeBinding = require ( '../rust/index.node' ) ;
56+ nativeBinding = loadNativeBinding ( ) ;
1157} catch ( error ) {
12- throw new Error (
13- `Failed to load native module: ${ error } . ` +
14- `Make sure the package is installed correctly and the native module is built for your platform (${ process . platform } -${ process . arch } ).`
15- ) ;
58+ throw error ;
1659}
1760
1861/**
0 commit comments