node-abi 2.18.0 → 2.19.3

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,99 @@
1
+ [
2
+ {
3
+ "runtime": "node",
4
+ "target": "11.0.0",
5
+ "lts": false,
6
+ "future": false,
7
+ "abi": "67"
8
+ },
9
+ {
10
+ "runtime": "node",
11
+ "target": "12.0.0",
12
+ "lts": [
13
+ "2019-10-21",
14
+ "2020-11-30"
15
+ ],
16
+ "future": false,
17
+ "abi": "72"
18
+ },
19
+ {
20
+ "runtime": "node",
21
+ "target": "13.0.0",
22
+ "lts": false,
23
+ "future": false,
24
+ "abi": "79"
25
+ },
26
+ {
27
+ "runtime": "node",
28
+ "target": "14.0.0",
29
+ "lts": [
30
+ "2020-10-27",
31
+ "2021-10-19"
32
+ ],
33
+ "future": false,
34
+ "abi": "83"
35
+ },
36
+ {
37
+ "runtime": "node",
38
+ "target": "15.0.0",
39
+ "lts": false,
40
+ "future": false,
41
+ "abi": "88"
42
+ },
43
+ {
44
+ "abi": "70",
45
+ "future": false,
46
+ "lts": false,
47
+ "runtime": "electron",
48
+ "target": "5.0.0-beta.9"
49
+ },
50
+ {
51
+ "abi": "73",
52
+ "future": false,
53
+ "lts": false,
54
+ "runtime": "electron",
55
+ "target": "6.0.0-beta.1"
56
+ },
57
+ {
58
+ "abi": "75",
59
+ "future": false,
60
+ "lts": false,
61
+ "runtime": "electron",
62
+ "target": "7.0.0-beta.1"
63
+ },
64
+ {
65
+ "abi": "76",
66
+ "future": false,
67
+ "lts": false,
68
+ "runtime": "electron",
69
+ "target": "8.0.0-beta.1"
70
+ },
71
+ {
72
+ "abi": "80",
73
+ "future": false,
74
+ "lts": false,
75
+ "runtime": "electron",
76
+ "target": "9.0.0-beta.2"
77
+ },
78
+ {
79
+ "abi": "82",
80
+ "future": false,
81
+ "lts": false,
82
+ "runtime": "electron",
83
+ "target": "10.0.0-beta.1"
84
+ },
85
+ {
86
+ "abi": "85",
87
+ "future": false,
88
+ "lts": false,
89
+ "runtime": "electron",
90
+ "target": "11.0.0-beta.11"
91
+ },
92
+ {
93
+ "abi": "87",
94
+ "future": true,
95
+ "lts": false,
96
+ "runtime": "electron",
97
+ "target": "12.0.0-nightly.20201013"
98
+ }
99
+ ]
package/index.js CHANGED
@@ -43,11 +43,65 @@ 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
+
64
+ function loadGeneratedTargets () {
65
+ var registry = require('./abi_registry.json')
66
+ var targets = {
67
+ supported: [],
68
+ additional: [],
69
+ future: []
70
+ }
71
+
72
+ registry.forEach(function (item) {
73
+ var target = {
74
+ runtime: item.runtime,
75
+ target: item.target,
76
+ abi: item.abi
77
+ }
78
+ if (item.lts) {
79
+ var startDate = new Date(Date.parse(item.lts[0]))
80
+ var endDate = new Date(Date.parse(item.lts[1]))
81
+ var currentDate = new Date()
82
+ target.lts = startDate < currentDate && currentDate < endDate
83
+ } else {
84
+ target.lts = false
85
+ }
86
+
87
+ if (target.runtime === 'node-webkit') {
88
+ targets.additional.push(target)
89
+ } else if (item.future) {
90
+ targets.future.push(target)
91
+ } else {
92
+ targets.supported.push(target)
93
+ }
94
+ })
95
+
96
+ targets.supported.sort(sortByTargetFn)
97
+ targets.additional.sort(sortByTargetFn)
98
+ targets.future.sort(sortByTargetFn)
99
+
100
+ return targets
101
+ }
102
+
103
+ var generatedTargets = loadGeneratedTargets()
104
+
51
105
  var supportedTargets = [
52
106
  {runtime: 'node', target: '5.0.0', abi: '47', lts: false},
53
107
  {runtime: 'node', target: '6.0.0', abi: '48', lts: false},
@@ -55,10 +109,6 @@ var supportedTargets = [
55
109
  {runtime: 'node', target: '8.0.0', abi: '57', lts: false},
56
110
  {runtime: 'node', target: '9.0.0', abi: '59', lts: false},
57
111
  {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
112
  {runtime: 'electron', target: '0.36.0', abi: '47', lts: false},
63
113
  {runtime: 'electron', target: '1.1.0', abi: '48', lts: false},
64
114
  {runtime: 'electron', target: '1.3.0', abi: '49', lts: false},
@@ -70,14 +120,11 @@ var supportedTargets = [
70
120
  {runtime: 'electron', target: '2.0.0', abi: '57', lts: false},
71
121
  {runtime: 'electron', target: '3.0.0', abi: '64', lts: false},
72
122
  {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},
78
- {runtime: 'electron', target: '9.0.0', abi: '80', lts: false}
123
+ {runtime: 'electron', target: '4.0.4', abi: '69', lts: false}
79
124
  ]
80
125
 
126
+ supportedTargets.push.apply(supportedTargets, generatedTargets.supported)
127
+
81
128
  var additionalTargets = [
82
129
  {runtime: 'node-webkit', target: '0.13.0', abi: '47', lts: false},
83
130
  {runtime: 'node-webkit', target: '0.15.0', abi: '48', lts: false},
@@ -86,6 +133,8 @@ var additionalTargets = [
86
133
  {runtime: 'node-webkit', target: '0.26.5', abi: '59', lts: false}
87
134
  ]
88
135
 
136
+ additionalTargets.push.apply(additionalTargets, generatedTargets.additional)
137
+
89
138
  var deprecatedTargets = [
90
139
  {runtime: 'node', target: '0.2.0', abi: '1', lts: false},
91
140
  {runtime: 'node', target: '0.9.1', abi: '0x000A', lts: false},
@@ -104,9 +153,7 @@ var deprecatedTargets = [
104
153
  {runtime: 'electron', target: '0.33.0', abi: '46', lts: false}
105
154
  ]
106
155
 
107
- var futureTargets = [
108
- {runtime: 'electron', target: '10.0.0-beta.1', abi: '82', lts: false}
109
- ]
156
+ var futureTargets = generatedTargets.future
110
157
 
111
158
  var allTargets = deprecatedTargets
112
159
  .concat(supportedTargets)
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "node-abi",
3
- "version": "2.18.0",
3
+ "version": "2.19.3",
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,113 @@
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 fetchElectronReleases () {
12
+ return (await getJSONFromCDN('electron/releases/lite.json'))
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'))
38
+ .NODE_MODULE_VERSION
39
+ .filter(({ modules }) => modules > 66)
40
+ }
41
+
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
+ )
57
+
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
+ }
77
+
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)
85
+
86
+ return {
87
+ [nodeVersion]: {
88
+ ...nodeVersions[nodeVersion],
89
+ abi: abiVersion.modules.toString(),
90
+ },
91
+ ...acc,
92
+ };
93
+ },
94
+ {}
95
+ )
96
+ )
97
+ }
98
+
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
+ ]
109
+
110
+ await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2))
111
+ }
112
+
113
+ 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},
@@ -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
 
