UNPKG

4.38 kBJavaScriptView Raw
1function getAbi (target, runtime) {
2 if (target === String(Number(target))) return target
3 if (target) target = target.replace(/^v/, '')
4
5 if (runtime === 'electron') {
6 if (/^1\.6\./.test(target)) return '53'
7 if (/^1\.5\./.test(target)) return '51'
8 if (/^1\.4\./.test(target)) return '50'
9 if (/^1\.3\./.test(target)) return '49'
10 if (/^1\.[1-2]\./.test(target)) return '48'
11 if (/^1\.0\./.test(target)) return '47'
12 if (/^0\.3[6-7]\./.test(target)) return '47'
13 if (/^0\.3[3-5]\./.test(target)) return '46'
14 if (/^0\.3[1-2]\./.test(target)) return '45'
15 if (/^0\.30\./.test(target)) return '44'
16 } else {
17 if (!target) return process.versions.modules
18 if (target === process.versions.node) return process.versions.modules
19 if (/^8\./.test(target)) return '52'
20 if (/^7\./.test(target)) return '51'
21 if (/^6\./.test(target)) return '48'
22 if (/^5\./.test(target)) return '47'
23 if (/^4\./.test(target)) return '46'
24 if (/^0\.12\./.test(target)) return '14'
25 if (/^0\.10\.[0-3]$/.test(target)) return '0x000B'
26 if (/^0\.10\./.test(target)) return '11'
27 // io.js and legacy Node.js
28 if (/^3\./.test(target)) return '45'
29 if (/^2\./.test(target)) return '44'
30 if (/^1\.[1-8]\./.test(target)) return '43'
31 if (/^1\.0\./.test(target)) return '42'
32 if (/^0\.11\.1[1-6]/.test(target)) return '14'
33 if (/^0\.11\.10/.test(target)) return '13'
34 if (/^0\.11\.[8-9]/.test(target)) return '13'
35 if (/^0\.11\.[0-7]/.test(target)) return '0x000C'
36 if (/^0\.9\.1[0-2]$/.test(target)) return '0x000B'
37 if (/^0\.9\.9$/.test(target)) return '0x000B'
38 if (/^0\.9\.[1-8]$/.test(target)) return '0x000A'
39 if (/^0\.9\.0/.test(target)) return '1'
40 if (/^0\.[2-8]/.test(target)) return '1'
41 }
42
43 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)
44}
45
46function getTarget (abi, runtime) {
47 if (abi && abi !== String(Number(abi))) return abi
48 if (!runtime) runtime = 'node'
49
50 if (runtime === 'node' && !abi) return process.versions.node
51
52 var match = allTargets
53 .filter(function (t) {
54 return t.abi === abi && t.runtime === runtime
55 })
56 .map(function (t) {
57 return t.target
58 })
59 if (match.length) return match[0]
60
61 throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime)
62}
63
64var supportedTargets = [
65 {runtime: 'node', target: '0.10.48', abi: '11', lts: false},
66 {runtime: 'node', target: '0.12.17', abi: '14', lts: false},
67 {runtime: 'node', target: '4.6.1', abi: '46', lts: new Date() < new Date(2017, 04, 01)},
68 {runtime: 'node', target: '5.12.0', abi: '47', lts: false},
69 {runtime: 'node', target: '6.9.4', abi: '48', lts: new Date() < new Date(2018, 04, 18)},
70 {runtime: 'node', target: '7.4.0', abi: '51', lts: false},
71 {runtime: 'electron', target: '1.0.2', abi: '47', lts: false},
72 {runtime: 'electron', target: '1.2.8', abi: '48', lts: false},
73 {runtime: 'electron', target: '1.3.13', abi: '49', lts: false},
74 {runtime: 'electron', target: '1.4.15', abi: '50', lts: false},
75 {runtime: 'electron', target: '1.5.0', abi: '51', lts: false},
76 {runtime: 'electron', target: '1.6.0', abi: '53', lts: false}
77]
78
79var 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.10.0', abi: '0x000B', lts: false},
83 {runtime: 'node', target: '0.11.0', abi: '0x000C', lts: false},
84 {runtime: 'node', target: '0.11.10', abi: '13', lts: false},
85 {runtime: 'node', target: '1.0.0', abi: '42', lts: false},
86 {runtime: 'node', target: '1.1.0', abi: '43', lts: false},
87 {runtime: 'node', target: '2.0.0', abi: '44', lts: false},
88 {runtime: 'node', target: '3.0.0', abi: '45', lts: false},
89 {runtime: 'node', target: '8.0.0', abi: '52', lts: false},
90 {runtime: 'electron', target: '0.30.0', abi: '44', lts: false},
91 {runtime: 'electron', target: '0.31.0', abi: '45', lts: false},
92 {runtime: 'electron', target: '0.33.0', abi: '46', lts: false}
93]
94
95var allTargets = supportedTargets.concat(deprecatedTargets)
96
97exports.getAbi = getAbi
98exports.getTarget = getTarget
99exports.supportedTargets = supportedTargets
100exports.deprecatedTargets = deprecatedTargets
101exports.allTargets = allTargets