node-abi 2.19.1 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  name: Auto-update ABI JSON file
2
2
  on:
3
3
  schedule:
4
- - cron: '0 0 * * *'
4
+ - cron: '0 * * * *'
5
5
  jobs:
6
6
  autoupdate:
7
7
  runs-on: ubuntu-latest
package/abi_registry.json CHANGED
@@ -6,87 +6,101 @@
6
6
  "future": false,
7
7
  "abi": "67"
8
8
  },
9
- {
10
- "runtime": "electron",
11
- "target": "5.0.0",
12
- "lts": false,
13
- "future": false,
14
- "abi": "70"
15
- },
16
9
  {
17
10
  "runtime": "node",
18
11
  "target": "12.0.0",
19
12
  "lts": [
20
13
  "2019-10-21",
21
- "2020-10-20"
14
+ "2020-11-30"
22
15
  ],
23
16
  "future": false,
24
- "abi": "68"
17
+ "abi": "72"
25
18
  },
26
19
  {
27
- "runtime": "electron",
28
- "target": "6.0.0",
20
+ "runtime": "node",
21
+ "target": "13.0.0",
29
22
  "lts": false,
30
23
  "future": false,
31
- "abi": "73"
24
+ "abi": "79"
32
25
  },
33
26
  {
34
- "runtime": "electron",
35
- "target": "7.0.0",
36
- "lts": false,
27
+ "runtime": "node",
28
+ "target": "14.0.0",
29
+ "lts": [
30
+ "2020-10-27",
31
+ "2021-10-19"
32
+ ],
37
33
  "future": false,
38
- "abi": "75"
34
+ "abi": "83"
39
35
  },
40
36
  {
41
- "runtime": "electron",
42
- "target": "8.0.0",
37
+ "runtime": "node",
38
+ "target": "15.0.0",
43
39
  "lts": false,
44
40
  "future": false,
45
- "abi": "76"
41
+ "abi": "88"
46
42
  },
47
43
  {
48
- "runtime": "node",
49
- "target": "13.0.0",
50
- "lts": false,
44
+ "abi": "70",
51
45
  "future": false,
52
- "abi": "74"
46
+ "lts": false,
47
+ "runtime": "electron",
48
+ "target": "5.0.0-beta.9"
53
49
  },
54
50
  {
55
- "runtime": "electron",
56
- "target": "9.0.0",
57
- "lts": false,
51
+ "abi": "73",
58
52
  "future": false,
59
- "abi": "80"
53
+ "lts": false,
54
+ "runtime": "electron",
55
+ "target": "6.0.0-beta.1"
60
56
  },
61
57
  {
62
- "runtime": "node",
63
- "target": "14.0.0",
64
- "lts": [
65
- "2020-10-27",
66
- "2021-10-19"
67
- ],
58
+ "abi": "75",
68
59
  "future": false,
69
- "abi": "81"
60
+ "lts": false,
61
+ "runtime": "electron",
62
+ "target": "7.0.0-beta.1"
70
63
  },
71
64
  {
65
+ "abi": "76",
66
+ "future": false,
67
+ "lts": false,
72
68
  "runtime": "electron",
73
- "target": "10.0.0-beta.1",
69
+ "target": "8.0.0-beta.1"
70
+ },
71
+ {
72
+ "abi": "80",
73
+ "future": false,
74
74
  "lts": false,
75
- "future": true,
76
- "abi": "82"
75
+ "runtime": "electron",
76
+ "target": "9.0.0-beta.2"
77
77
  },
78
78
  {
79
- "runtime": "node",
80
- "target": "15.0.0",
79
+ "abi": "82",
80
+ "future": false,
81
81
  "lts": false,
82
- "future": true,
83
- "abi": "84"
82
+ "runtime": "electron",
83
+ "target": "10.0.0-beta.1"
84
84
  },
85
85
  {
86
+ "abi": "85",
87
+ "future": false,
88
+ "lts": false,
86
89
  "runtime": "electron",
87
- "target": "11.0.0-beta.1",
90
+ "target": "11.0.0-beta.11"
91
+ },
92
+ {
93
+ "abi": "87",
94
+ "future": false,
88
95
  "lts": false,
96
+ "runtime": "electron",
97
+ "target": "12.0.0-beta.1"
98
+ },
99
+ {
100
+ "abi": "89",
89
101
  "future": true,
90
- "abi": "85"
102
+ "lts": false,
103
+ "runtime": "electron",
104
+ "target": "13.0.0-beta.2"
91
105
  }
92
106
  ]
