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 diff --git a/abi_registry.json b/abi_registry.json index a475752..94e3d44 100644 --- a/abi_registry.json +++ b/abi_registry.json @@ -6,13 +6,6 @@ "future": false, "abi": "67" }, - { - "runtime": "electron", - "target": "5.0.0", - "lts": false, - "future": false, - "abi": "70" - }, { "runtime": "node", "target": "12.0.0", @@ -21,79 +14,86 @@ "2020-11-30" ], "future": false, - "abi": "68" + "abi": "72" }, { - "runtime": "electron", - "target": "6.0.0", + "runtime": "node", + "target": "13.0.0", "lts": false, "future": false, - "abi": "73" + "abi": "79" }, { - "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": "74" + "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": "node", - "target": "14.0.0", - "lts": [ - "2020-10-27", - "2021-10-19" - ], + "abi": "75", "future": false, - "abi": "81" + "lts": false, + "runtime": "electron", + "target": "7.0.0-beta.1" }, { - "runtime": "electron", - "target": "10.0.0", - "lts": false, + "abi": "76", "future": false, - "abi": "82" + "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 diff --git a/index.js b/index.js index 8a25f25..e93924c 100644 --- a/index.js +++ b/index.js @@ -43,11 +43,20 @@ 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) } +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 = { @@ -80,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 } diff --git a/scripts/update-abi-registry.js b/scripts/update-abi-registry.js index 2e56c21..58e3a47 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 () { @@ -34,58 +34,78 @@ 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 () { - const nodeVersions = await fetchNodeVersions() - const abiVersions = await fetchAbiVersions() - const electronVersions = await fetchElectronVersions() +function electronReleasesToTargets (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, + }), + {} + ) - 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) { - // Don't try to parse Electron ABI versions below Electron 5 - continue - } + 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 + }) + ) +} - let target - if (abiVersion.runtime === 'node') { - const nodeVersion = `${abiVersion.versions.replace('.0.0-pre', '')}.0.0` - 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') { - 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 - } - } - } - target.abi = abiVersion.modules.toString() +function nodeVersionsToTargets (abiVersions, nodeVersions) { + return Object.values( + abiVersions + .filter(({ runtime }) => runtime === 'node') + .reduce( + (acc, abiVersion) => { + const { version: nodeVersion } = semver.coerce(abiVersion.versions) - const key = [target.runtime, target.target].join('-') - if (abiVersionSet.has(key)) { - continue - } + return { + [nodeVersion]: { + ...nodeVersions[nodeVersion], + abi: abiVersion.modules.toString(), + }, + ...acc, + }; + }, + {} + ) + ) +} - abiVersionSet.add(key) - supportedTargets.unshift(target) - } +async function main () { + const nodeVersions = await fetchNodeVersions() + const abiVersions = await fetchAbiVersions() + const electronReleases = await fetchElectronReleases() + 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)) } diff --git a/test/index.js b/test/index.js index 2cdbefa..e14cd6f 100644 --- a/test/index.js +++ b/test/index.js @@ -26,6 +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('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() }) @@ -36,6 +40,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 +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('12.0.0'), '68') + t.equal(getAbi('15.0.0'), '88') + t.equal(getAbi('14.0.0'), '83') + 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') @@ -91,6 +100,7 @@ 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')