node-abi 2.16.0 → 2.19.1

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.
@@ -0,0 +1,41 @@
1
+ name: Auto-update ABI JSON file
2
+ on:
3
+ schedule:
4
+ - cron: '0 0 * * *'
5
+ jobs:
6
+ autoupdate:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: actions/setup-node@v1
11
+ with:
12
+ node-version: '12.x'
13
+ - name: Get npm cache directory
14
+ id: npm-cache
15
+ run: |
16
+ echo "::set-output name=dir::$(npm config get cache)"
17
+ - uses: actions/cache@v1
18
+ with:
19
+ path: ${{ steps.npm-cache.outputs.dir }}
20
+ key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
21
+ restore-keys: |
22
+ ${{ runner.os }}-node-
23
+ - run: npm install --no-package-lock
24
+ - name: Update ABI registry
25
+ run: npm run update-abi-registry
26
+ - name: Commit Changes to ABI registry
27
+ env:
28
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29
+ run: |
30
+ echo "machine github.com login $GITHUB_ACTOR password $GITHUB_TOKEN" > ~/.netrc
31
+ chmod 600 ~/.netrc
32
+ git add abi_registry.json
33
+ if test -n "$(git status -s)"; then
34
+ git config user.name "GitHub Actions"
35
+ git config user.email "github-actions@users.noreply.github.com"
36
+ git diff --cached
37
+ git commit -m "feat: update ABI registry"
38
+ git push origin HEAD:$GITHUB_REF
39
+ else
40
+ echo No update needed
41
+ fi
@@ -0,0 +1,92 @@
1
+ [
2
+ {
3
+ "runtime": "node",
4
+ "target": "11.0.0",
5
+ "lts": false,
6
+ "future": false,
7
+ "abi": "67"
8
+ },
9
+ {
10
+ "runtime": "electron",
11
+ "target": "5.0.0",
12
+ "lts": false,
13
+ "future": false,
14
+ "abi": "70"
15
+ },
16
+ {
17
+ "runtime": "node",
18
+ "target": "12.0.0",
19
+ "lts": [
20
+ "2019-10-21",
21
+ "2020-10-20"
22
+ ],
23
+ "future": false,
24
+ "abi": "68"
25
+ },
26
+ {
27
+ "runtime": "electron",
28
+ "target": "6.0.0",
29
+ "lts": false,
30
+ "future": false,
31
+ "abi": "73"
32
+ },
33
+ {
34
+ "runtime": "electron",
35
+ "target": "7.0.0",
36
+ "lts": false,
37
+ "future": false,
38
+ "abi": "75"
39
+ },
40
+ {
41
+ "runtime": "electron",
42
+ "target": "8.0.0",
43
+ "lts": false,
44
+ "future": false,
45
+ "abi": "76"
46
+ },
47
+ {
48
+ "runtime": "node",
49
+ "target": "13.0.0",
50
+ "lts": false,
51
+ "future": false,
52
+ "abi": "74"
53
+ },
54
+ {
55
+ "runtime": "electron",
56
+ "target": "9.0.0",
57
+ "lts": false,
58
+ "future": false,
59
+ "abi": "80"
60
+ },
61
+ {
62
+ "runtime": "node",
63
+ "target": "14.0.0",
64
+ "lts": [
65
+ "2020-10-27",
66
+ "2021-10-19"
67
+ ],
68
+ "future": false,
69
+ "abi": "81"
70
+ },
71
+ {
72
+ "runtime": "electron",
73
+ "target": "10.0.0-beta.1",
74
+ "lts": false,
75
+ "future": true,
76
+ "abi": "82"
77
+ },
78
+ {
79
+ "runtime": "node",
80
+ "target": "15.0.0",
81
+ "lts": false,
82
+ "future": true,
83
+ "abi": "84"
84
+ },
85
+ {
86
+ "runtime": "electron",
87
+ "target": "11.0.0-beta.1",
88
+ "lts": false,
89
+ "future": true,
90
+ "abi": "85"
91
+ }
92
+ ]
package/index.js CHANGED
@@ -48,6 +48,47 @@ function getTarget (abi, runtime) {
48
48
  throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime)
