From 257701d01c50e0539df2fb8ac005cf0f5e78faac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Thu, 24 Sep 2020 16:43:26 +0200 Subject: [PATCH 01/11] fix: ABI registry updater --- scripts/update-abi-registry.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/update-abi-registry.js b/scripts/update-abi-registry.js index 2e56c21..a9d7a93 100644 --- a/scripts/update-abi-registry.js +++ b/scripts/update-abi-registry.js @@ -55,7 +55,7 @@ async function main () { let target if (abiVersion.runtime === 'node') { - const nodeVersion = `${abiVersion.versions.replace('.0.0-pre', '')}.0.0` + const nodeVersion = abiVersion.versions.replace('-pre', '') target = nodeVersions[nodeVersion] if (!target) { continue @@ -76,7 +76,6 @@ async function main () { } } } - target.abi = abiVersion.modules.toString() const key = [target.runtime, target.target].join('-') if (abiVersionSet.has(key)) { @@ -84,7 +83,10 @@ async function main () { } abiVersionSet.add(key) - supportedTargets.unshift(target) + supportedTargets.unshift({ + ...target, + abi: abiVersion.modules.toString() + }) } await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2)) From 42f98bb70a3ed03773acd9f1fbb11cd90621f02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Thu, 24 Sep 2020 17:01:48 +0200 Subject: [PATCH 02/11] fix: update ABI registry --- abi_registry.json | 27 ++++++++++----------------- test/index.js | 9 +++++++-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/abi_registry.json b/abi_registry.json index a475752..0199227 100644 --- a/abi_registry.json +++ b/abi_registry.json @@ -1,11 +1,4 @@ [ - { - "runtime": "node", - "target": "11.0.0", - "lts": false, - "future": false, - "abi": "67" - }, { "runtime": "electron", "target": "5.0.0", @@ -21,7 +14,7 @@ "2020-11-30" ], "future": false, - "abi": "68" + "abi": "71" }, { "runtime": "electron", @@ -49,7 +42,7 @@ "target": "13.0.0", "lts": false, "future": false, - "abi": "74" + "abi": "78" }, { "runtime": "electron", @@ -58,6 +51,13 @@ "future": false, "abi": "80" }, + { + "runtime": "electron", + "target": "10.0.0", + "lts": false, + "future": false, + "abi": "82" + }, { "runtime": "node", "target": "14.0.0", @@ -66,14 +66,7 @@ "2021-10-19" ], "future": false, - "abi": "81" - }, - { - "runtime": "electron", - "target": "10.0.0", - "lts": false, - "future": false, - "abi": "82" + "abi": "83" }, { "runtime": "electron", diff --git a/test/index.js b/test/index.js index 2cdbefa..5117621 100644 --- a/test/index.js +++ b/test/index.js @@ -26,6 +26,8 @@ test('getTarget calculates correct Node target', function (t) { t.equal(getTarget('47'), '5.0.0') t.equal(getTarget('48'), '6.0.0') t.equal(getTarget('51'), '7.0.0') + t.equal(getTarget('71'), '12.0.0') + t.equal(getTarget('83'), '14.0.0') t.end() }) @@ -36,6 +38,7 @@ test('getTarget calculates correct Electron target', function (t) { t.equal(getTarget('49', 'electron'), '1.3.0') t.equal(getTarget('50', 'electron'), '1.4.0') t.equal(getTarget('76', 'electron'), '8.0.0') + t.equal(getTarget('82', 'electron'), '10.0.0') t.end() }) @@ -54,7 +57,9 @@ test('getAbi calculates correct Node ABI', function (t) { t.equal(getAbi(null), process.versions.modules) t.throws(function () { getAbi('a.b.c') }) t.throws(function () { getAbi(getNextTarget('node')) }) - t.equal(getAbi('12.0.0'), '68') + t.equal(getAbi('14.0.0'), '83') + t.equal(getAbi('13.0.0'), '78') + t.equal(getAbi('12.0.0'), '71') t.equal(getAbi('7.2.0'), '51') t.equal(getAbi('7.0.0'), '51') t.equal(getAbi('6.9.9'), '48') @@ -90,7 +95,7 @@ test('getAbi calculates correct Node ABI', function (t) { test('getAbi calculates correct Electron ABI', function (t) { t.throws(function () { getAbi(undefined, 'electron') }) t.throws(function () { getAbi(getNextTarget('electron'), 'electron') }) - t.equal(getAbi('10.0.0-beta.1', 'electron'), '82') + t.equal(getAbi('10.0.0', 'electron'), '82') t.equal(getAbi('9.0.0', 'electron'), '80') t.equal(getAbi('8.0.0', 'electron'), '76') t.equal(getAbi('7.0.0', 'electron'), '75') From 894ed67e730f01d81c916feef66af017a94bd9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Thu, 24 Sep 2020 17:04:39 +0200 Subject: [PATCH 03/11] chore: add different lock files to .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 5148e52..e632135 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,7 @@ jspm_packages # Optional REPL history .node_repl_history + +# lock files +yarn.lock +package-lock.json From 3e0b4300327fdf82f12fff643aad22a59cd17a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Thu, 1 Oct 2020 22:43:22 +0200 Subject: [PATCH 04/11] Update test/index.js Co-authored-by: Mark Lee --- test/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/index.js b/test/index.js index 5117621..9d9d83d 100644 --- a/test/index.js +++ b/test/index.js @@ -95,6 +95,7 @@ test('getAbi calculates correct Node ABI', function (t) { test('getAbi calculates correct Electron ABI', function (t) { t.throws(function () { getAbi(undefined, 'electron') }) t.throws(function () { getAbi(getNextTarget('electron'), 'electron') }) + t.equal(getAbi('10.0.0-beta.1', 'electron'), '82') t.equal(getAbi('10.0.0', 'electron'), '82') t.equal(getAbi('9.0.0', 'electron'), '80') t.equal(getAbi('8.0.0', 'electron'), '76') From 6eb4db33fb665e0fff187197fd64b8e997264421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Sat, 24 Oct 2020 08:43:05 +0200 Subject: [PATCH 05/11] refactor: move ABI filtering to fetchAbiVersions --- scripts/update-abi-registry.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/update-abi-registry.js b/scripts/update-abi-registry.js index a9d7a93..1c53a38 100644 --- a/scripts/update-abi-registry.js +++ b/scripts/update-abi-registry.js @@ -34,7 +34,9 @@ async function fetchNodeVersions () { } async function fetchAbiVersions () { - return (await getJSONFromCDN('nodejs/node/doc/abi_version_registry.json')).NODE_MODULE_VERSION + return (await getJSONFromCDN('nodejs/node/doc/abi_version_registry.json')) + .NODE_MODULE_VERSION + .filter(({ modules }) => modules > 66) } async function main () { @@ -45,10 +47,7 @@ async function main () { const abiVersionSet = new Set() const supportedTargets = [] for (const abiVersion of abiVersions) { - if (abiVersion.modules <= 66) { - // Don't try to parse any ABI versions older than 60 - break - } else if (abiVersion.runtime === 'electron' && abiVersion.modules < 70) { + if (abiVersion.runtime === 'electron' && abiVersion.modules < 70) { // Don't try to parse Electron ABI versions below Electron 5 continue } From 250d7d7b38da4f01cfa75f2ed7a9b693aa6830d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Sat, 24 Oct 2020 10:02:39 +0200 Subject: [PATCH 06/11] refactor: extract processing of electron targets to a standalone function --- scripts/update-abi-registry.js | 59 ++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/scripts/update-abi-registry.js b/scripts/update-abi-registry.js index 1c53a38..d494515 100644 --- a/scripts/update-abi-registry.js +++ b/scripts/update-abi-registry.js @@ -8,8 +8,8 @@ async function getJSONFromCDN (urlPath) { return JSON.parse(response.body) } -async function fetchElectronVersions () { - return (await getJSONFromCDN('electron/releases/lite.json')).map(metadata => metadata.version) +async function fetchElectronReleases () { + return (await getJSONFromCDN('electron/releases/lite.json')) } async function fetchNodeVersions () { @@ -39,19 +39,51 @@ async function fetchAbiVersions () { .filter(({ modules }) => modules > 66) } +function electronTargetsByModules(releases) { + const versions = releases.map(({ version }) => version) + const versionsByModules = releases + .filter(release => release.deps && Number(release.deps.modules) >= 70) + .map(({ version, deps: { modules } }) => ({ + version, + modules, + })) + .reduce( + (acc, { modules, version }) => ({ + ...acc, + [modules]: version, + }), + {} + ) + + return Object.entries(versionsByModules) + .map( + ([modules, version]) => ({ + abi: modules, + future: !versions.find( + v => { + const major = version.split(".")[0] + return semver.satisfies( + v, + /^[0-9]/.test(major) ? `>= ${major}` : major + ) + } + ), + lts: false, + runtime: 'electron', + target: version + }) + ) +} + async function main () { const nodeVersions = await fetchNodeVersions() const abiVersions = await fetchAbiVersions() - const electronVersions = await fetchElectronVersions() + const electronReleases = await fetchElectronReleases() + const electronTargets = electronTargetsByModules(electronReleases) const abiVersionSet = new Set() const supportedTargets = [] for (const abiVersion of abiVersions) { - if (abiVersion.runtime === 'electron' && abiVersion.modules < 70) { - // Don't try to parse Electron ABI versions below Electron 5 - continue - } - let target if (abiVersion.runtime === 'node') { const nodeVersion = abiVersion.versions.replace('-pre', '') @@ -67,12 +99,7 @@ async function main () { future: false } if (target.runtime === 'electron') { - target.target = `${target.target}.0.0` - const constraint = /^[0-9]/.test(abiVersion.versions) ? `>= ${abiVersion.versions}` : abiVersion.versions - if (!electronVersions.find(electronVersion => semver.satisfies(electronVersion, constraint))) { - target.target = `${target.target}-beta.1` - target.future = true - } + continue } } @@ -88,6 +115,10 @@ async function main () { }) } + for (const electronTarget of electronTargets) { + supportedTargets.push(electronTarget) + } + await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2)) } From 9fbcb64ae783247d8c65acec04dc5e68b47de281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Sat, 24 Oct 2020 10:04:05 +0200 Subject: [PATCH 07/11] chore: update ABI registry --- abi_registry.json | 94 +++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/abi_registry.json b/abi_registry.json index 0199227..9777e9b 100644 --- a/abi_registry.json +++ b/abi_registry.json @@ -1,11 +1,4 @@ [ - { - "runtime": "electron", - "target": "5.0.0", - "lts": false, - "future": false, - "abi": "70" - }, { "runtime": "node", "target": "12.0.0", @@ -17,76 +10,83 @@ "abi": "71" }, { - "runtime": "electron", - "target": "6.0.0", + "runtime": "node", + "target": "13.0.0", "lts": false, "future": false, - "abi": "73" + "abi": "78" }, { - "runtime": "electron", - "target": "7.0.0", - "lts": false, + "runtime": "node", + "target": "14.0.0", + "lts": [ + "2020-10-27", + "2021-10-19" + ], "future": false, - "abi": "75" + "abi": "83" }, { - "runtime": "electron", - "target": "8.0.0", + "runtime": "node", + "target": "15.0.0", "lts": false, "future": false, - "abi": "76" + "abi": "88" }, { - "runtime": "node", - "target": "13.0.0", - "lts": false, + "abi": "70", "future": false, - "abi": "78" + "lts": false, + "runtime": "electron", + "target": "5.0.0-beta.9" }, { - "runtime": "electron", - "target": "9.0.0", - "lts": false, + "abi": "73", "future": false, - "abi": "80" + "lts": false, + "runtime": "electron", + "target": "6.0.0-beta.1" }, { - "runtime": "electron", - "target": "10.0.0", - "lts": false, + "abi": "75", "future": false, - "abi": "82" + "lts": false, + "runtime": "electron", + "target": "7.0.0-beta.1" }, { - "runtime": "node", - "target": "14.0.0", - "lts": [ - "2020-10-27", - "2021-10-19" - ], + "abi": "76", "future": false, - "abi": "83" + "lts": false, + "runtime": "electron", + "target": "8.0.0-beta.1" }, { - "runtime": "electron", - "target": "11.0.0-beta.1", + "abi": "80", + "future": false, "lts": false, - "future": true, - "abi": "85" + "runtime": "electron", + "target": "9.0.0-beta.2" }, { - "runtime": "node", - "target": "15.0.0", - "lts": false, + "abi": "82", "future": false, - "abi": "84" + "lts": false, + "runtime": "electron", + "target": "10.0.0-beta.1" }, { - "runtime": "electron", - "target": "12.0.0-beta.1", + "abi": "85", + "future": true, "lts": false, + "runtime": "electron", + "target": "11.0.0-beta.11" + }, + { + "abi": "87", "future": true, - "abi": "87" + "lts": false, + "runtime": "electron", + "target": "12.0.0-nightly.20201013" } ] \ No newline at end of file From 2052e95325f887cf007fd7b0c19ee9a0e25fadba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Sat, 24 Oct 2020 10:04:37 +0200 Subject: [PATCH 08/11] refactor: format matching target in getTarget --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8a25f25..0fbcd45 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,12 @@ function getTarget (abi, runtime) { .map(function (t) { return t.target }) - if (match.length) return match[0] + if (match.length) { + var betaSeparatorIndex = match[0].indexOf("-") + return betaSeparatorIndex > -1 + ? match[0].substring(0, betaSeparatorIndex) + : match[0] + } throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime) } From 6db0b32fbf985432e5d6b73f844342d6c48f9e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Sat, 31 Oct 2020 09:07:35 +0100 Subject: [PATCH 09/11] fix: detection of the correct ABI versions for Node v13, v12 and v11 --- abi_registry.json | 11 +++++++++-- scripts/update-abi-registry.js | 2 +- test/index.js | 10 +++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/abi_registry.json b/abi_registry.json index 9777e9b..94e3d44 100644 --- a/abi_registry.json +++ b/abi_registry.json @@ -1,4 +1,11 @@ [ + { + "runtime": "node", + "target": "11.0.0", + "lts": false, + "future": false, + "abi": "67" + }, { "runtime": "node", "target": "12.0.0", @@ -7,14 +14,14 @@ "2020-11-30" ], "future": false, - "abi": "71" + "abi": "72" }, { "runtime": "node", "target": "13.0.0", "lts": false, "future": false, - "abi": "78" + "abi": "79" }, { "runtime": "node", diff --git a/scripts/update-abi-registry.js b/scripts/update-abi-registry.js index d494515..fafb0e8 100644 --- a/scripts/update-abi-registry.js +++ b/scripts/update-abi-registry.js @@ -86,7 +86,7 @@ async function main () { for (const abiVersion of abiVersions) { let target if (abiVersion.runtime === 'node') { - const nodeVersion = abiVersion.versions.replace('-pre', '') + const { version: nodeVersion } = semver.coerce(abiVersion.versions) target = nodeVersions[nodeVersion] if (!target) { continue diff --git a/test/index.js b/test/index.js index 9d9d83d..e14cd6f 100644 --- a/test/index.js +++ b/test/index.js @@ -26,8 +26,10 @@ test('getTarget calculates correct Node target', function (t) { t.equal(getTarget('47'), '5.0.0') t.equal(getTarget('48'), '6.0.0') t.equal(getTarget('51'), '7.0.0') - t.equal(getTarget('71'), '12.0.0') + t.equal(getTarget('67'), '11.0.0') + t.equal(getTarget('72'), '12.0.0') t.equal(getTarget('83'), '14.0.0') + t.equal(getTarget('88'), '15.0.0') t.end() }) @@ -57,9 +59,11 @@ test('getAbi calculates correct Node ABI', function (t) { t.equal(getAbi(null), process.versions.modules) t.throws(function () { getAbi('a.b.c') }) t.throws(function () { getAbi(getNextTarget('node')) }) + t.equal(getAbi('15.0.0'), '88') t.equal(getAbi('14.0.0'), '83') - t.equal(getAbi('13.0.0'), '78') - t.equal(getAbi('12.0.0'), '71') + t.equal(getAbi('13.0.0'), '79') + t.equal(getAbi('12.0.0'), '72') + t.equal(getAbi('11.0.0'), '67') t.equal(getAbi('7.2.0'), '51') t.equal(getAbi('7.0.0'), '51') t.equal(getAbi('6.9.9'), '48') From 58175754725eec330ef8f4a4ac8932a969c61595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Sat, 31 Oct 2020 10:57:52 +0100 Subject: [PATCH 10/11] refactor: derivation of node targets --- scripts/update-abi-registry.js | 68 ++++++++++++++-------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/scripts/update-abi-registry.js b/scripts/update-abi-registry.js index fafb0e8..58e3a47 100644 --- a/scripts/update-abi-registry.js +++ b/scripts/update-abi-registry.js @@ -39,7 +39,7 @@ async function fetchAbiVersions () { .filter(({ modules }) => modules > 66) } -function electronTargetsByModules(releases) { +function electronReleasesToTargets (releases) { const versions = releases.map(({ version }) => version) const versionsByModules = releases .filter(release => release.deps && Number(release.deps.modules) >= 70) @@ -75,49 +75,37 @@ function electronTargetsByModules(releases) { ) } +function nodeVersionsToTargets (abiVersions, nodeVersions) { + return Object.values( + abiVersions + .filter(({ runtime }) => runtime === 'node') + .reduce( + (acc, abiVersion) => { + const { version: nodeVersion } = semver.coerce(abiVersion.versions) + + return { + [nodeVersion]: { + ...nodeVersions[nodeVersion], + abi: abiVersion.modules.toString(), + }, + ...acc, + }; + }, + {} + ) + ) +} + async function main () { const nodeVersions = await fetchNodeVersions() const abiVersions = await fetchAbiVersions() const electronReleases = await fetchElectronReleases() - const electronTargets = electronTargetsByModules(electronReleases) - - const abiVersionSet = new Set() - const supportedTargets = [] - for (const abiVersion of abiVersions) { - let target - if (abiVersion.runtime === 'node') { - const { version: nodeVersion } = semver.coerce(abiVersion.versions) - target = nodeVersions[nodeVersion] - if (!target) { - continue - } - } else { - target = { - runtime: abiVersion.runtime === 'nw.js' ? 'node-webkit' : abiVersion.runtime, - target: abiVersion.versions, - lts: false, - future: false - } - if (target.runtime === 'electron') { - continue - } - } - - const key = [target.runtime, target.target].join('-') - if (abiVersionSet.has(key)) { - continue - } - - abiVersionSet.add(key) - supportedTargets.unshift({ - ...target, - abi: abiVersion.modules.toString() - }) - } - - for (const electronTarget of electronTargets) { - supportedTargets.push(electronTarget) - } + const electronTargets = electronReleasesToTargets(electronReleases) + const nodeTargets = nodeVersionsToTargets(abiVersions, nodeVersions) + const supportedTargets = [ + ...nodeTargets, + ...electronTargets, + ] await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2)) } From dc36ed463c9277b2fa08e65c2f4bb9fd215215f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ve=C4=8Derek?= Date: Sat, 31 Oct 2020 11:48:52 +0100 Subject: [PATCH 11/11] fix: sorting of node + electron targets --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0fbcd45..e93924c 100644 --- a/index.js +++ b/index.js @@ -53,6 +53,10 @@ function getTarget (abi, runtime) { throw new Error('Could not detect target for abi ' + abi + ' and runtime ' + runtime) } +function sortByTargetFn (a, b) { + return Number(a.abi) > Number(b.abi) && a.target > b.target +} + function loadGeneratedTargets () { var registry = require('./abi_registry.json') var targets = { @@ -85,9 +89,9 @@ function loadGeneratedTargets () { } }) - targets.supported.sort() - targets.additional.sort() - targets.future.sort() + targets.supported.sort(sortByTargetFn) + targets.additional.sort(sortByTargetFn) + targets.future.sort(sortByTargetFn) return targets }