package/index.js CHANGED
@@ -43,11 +43,24 @@ function getTarget (abi, runtime) {
43
43
  .map(function (t) {
44
44
  return t.target
45
45
  })
46
- if (match.length) return match[0]
46
+ if (match.length) {
47
+ var betaSeparatorIndex = match[0].indexOf("-")
48
+ return betaSeparatorIndex > -1
49
+ ? match[0].substring(0, betaSeparatorIndex)
50
+ : match[0]
51
+ }
47
52
 
48
53
  throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime)
49
54
  }
50
55
 
56
+ function sortByTargetFn (a, b) {
57
+ var abiComp = Number(a.abi) - Number(b.abi)
58
+ if (abiComp !== 0) return abiComp
59
+ if (a.target < b.target) return -1
60
+ if (a.target > b.target) return 1
61
+ return 0
62
+ }
63
+
51
64
  function loadGeneratedTargets () {
52
65
  var registry = require('./abi_registry.json')
53
66
  var targets = {
@@ -80,9 +93,9 @@ function loadGeneratedTargets () {
80
93
  }
81
94
  })
82
95
 
83
- targets.supported.sort()
84
- targets.additional.sort()
85
- targets.future.sort()
96
+ targets.supported.sort(sortByTargetFn)
97
+ targets.additional.sort(sortByTargetFn)
98
+ targets.future.sort(sortByTargetFn)
86
99
 
87
100
  return targets
88
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-abi",
3
- "version": "2.19.1",
3
+ "version": "2.21.0",
4
4
  "description": "Get the Node ABI for a given target and runtime, and vice versa.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,8 +8,8 @@ async function getJSONFromCDN (urlPath) {
8
8
  return JSON.parse(response.body)
9
9
  }
10
10
 