49
49
  }
50
50
 
51
+ function loadGeneratedTargets () {
52
+ var registry = require('./abi_registry.json')
53
+ var targets = {
54
+ supported: [],
55
+ additional: [],
56
+ future: []
57
+ }
58
+
59
+ registry.forEach(function (item) {
60
+ var target = {
61
+ runtime: item.runtime,
62
+ target: item.target,
63
+ abi: item.abi
64
+ }
65
+ if (item.lts) {
66
+ var startDate = new Date(Date.parse(item.lts[0]))
67
+ var endDate = new Date(Date.parse(item.lts[1]))
68
+ var currentDate = new Date()
69
+ target.lts = startDate < currentDate && currentDate < endDate
70
+ } else {
71
+ target.lts = false
72
+ }
73
+
74
+ if (target.runtime === 'node-webkit') {
75
+ targets.additional.push(target)
76
+ } else if (item.future) {
77
+ targets.future.push(target)
78
+ } else {
79
+ targets.supported.push(target)
80
+ }
81
+ })
82
+
83
+ targets.supported.sort()
84
+ targets.additional.sort()
85
+ targets.future.sort()
86
+
87
+ return targets
88
+ }
89
+
90
+ var generatedTargets = loadGeneratedTargets()
91
+
51
92
  var supportedTargets = [
52
93
  {runtime: 'node', target: '5.0.0', abi: '47', lts: false},
53
94
  {runtime: 'node', target: '6.0.0', abi: '48', lts: false},
@@ -55,10 +96,6 @@ var supportedTargets = [
55
96
  {runtime: 'node', target: '8.0.0', abi: '57', lts: false},
56
97
  {runtime: 'node', target: '9.0.0', abi: '59', lts: false},
57
98
  {runtime: 'node', target: '10.0.0', abi: '64', lts: new Date(2018, 10, 1) < new Date() && new Date() < new Date(2020, 4, 31)},
58
- {runtime: 'node', target: '11.0.0', abi: '67', lts: false},
59
- {runtime: 'node', target: '12.0.0', abi: '72', lts: new Date(2019, 9, 21) < new Date() && new Date() < new Date(2020, 9, 31)},
60
- {runtime: 'node', target: '13.0.0', abi: '79', lts: false},
61
- {runtime: 'node', target: '14.0.0', abi: '83', lts: false},
62
99
  {runtime: 'electron', target: '0.36.0', abi: '47', lts: false},
63
100
  {runtime: 'electron', target: '1.1.0', abi: '48', lts: false},
64
101
  {runtime: 'electron', target: '1.3.0', abi: '49', lts: false},
@@ -70,13 +107,11 @@ var supportedTargets = [
70
107
  {runtime: 'electron', target: '2.0.0', abi: '57', lts: false},
71
108
  {runtime: 'electron', target: '3.0.0', abi: '64', lts: false},
72
109
  {runtime: 'electron', target: '4.0.0', abi: '64', lts: false},
73
- {runtime: 'electron', target: '4.0.4', abi: '69', lts: false},
74
- {runtime: 'electron', target: '5.0.0', abi: '70', lts: false},
75
- {runtime: 'electron', target: '6.0.0', abi: '73', lts: false},
76
- {runtime: 'electron', target: '7.0.0', abi: '75', lts: false},
77
- {runtime: 'electron', target: '8.0.0', abi: '76', lts: false}
110
+ {runtime: 'electron', target: '4.0.4', abi: '69', lts: false}
78
111
  ]
79
112
 
113
+ supportedTargets.push.apply(supportedTargets, generatedTargets.supported)
114
+
80
115
  var additionalTargets = [
81
116
  {runtime: 'node-webkit', target: '0.13.0', abi: '47', lts: false},
82
117
  {runtime: 'node-webkit', target: '0.15.0', abi: '48', lts: false},
@@ -85,6 +120,8 @@ var additionalTargets = [
85
120
  {runtime: 'node-webkit', target: '0.26.5', abi: '59', lts: false}
86
121
  ]
87
122
 
123
+ additionalTargets.push.apply(additionalTargets, generatedTargets.additional)
124
+
88
125
  var deprecatedTargets = [
89
126
  {runtime: 'node', target: '0.2.0', abi: '1', lts: false},
90
127
  {runtime: 'node', target: '0.9.1', abi: '0x000A', lts: false},
@@ -103,9 +140,7 @@ var deprecatedTargets = [
103
140
  {runtime: 'electron', target: '0.33.0', abi: '46', lts: false}
104
141
  ]
105
142
 
106
- var futureTargets = [
107
- {runtime: 'electron', target: '9.0.0-beta.1', abi: '80', lts: false}
108
- ]
143
+ var futureTargets = generatedTargets.future
109
144
 
110
145
  var allTargets = deprecatedTargets
111
146
  .concat(supportedTargets)
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "node-abi",
3
- "version": "2.16.0",
3
+ "version": "2.19.1",
4
4
  "description": "Get the Node ABI for a given target and runtime, and vice versa.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "tape test/index.js",
8
7
  "semantic-release": "semantic-release",
9
- "travis-deploy-once": "travis-deploy-once"
8
+ "test": "tape test/index.js",
9
+ "travis-deploy-once": "travis-deploy-once",
10
+ "update-abi-registry": "node --unhandled-rejections=strict scripts/update-abi-registry.js"
10
11
  },
11
12
  "repository": {
12
13
  "type": "git",
@@ -26,6 +27,7 @@
26
27
  },
27
28
  "homepage": "https://github.com/lgeiger/node-abi#readme",
28
29
  "devDependencies": {
30
+ "got": "^10.6.0",
29
31
  "semantic-release": "^15.8.0",
30
32
  "tape": "^4.6.3",
31
33
  "travis-deploy-once": "^5.0.1"
@@ -0,0 +1,93 @@
1
+ const got = require('got')
2
+ const path = require('path')
3
+ const semver = require('semver')
4
+ const { writeFile } = require('fs').promises
5
+
6
+ async function getJSONFromCDN (urlPath) {
7
+ const response = await got(`https://cdn.jsdelivr.net/gh/${urlPath}`)
8
+ return JSON.parse(response.body)
9
+ }
10
+
11
+ async function fetchElectronVersions () {
12
+ return (await getJSONFromCDN('electron/releases/lite.json')).map(metadata => metadata.version)
13
+ }
14
+
15
+ async function fetchNodeVersions () {
16
+ const schedule = await getJSONFromCDN('nodejs/Release/schedule.json')
17
+ const versions = {}
18
+
19
+ for (const [majorVersion, metadata] of Object.entries(schedule)) {
20
+ if (majorVersion.startsWith('v0')) {
21
+ continue
22
+ }
23
+ const version = `${majorVersion.slice(1)}.0.0`
24
+ const lts = metadata.hasOwnProperty('lts') ? [metadata.lts, metadata.maintenance] : false
25
+ versions[version] = {
26
+ runtime: 'node',
27
+ target: version,
28
+ lts: lts,
29
+ future: new Date(Date.parse(metadata.start)) > new Date()
30
+ }
31
+ }
32
+
33
+ return versions
34
+ }
35
+
36
+ async function fetchAbiVersions () {
37
+ return (await getJSONFromCDN('nodejs/node/doc/abi_version_registry.json')).NODE_MODULE_VERSION
38
+ }
39
+
40
+ async function main () {
41
+ const nodeVersions = await fetchNodeVersions()
42
+ const abiVersions = await fetchAbiVersions()
43
+ const electronVersions = await fetchElectronVersions()
44
+
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
+ }
55
+
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()
80
+
81
+ const key = [target.runtime, target.target].join('-')
82
+ if (abiVersionSet.has(key)) {
83
+ continue
84
+ }
85
+
86
+ abiVersionSet.add(key)
87
+ supportedTargets.unshift(target)
88
+ }
89
+
90
+ await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2))
91
+ }
92
+
93
+ main()
package/test/index.js CHANGED
@@ -5,7 +5,7 @@ var getTarget = require('../index').getTarget
5
5
  var getNextTarget = require('../index')._getNextTarget