@@ -35,6 +39,8 @@ test('getTarget calculates correct Electron target', function (t) {
35
39
  t.equal(getTarget('48', 'electron'), '1.1.0')
36
40
  t.equal(getTarget('49', 'electron'), '1.3.0')
37
41
  t.equal(getTarget('50', 'electron'), '1.4.0')
42
+ t.equal(getTarget('76', 'electron'), '8.0.0')
43
+ t.equal(getTarget('82', 'electron'), '10.0.0')
38
44
  t.end()
39
45
  })
40
46
 
@@ -53,6 +59,11 @@ test('getAbi calculates correct Node ABI', function (t) {
53
59
  t.equal(getAbi(null), process.versions.modules)
54
60
  t.throws(function () { getAbi('a.b.c') })
55
61
  t.throws(function () { getAbi(getNextTarget('node')) })
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')
56
67
  t.equal(getAbi('7.2.0'), '51')
57
68
  t.equal(getAbi('7.0.0'), '51')
58
69
  t.equal(getAbi('6.9.9'), '48')
@@ -89,6 +100,7 @@ test('getAbi calculates correct Electron ABI', function (t) {
89
100
  t.throws(function () { getAbi(undefined, 'electron') })
90
101
  t.throws(function () { getAbi(getNextTarget('electron'), 'electron') })
91
102
  t.equal(getAbi('10.0.0-beta.1', 'electron'), '82')
103
+ t.equal(getAbi('10.0.0', 'electron'), '82')
92
104
  t.equal(getAbi('9.0.0', 'electron'), '80')
93
105
  t.equal(getAbi('8.0.0', 'electron'), '76')
94
106
  t.equal(getAbi('7.0.0', 'electron'), '75')
@@ -155,8 +167,8 @@ test('allTargets are sorted', function (t) {
155
167
  return semver.compare(t1.target, t2.target)
156
168
  }
157
169
 
158
- t.deepEqual(electron, electron.slice().sort(sort))
159
- t.deepEqual(node, node.slice().sort(sort))
160
- t.deepEqual(nodeWebkit, nodeWebkit.slice().sort(sort))
170
+ t.deepEqual(electron, electron.slice().sort(sort), 'electron targets are sorted')
171
+ t.deepEqual(node, node.slice().sort(sort), 'node targets are sorted')
172
+ t.deepEqual(nodeWebkit, nodeWebkit.slice().sort(sort), 'node-webkit targets are sorted')
161
173
  t.end()
162
174
  })