| 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 | var next = semver.inc(latest.target, increment)
|
|---|
| 8 | // Electron releases appear in the registry in their beta form, sometimes there is
|
|---|
| 9 | // no active beta line. During this time we need to double bump
|
|---|
| 10 | if (runtime === 'electron' && semver.parse(latest.target).prerelease.length) {
|
|---|
| 11 | next = semver.inc(next, 'major')
|
|---|
| 12 | }
|
|---|
| 13 | return next
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | function getAbi (target, runtime) {
|
|---|
| 17 | if (target === String(Number(target))) return target
|
|---|
| 18 | if (target) target = target.replace(/^v/, '')
|
|---|
| 19 | if (!runtime) runtime = 'node'
|
|---|
| 20 |
|
|---|
| 21 | if (runtime === 'node') {
|
|---|
| 22 | if (!target) return process.versions.modules
|
|---|
| 23 | if (target === process.versions.node) return process.versions.modules
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | var abi
|
|---|
| 27 | var lastTarget
|
|---|
| 28 |
|
|---|
| 29 | for (var i = 0; i < allTargets.length; i++) {
|
|---|
| 30 | var t = allTargets[i]
|
|---|
| 31 | if (t.runtime !== runtime) continue
|
|---|
| 32 | if (semver.lte(t.target, target) && (!lastTarget || semver.gte(t.target, lastTarget))) {
|
|---|
| 33 | abi = t.abi
|
|---|
| 34 | lastTarget = t.target
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | if (abi && semver.lt(target, getNextTarget(runtime))) return abi
|
|---|
| 39 | 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)
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | function getTarget (abi, runtime) {
|
|---|
| 43 | if (abi && abi !== String(Number(abi))) return abi
|
|---|
| 44 | if (!runtime) runtime = 'node'
|
|---|
| 45 |
|
|---|
| 46 | if (runtime === 'node' && !abi) return process.versions.node
|
|---|
| 47 |
|
|---|
| 48 | var match = allTargets
|
|---|
| 49 | .filter(function (t) {
|
|---|
| 50 | return t.abi === abi && t.runtime === runtime
|
|---|
| 51 | })
|
|---|
| 52 | .map(function (t) {
|
|---|
| 53 | return t.target
|
|---|
| 54 | })
|
|---|
| 55 | if (match.length) {
|
|---|
| 56 | var betaSeparatorIndex = match[0].indexOf("-")
|
|---|
| 57 | return betaSeparatorIndex > -1
|
|---|
| 58 | ? match[0].substring(0, betaSeparatorIndex)
|
|---|
| 59 | : match[0]
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime)
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | function sortByTargetFn (a, b) {
|
|---|
| 66 | var abiComp = Number(a.abi) - Number(b.abi)
|
|---|
| 67 | if (abiComp !== 0) return abiComp
|
|---|
| 68 | if (a.target < b.target) return -1
|
|---|
| 69 | if (a.target > b.target) return 1
|
|---|
| 70 | return 0
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | function loadGeneratedTargets () {
|
|---|
| 74 | var registry = require('./abi_registry.json')
|
|---|
| 75 | var targets = {
|
|---|
| 76 | supported: [],
|
|---|
| 77 | additional: [],
|
|---|
| 78 | future: []
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | registry.forEach(function (item) {
|
|---|
| 82 | var target = {
|
|---|
| 83 | runtime: item.runtime,
|
|---|
| 84 | target: item.target,
|
|---|
| 85 | abi: item.abi
|
|---|
| 86 | }
|
|---|
| 87 | if (item.lts) {
|
|---|
| 88 | var startDate = new Date(Date.parse(item.lts[0]))
|
|---|
| 89 | var endDate = new Date(Date.parse(item.lts[1]))
|
|---|
| 90 | var currentDate = new Date()
|
|---|
| 91 | target.lts = startDate < currentDate && currentDate < endDate
|
|---|
| 92 | } else {
|
|---|
| 93 | target.lts = false
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | if (target.runtime === 'node-webkit') {
|
|---|
| 97 | targets.additional.push(target)
|
|---|
| 98 | } else if (item.future) {
|
|---|
| 99 | targets.future.push(target)
|
|---|
| 100 | } else {
|
|---|
| 101 | targets.supported.push(target)
|
|---|
| 102 | }
|
|---|
| 103 | })
|
|---|
| 104 |
|
|---|
| 105 | targets.supported.sort(sortByTargetFn)
|
|---|
| 106 | targets.additional.sort(sortByTargetFn)
|
|---|
| 107 | targets.future.sort(sortByTargetFn)
|
|---|
| 108 |
|
|---|
| 109 | return targets
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | var generatedTargets = loadGeneratedTargets()
|
|---|
| 113 |
|
|---|
| 114 | var supportedTargets = [
|
|---|
| 115 | {runtime: 'node', target: '5.0.0', abi: '47', lts: false},
|
|---|
| 116 | {runtime: 'node', target: '6.0.0', abi: '48', lts: false},
|
|---|
| 117 | {runtime: 'node', target: '7.0.0', abi: '51', lts: false},
|
|---|
| 118 | {runtime: 'node', target: '8.0.0', abi: '57', lts: false},
|
|---|
| 119 | {runtime: 'node', target: '9.0.0', abi: '59', lts: false},
|
|---|
| 120 | {runtime: 'node', target: '10.0.0', abi: '64', lts: new Date(2018, 10, 1) < new Date() && new Date() < new Date(2020, 4, 31)},
|
|---|
| 121 | {runtime: 'electron', target: '0.36.0', abi: '47', lts: false},
|
|---|
| 122 | {runtime: 'electron', target: '1.1.0', abi: '48', lts: false},
|
|---|
| 123 | {runtime: 'electron', target: '1.3.0', abi: '49', lts: false},
|
|---|
| 124 | {runtime: 'electron', target: '1.4.0', abi: '50', lts: false},
|
|---|
| 125 | {runtime: 'electron', target: '1.5.0', abi: '51', lts: false},
|
|---|
| 126 | {runtime: 'electron', target: '1.6.0', abi: '53', lts: false},
|
|---|
| 127 | {runtime: 'electron', target: '1.7.0', abi: '54', lts: false},
|
|---|
| 128 | {runtime: 'electron', target: '1.8.0', abi: '57', lts: false},
|
|---|
| 129 | {runtime: 'electron', target: '2.0.0', abi: '57', lts: false},
|
|---|
| 130 | {runtime: 'electron', target: '3.0.0', abi: '64', lts: false},
|
|---|
| 131 | {runtime: 'electron', target: '4.0.0', abi: '64', lts: false},
|
|---|
| 132 | {runtime: 'electron', target: '4.0.4', abi: '69', lts: false}
|
|---|
| 133 | ]
|
|---|
| 134 |
|
|---|
| 135 | supportedTargets.push.apply(supportedTargets, generatedTargets.supported)
|
|---|
| 136 |
|
|---|
| 137 | var additionalTargets = [
|
|---|
| 138 | {runtime: 'node-webkit', target: '0.13.0', abi: '47', lts: false},
|
|---|
| 139 | {runtime: 'node-webkit', target: '0.15.0', abi: '48', lts: false},
|
|---|
| 140 | {runtime: 'node-webkit', target: '0.18.3', abi: '51', lts: false},
|
|---|
| 141 | {runtime: 'node-webkit', target: '0.23.0', abi: '57', lts: false},
|
|---|
| 142 | {runtime: 'node-webkit', target: '0.26.5', abi: '59', lts: false}
|
|---|
| 143 | ]
|
|---|
| 144 |
|
|---|
| 145 | additionalTargets.push.apply(additionalTargets, generatedTargets.additional)
|
|---|
| 146 |
|
|---|
| 147 | var deprecatedTargets = [
|
|---|
| 148 | {runtime: 'node', target: '0.2.0', abi: '1', lts: false},
|
|---|
| 149 | {runtime: 'node', target: '0.9.1', abi: '0x000A', lts: false},
|
|---|
| 150 | {runtime: 'node', target: '0.9.9', abi: '0x000B', lts: false},
|
|---|
| 151 | {runtime: 'node', target: '0.10.4', abi: '11', lts: false},
|
|---|
| 152 | {runtime: 'node', target: '0.11.0', abi: '0x000C', lts: false},
|
|---|
| 153 | {runtime: 'node', target: '0.11.8', abi: '13', lts: false},
|
|---|
| 154 | {runtime: 'node', target: '0.11.11', abi: '14', lts: false},
|
|---|
| 155 | {runtime: 'node', target: '1.0.0', abi: '42', lts: false},
|
|---|
| 156 | {runtime: 'node', target: '1.1.0', abi: '43', lts: false},
|
|---|
| 157 | {runtime: 'node', target: '2.0.0', abi: '44', lts: false},
|
|---|
| 158 | {runtime: 'node', target: '3.0.0', abi: '45', lts: false},
|
|---|
| 159 | {runtime: 'node', target: '4.0.0', abi: '46', lts: false},
|
|---|
| 160 | {runtime: 'electron', target: '0.30.0', abi: '44', lts: false},
|
|---|
| 161 | {runtime: 'electron', target: '0.31.0', abi: '45', lts: false},
|
|---|
| 162 | {runtime: 'electron', target: '0.33.0', abi: '46', lts: false}
|
|---|
| 163 | ]
|
|---|
| 164 |
|
|---|
| 165 | var futureTargets = generatedTargets.future
|
|---|
| 166 |
|
|---|
| 167 | var allTargets = deprecatedTargets
|
|---|
| 168 | .concat(supportedTargets)
|
|---|
| 169 | .concat(additionalTargets)
|
|---|
| 170 | .concat(futureTargets)
|
|---|
| 171 |
|
|---|
| 172 | exports.getAbi = getAbi
|
|---|
| 173 | exports.getTarget = getTarget
|
|---|
| 174 | exports.deprecatedTargets = deprecatedTargets
|
|---|
| 175 | exports.supportedTargets = supportedTargets
|
|---|
| 176 | exports.additionalTargets = additionalTargets
|
|---|
| 177 | exports.futureTargets = futureTargets
|
|---|
| 178 | exports.allTargets = allTargets
|
|---|
| 179 | exports._getNextTarget = getNextTarget
|
|---|