index.js 5.1 KB

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