6
6
  var allTargets = require('../index').allTargets
7
7
 
8
- test('getNextTarget gets the next unsopported target', function (t) {
8
+ test('getNextTarget gets the next unsupported target', function (t) {
9
9
  var mockTargets = [
10
10
  {runtime: 'node', target: '7.0.0', abi: '51', lts: false},
11
11
  {runtime: 'node', target: '8.0.0', abi: '57', lts: false},
@@ -35,6 +35,7 @@ test('getTarget calculates correct Electron target', function (t) {
35
35
  t.equal(getTarget('48', 'electron'), '1.1.0')
36
36
  t.equal(getTarget('49', 'electron'), '1.3.0')
37
37
  t.equal(getTarget('50', 'electron'), '1.4.0')
38
+ t.equal(getTarget('76', 'electron'), '8.0.0')
38
39
  t.end()
39
40
  })
40
41
 
@@ -53,6 +54,7 @@ test('getAbi calculates correct Node ABI', function (t) {
53
54
  t.equal(getAbi(null), process.versions.modules)
54
55
  t.throws(function () { getAbi('a.b.c') })
55
56
  t.throws(function () { getAbi(getNextTarget('node')) })
57
+ t.equal(getAbi('12.0.0'), '68')
56
58
  t.equal(getAbi('7.2.0'), '51')
57
59
  t.equal(getAbi('7.0.0'), '51')
58
60
  t.equal(getAbi('6.9.9'), '48')
@@ -88,6 +90,11 @@ test('getAbi calculates correct Node ABI', function (t) {
88
90
  test('getAbi calculates correct Electron ABI', function (t) {
89
91
  t.throws(function () { getAbi(undefined, 'electron') })
90
92
  t.throws(function () { getAbi(getNextTarget('electron'), 'electron') })
93
+ t.equal(getAbi('10.0.0-beta.1', 'electron'), '82')
94
+ t.equal(getAbi('9.0.0', 'electron'), '80')
95
+ t.equal(getAbi('8.0.0', 'electron'), '76')
96
+ t.equal(getAbi('7.0.0', 'electron'), '75')
97
+ t.equal(getAbi('6.0.0', 'electron'), '73')
91
98
  t.equal(getAbi('5.0.0', 'electron'), '70')
92
99
  t.equal(getAbi('4.1.4', 'electron'), '69')
93
100
  t.equal(getAbi('4.0.4', 'electron'), '69')
@@ -150,8 +157,8 @@ test('allTargets are sorted', function (t) {
150
157
  return semver.compare(t1.target, t2.target)
151
158
  }
152
159
 
153
- t.deepEqual(electron, electron.slice().sort(sort))
154
- t.deepEqual(node, node.slice().sort(sort))
155
- t.deepEqual(nodeWebkit, nodeWebkit.slice().sort(sort))
160
+ t.deepEqual(electron, electron.slice().sort(sort), 'electron targets are sorted')
161
+ t.deepEqual(node, node.slice().sort(sort), 'node targets are sorted')
162
+ t.deepEqual(nodeWebkit, nodeWebkit.slice().sort(sort), 'node-webkit targets are sorted')
156
163
  t.end()
157
164
  })