Skip to content

Commit 72a7c1a

Browse files
committed
fix: sort the addon paths via a map
1 parent c8e6259 commit 72a7c1a

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

lib/load-addon.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/load-addon.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/load-addon.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function findAddon(): any | undefined {
2323
) as Record<string, string>
2424

2525
// compatible addons (abi -> addon path)
26-
const compatibleAddons: Record<string, string> = {}
26+
const compatibleAddons: Map<BuildConfiguration, string> = new Map()
2727

2828
const configs = Object.keys(manifest)
2929
for (const configStr of configs) {
@@ -39,20 +39,18 @@ function findAddon(): any | undefined {
3939
}
4040

4141
const addonRelativePath = manifest[configStr]
42-
compatibleAddons[config.abi ?? 0] = path.resolve(
43-
buildDir,
44-
addonRelativePath,
45-
)
42+
compatibleAddons.set(config, path.resolve(buildDir, addonRelativePath))
4643
}
4744

4845
// 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-
})
46+
const compatibleAddonsSorted = [...compatibleAddons.entries()].sort(
47+
([c1, _p1], [c2, _p2]) => {
48+
return (c2.abi ?? 0) - (c1.abi ?? 0)
49+
},
50+
)
5251

5352
// try each available addon ABI
54-
for (const abi of compatibleAbis) {
55-
const addonPath = compatibleAddons[abi]
53+
for (const [_config, addonPath] of compatibleAddonsSorted) {
5654
try {
5755
addon = require(addonPath)
5856
break

0 commit comments

Comments
 (0)