11
- async function fetchElectronVersions () {
12
- return (await getJSONFromCDN('electron/releases/lite.json')).map(metadata => metadata.version)
11
+ async function fetchElectronReleases () {
12
+ return (await getJSONFromCDN('electron/releases/lite.json'))
13
13
  }
14
14
 
15
15
  async function fetchNodeVersions () {
@@ -34,58 +34,78 @@ async function fetchNodeVersions () {
34
34
  }
35
35
 
36
36
  async function fetchAbiVersions () {
37
- return (await getJSONFromCDN('nodejs/node/doc/abi_version_registry.json')).NODE_MODULE_VERSION
37
+ return (await getJSONFromCDN('nodejs/node/doc/abi_version_registry.json'))
38
+ .NODE_MODULE_VERSION
39
+ .filter(({ modules }) => modules > 66)
38
40
  }
39
41
 
40
- async function main () {
41
- const nodeVersions = await fetchNodeVersions()
42
- const abiVersions = await fetchAbiVersions()
43
- const electronVersions = await fetchElectronVersions()
42
+ function electronReleasesToTargets (releases) {
43
+ const versions = releases.map(({ version }) => version)
44
+ const versionsByModules = releases
45
+ .filter(release => release.deps && Number(release.deps.modules) >= 70)
46
+ .map(({ version, deps: { modules } }) => ({
47
+ version,
48
+ modules,
49
+ }))
50
+ .reduce(
51
+ (acc, { modules, version }) => ({
52
+ ...acc,
53
+ [modules]: version,
54
+ }),
55
+ {}
56
+ )
44
57
 
45
- const abiVersionSet = new Set()
46
- const supportedTargets = []
47
- for (const abiVersion of abiVersions) {
48
- if (abiVersion.modules <= 66) {
49
- // Don't try to parse any ABI versions older than 60
50
- break
51
- } else if (abiVersion.runtime === 'electron' && abiVersion.modules < 70) {
52
- // Don't try to parse Electron ABI versions below Electron 5
53
- continue
54
- }
58
+ return Object.entries(versionsByModules)
59
+ .map(
60
+ ([modules, version]) => ({
61
+ abi: modules,
62
+ future: !versions.find(
63
+ v => {
64
+ const major = version.split(".")[0]
65
+ return semver.satisfies(
66
+ v,
67
+ /^[0-9]/.test(major) ? `>= ${major}` : major
68
+ )
69
+ }
70
+ ),
71
+ lts: false,
72
+ runtime: 'electron',
73
+ target: version
74
+ })
75
+ )
76
+ }
55
77
 
56
- let target
57
- if (abiVersion.runtime === 'node') {
58
- const nodeVersion = `${abiVersion.versions.replace('.0.0-pre', '')}.0.0`
59
- target = nodeVersions[nodeVersion]
60
- if (!target) {
61
- continue
62
- }
63
- } else {
64
- target = {
65
- runtime: abiVersion.runtime === 'nw.js' ? 'node-webkit' : abiVersion.runtime,
66
- target: abiVersion.versions,
67
- lts: false,
68
- future: false
69
- }
70
- if (target.runtime === 'electron') {
71
- target.target = `${target.target}.0.0`
72
- const constraint = /^[0-9]/.test(abiVersion.versions) ? `>= ${abiVersion.versions}` : abiVersion.versions
73
- if (!electronVersions.find(electronVersion => semver.satisfies(electronVersion, constraint))) {
74
- target.target = `${target.target}-beta.1`
75
- target.future = true
76
- }
77
- }
78
- }
79
- target.abi = abiVersion.modules.toString()
78
+ function nodeVersionsToTargets (abiVersions, nodeVersions) {
79
+ return Object.values(
80
+ abiVersions
81
+ .filter(({ runtime }) => runtime === 'node')
82
+ .reduce(
83
+ (acc, abiVersion) => {
84
+ const { version: nodeVersion } = semver.coerce(abiVersion.versions)
80
85
 
81
- const key = [target.runtime, target.target].join('-')
82
- if (abiVersionSet.has(key)) {
83
- continue
84
- }
86
+ return {
87
+ [nodeVersion]: {
88
+ ...nodeVersions[nodeVersion],
89
+ abi: abiVersion.modules.toString(),
90
+ },
91
+ ...acc,
92
+ };
93
+ },
94
+ {}
95
+ )
96
+ )
97
+ }
85
98
 
86
- abiVersionSet.add(key)
87
- supportedTargets.unshift(target)
88
- }
99
+ async function main () {
100
+ const nodeVersions = await fetchNodeVersions()
101
+ const abiVersions = await fetchAbiVersions()
102
+ const electronReleases = await fetchElectronReleases()
103
+ const electronTargets = electronReleasesToTargets(electronReleases)
104
+ const nodeTargets = nodeVersionsToTargets(abiVersions, nodeVersions)
105
+ const supportedTargets = [
106
+ ...nodeTargets,
107
+ ...electronTargets,
108
+ ]
89
109
 
90
110
  await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2))
91
111
  }
package/test/index.js CHANGED
@@ -26,6 +26,10 @@ test('getTarget calculates correct Node target', function (t) {
26
26
  t.equal(getTarget('47'), '5.0.0')
27
27
  t.equal(getTarget('48'), '6.0.0')
28
28
  t.equal(getTarget('51'), '7.0.0')
29
+ t.equal(getTarget('67'), '11.0.0')
30
+ t.equal(getTarget('72'), '12.0.0')
31
+ t.equal(getTarget('83'), '14.0.0')
32
+ t.equal(getTarget('88'), '15.0.0')
29
33
  t.end()
30
34
  })
31
35
 
@@ -36,6 +40,7 @@ test('getTarget calculates correct Electron target', function (t) {
36
40
  t.equal(getTarget('49', 'electron'), '1.3.0')
37
41
  t.equal(getTarget('50', 'electron'), '1.4.0')
38
42
  t.equal(getTarget('76', 'electron'), '8.0.0')
43
+ t.equal(getTarget('82', 'electron'), '10.0.0')
39
44
  t.end()
40
45
  })
41
46
 
@@ -54,7 +59,11 @@ test('getAbi calculates correct Node ABI', function (t) {
54
59
  t.equal(getAbi(null), process.versions.modules)
55
60
  t.throws(function () { getAbi('a.b.c') })
56
61
  t.throws(function () { getAbi(getNextTarget('node')) })
57
- t.equal(getAbi('12.0.0'), '68')
62
+ t.equal(getAbi('15.0.0'), '88')
63
+ t.equal(getAbi('14.0.0'), '83')
64
+ t.equal(getAbi('13.0.0'), '79')
65
+ t.equal(getAbi('12.0.0'), '72')
66
+ t.equal(getAbi('11.0.0'), '67')
58
67
  t.equal(getAbi('7.2.0'), '51')
59
68
  t.equal(getAbi('7.0.0'), '51')
60
69
  t.equal(getAbi('6.9.9'), '48')
@@ -91,6 +100,7 @@ test('getAbi calculates correct Electron ABI', function (t) {
91
100
  t.throws(function () { getAbi(undefined, 'electron') })
92
101
  t.throws(function () { getAbi(getNextTarget('electron'), 'electron') })
93
102
  t.equal(getAbi('10.0.0-beta.1', 'electron'), '82')
103
+ t.equal(getAbi('10.0.0', 'electron'), '82')
94
104
  t.equal(getAbi('9.0.0', 'electron'), '80')
95
105
  t.equal(getAbi('8.0.0', 'electron'), '76')
96
106
  t.equal(getAbi('7.0.0', 'electron'), '75')