@@ -3,7 +3,7 @@ import fs from "fs"
3
3
4
4
function errStr ( error : unknown ) {
5
5
return error instanceof Error
6
- ? `${ error . name } : ${ error . message } \n ${ error . stack } `
6
+ ? `${ error . name } : ${ error . stack } `
7
7
: String ( error )
8
8
}
9
9
@@ -23,36 +23,43 @@ function findAddon(): any | undefined {
23
23
) as Record < string , string >
24
24
25
25
// compatible addons (abi -> addon path)
26
- const compatibleAddons : Record < string , string > = { }
26
+ const compatibleAddons : Map < BuildConfiguration , string > = new Map ( )
27
+
28
+ const libc = detectLibc ( )
27
29
28
30
const configs = Object . keys ( manifest )
29
31
for ( const configStr of configs ) {
30
32
const config = JSON . parse ( configStr ) as BuildConfiguration
31
33
32
34
// check if the config is compatible with the current runtime
33
- if ( config . os !== process . platform || config . arch !== process . arch ) {
34
- continue
35
- }
36
- const libc = detectLibc ( )
37
- if ( config . libc !== libc ) {
35
+ if (
36
+ config . os !== process . platform ||
37
+ config . arch !== process . arch ||
38
+ config . libc !== libc
39
+ ) {
38
40
continue
39
41
}
40
42
41
43
const addonRelativePath = manifest [ configStr ]
42
- compatibleAddons [ config . abi ?? 0 ] = path . resolve (
43
- buildDir ,
44
- addonRelativePath ,
44
+ compatibleAddons . set ( config , path . resolve ( buildDir , addonRelativePath ) )
45
+ }
46
+ if ( compatibleAddons . size === 0 ) {
47
+ throw new Error (
48
+ `No compatible zeromq.js addon found for ${ process . platform } ${ process . arch } ${ libc } . The candidates were:\n${ configs . join (
49
+ "\n" ,
50
+ ) } `,
45
51
)
46
52
}
47
53
48
54
// sort the compatible abis in descending order
49
- const compatibleAbis = Object . keys ( compatibleAddons ) . sort ( ( a , b ) => {
50
- return Number . parseInt ( b , 10 ) - Number . parseInt ( a , 10 )
51
- } )
55
+ const compatibleAddonsSorted = [ ...compatibleAddons . entries ( ) ] . sort (
56
+ ( [ c1 , _p1 ] , [ c2 , _p2 ] ) => {
57
+ return ( c2 . abi ?? 0 ) - ( c1 . abi ?? 0 )
58
+ } ,
59
+ )
52
60
53
61
// try each available addon ABI
54
- for ( const abi of compatibleAbis ) {
55
- const addonPath = compatibleAddons [ abi ]
62
+ for ( const [ _config , addonPath ] of compatibleAddonsSorted ) {
56
63
try {
57
64
addon = require ( addonPath )
58
65
break
0 commit comments