1 | var semver = require('semver')
|
2 |
|
3 | function getNextTarget (runtime, targets) {
|
4 | if (targets == null) targets = allTargets
|
5 | var latest = targets.filter(function (t) { return t.runtime === runtime }).slice(-1)[0]
|
6 | var increment = runtime === 'electron' ? 'minor' : 'major'
|
7 | return semver.inc(latest.target, increment)
|
8 | }
|
9 |
|
10 | function getAbi (target, runtime) {
|
11 | if (target === String(Number(target))) return target
|
12 | if (target) target = target.replace(/^v/, '')
|
13 | if (!runtime) runtime = 'node'
|
14 |
|
15 | if (runtime === 'node') {
|
16 | if (!target) return process.versions.modules
|
17 | if (target === process.versions.node) return process.versions.modules
|
18 | }
|
19 |
|
20 | var abi
|
21 |
|
22 | for (var i = 0; i < allTargets.length; i++) {
|
23 | var t = allTargets[i]
|
24 | if (t.runtime !== runtime) continue
|
25 | if (semver.lte(t.target, target)) abi = t.abi
|
26 | else break
|
27 | }
|
28 |
|
29 | if (abi && semver.lt(target, getNextTarget(runtime))) return abi
|
30 | throw new Error('Could not detect abi for version ' + target + ' and runtime ' + runtime + '. Updating "node-abi" might help solve this issue if it is a new release of ' + runtime)
|
31 | }
|
32 |
|
33 | function getTarget (abi, runtime) {
|
34 | if (abi && abi !== String(Number(abi))) return abi
|
35 | if (!runtime) runtime = 'node'
|
36 |
|
37 | if (runtime === 'node' && !abi) return process.versions.node
|
38 |
|
39 | var match = allTargets
|
40 | .filter(function (t) {
|
41 | return t.abi === abi && t.runtime === runtime
|
42 | })
|
43 | .map(function (t) {
|
44 | return t.target
|
45 | })
|
46 | if (match.length) return match[0]
|
47 |
|
48 | throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime)
|
49 | }
|
50 |
|
51 | var supportedTargets = [
|
52 | {runtime: 'node', target: '5.0.0', abi: '47', lts: false},
|
53 | {runtime: 'node', target: '6.0.0', abi: '48', lts: false},
|
54 | {runtime: 'node', target: '7.0.0', abi: '51', lts: false},
|
55 | {runtime: 'node', target: '8.0.0', abi: '57', lts: new Date() < new Date(2019, 4, 31)},
|
56 | {runtime: 'node', target: '9.0.0', abi: '59', lts: false},
|
57 | {runtime: 'node', target: '10.0.0', abi: '64', lts: new Date(2018, 10, 1) < new Date() < new Date(2020, 4, 31)},
|
58 | {runtime: 'node', target: '11.0.0', abi: '67', lts: false},
|
59 | {runtime: 'electron', target: '0.36.0', abi: '47', lts: false},
|
60 | {runtime: 'electron', target: '1.1.0', abi: '48', lts: false},
|
61 | {runtime: 'electron', target: '1.3.0', abi: '49', lts: false},
|
62 | {runtime: 'electron', target: '1.4.0', abi: '50', lts: false},
|
63 | {runtime: 'electron', target: '1.5.0', abi: '51', lts: false},
|
64 | {runtime: 'electron', target: '1.6.0', abi: '53', lts: false},
|
65 | {runtime: 'electron', target: '1.7.0', abi: '54', lts: false},
|
66 | {runtime: 'electron', target: '1.8.0', abi: '57', lts: false},
|
67 | {runtime: 'electron', target: '2.0.0', abi: '57', lts: false},
|
68 | {runtime: 'electron', target: '3.0.0', abi: '64', lts: false}
|
69 | ]
|
70 |
|
71 | var additionalTargets = [
|
72 | {runtime: 'node-webkit', target: '0.13.0', abi: '47', lts: false},
|
73 | {runtime: 'node-webkit', target: '0.15.0', abi: '48', lts: false},
|
74 | {runtime: 'node-webkit', target: '0.18.3', abi: '51', lts: false},
|
75 | {runtime: 'node-webkit', target: '0.23.0', abi: '57', lts: false},
|
76 | {runtime: 'node-webkit', target: '0.26.5', abi: '59', lts: false}
|
77 | ]
|
78 |
|
79 | var deprecatedTargets = [
|
80 | {runtime: 'node', target: '0.2.0', abi: '1', lts: false},
|
81 | {runtime: 'node', target: '0.9.1', abi: '0x000A', lts: false},
|
82 | {runtime: 'node', target: '0.9.9', abi: '0x000B', lts: false},
|
83 | {runtime: 'node', target: '0.10.4', abi: '11', lts: false},
|
84 | {runtime: 'node', target: '0.11.0', abi: '0x000C', lts: false},
|
85 | {runtime: 'node', target: '0.11.8', abi: '13', lts: false},
|
86 | {runtime: 'node', target: '0.11.11', abi: '14', lts: false},
|
87 | {runtime: 'node', target: '1.0.0', abi: '42', lts: false},
|
88 | {runtime: 'node', target: '1.1.0', abi: '43', lts: false},
|
89 | {runtime: 'node', target: '2.0.0', abi: '44', lts: false},
|
90 | {runtime: 'node', target: '3.0.0', abi: '45', lts: false},
|
91 | {runtime: 'node', target: '4.0.0', abi: '46', lts: false},
|
92 | {runtime: 'electron', target: '0.30.0', abi: '44', lts: false},
|
93 | {runtime: 'electron', target: '0.31.0', abi: '45', lts: false},
|
94 | {runtime: 'electron', target: '0.33.0', abi: '46', lts: false}
|
95 | ]
|
96 |
|
97 | var futureTargets = [
|
98 | {runtime: 'electron', target: '4.0.0-beta.0', abi: '64', lts: false}
|
99 | ]
|
100 |
|
101 | var allTargets = deprecatedTargets
|
102 | .concat(supportedTargets)
|
103 | .concat(additionalTargets)
|
104 | .concat(futureTargets)
|
105 |
|
106 | exports.getAbi = getAbi
|
107 | exports.getTarget = getTarget
|
108 | exports.deprecatedTargets = deprecatedTargets
|
109 | exports.supportedTargets = supportedTargets
|
110 | exports.additionalTargets = additionalTargets
|
111 | exports.futureTargets = futureTargets
|
112 | exports.allTargets = allTargets
|
113 | exports._getNextTarget = getNextTarget
|