Skip to content

Commit

Permalink
fix: ABI registry updater (electron#95)
Browse files Browse the repository at this point in the history
* fix: ABI registry updater

* fix: update ABI registry

* chore: add different lock files to .gitignore

* Update test/index.js

Co-authored-by: Mark Lee <[email protected]>

* refactor: move ABI filtering to fetchAbiVersions

* refactor: extract processing of electron targets to a standalone function

* chore: update ABI registry

* refactor: format matching target in getTarget

* fix: detection of the correct ABI versions for Node v13, v12 and v11

* refactor: derivation of node targets

* fix: sorting of node + electron targets

Co-authored-by: Mark Lee <[email protected]>
  • Loading branch information
vecerek and malept authored Nov 17, 2020
1 parent 9851a5f commit 65c4a08
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 101 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ jspm_packages

# Optional REPL history
.node_repl_history

# lock files
yarn.lock
package-lock.json
96 changes: 48 additions & 48 deletions abi_registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
]
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
Expand Down
116 changes: 68 additions & 48 deletions scripts/update-abi-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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))
}
Expand Down
12 changes: 11 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 65c4a08

Please sign in to comment.