-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-targets.js
47 lines (40 loc) · 1.29 KB
/
build-targets.js
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
44
45
46
47
'use strict'
function cleanTarget ({ runtime, abi, target }) {
return { runtime, abi, target }
}
function buildTargets (currentNode, supportedTargets, pkg) {
const nodeTarget = {
runtime: 'node',
abi: currentNode.modules,
target: currentNode.node
}
// Electron versions with the same ABI as current Node ABI
const electronTargets = supportedTargets
.filter(target => target.runtime === 'electron' && target.abi === currentNode.modules)
.map(cleanTarget)
// Oddball Electron versions, where no version of Node has the same ABI
const nodeAbis = supportedTargets
.filter(target => target.runtime === 'node')
.map(target => target.abi)
const oddballElectronTargets = supportedTargets
.filter(target => target.runtime === 'electron' && target.abi >= currentNode.modules)
.filter(target => !nodeAbis.includes(target.abi))
.map(cleanTarget)
// N-API versions, requires napi_versions to be set
const napiTargets = []
if (pkg.binary && pkg.binary.napi_versions) {
pkg.binary.napi_versions.forEach(napiVersion => {
napiTargets.push({
runtime: 'napi',
target: String(napiVersion)
})
})
}
return [
nodeTarget,
...electronTargets,
...oddballElectronTargets,
...napiTargets
]
}
module.exports = buildTargets