Skip to content

Commit

Permalink
feat!: bump engines to Node.js 22
Browse files Browse the repository at this point in the history
BREAKING CHANGE: bumps minimum Node.js version to 22
  • Loading branch information
dsanders11 committed Feb 21, 2025
1 parent 117e620 commit a9f15fa
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 746 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-electron-abi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const nodeAbi = require('node-abi');
import nodeAbi from 'node-abi';
const abi = nodeAbi.getAbi('${{ github.event.inputs.electron-version }}', 'electron');
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20.x
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install
run: yarn install --frozen-lockfile
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ jobs:
strategy:
matrix:
node-version:
- '20.10'
- '18.18'
- '16.20'
- '14.21'
- 22.12.x
os:
- macos-latest
- ubuntu-latest
- windows-latest
exclude:
- os: macos-latest
node-version: '14.21'
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-abi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
token: ${{ steps.generate-token.outputs.token }}
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: '20.x'
node-version-file: '.nvmrc'
- name: Get npm cache directory
id: npm-cache
run: |
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.12
75 changes: 33 additions & 42 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var semver = require('semver')
import fs from 'node:fs';

function getNextTarget (runtime, targets) {
import semver from 'semver';

export function _getNextTarget (runtime, targets) {
if (targets == null) targets = allTargets
var latest = targets.filter(function (t) { return t.runtime === runtime }).slice(-1)[0]
var increment = runtime === 'electron' ? 'minor' : 'major'
var next = semver.inc(latest.target, increment)
const latest = targets.filter(function (t) { return t.runtime === runtime }).slice(-1)[0]
const increment = runtime === 'electron' ? 'minor' : 'major'
let next = semver.inc(latest.target, increment)
// Electron releases appear in the registry in their beta form, sometimes there is
// no active beta line. During this time we need to double bump
if (runtime === 'electron' && semver.parse(latest.target).prerelease.length) {
Expand All @@ -13,7 +15,7 @@ function getNextTarget (runtime, targets) {
return next
}

function getAbi (target, runtime) {
export function getAbi (target, runtime) {
if (target === String(Number(target))) return target
if (target) target = target.replace(/^v/, '')
if (!runtime) runtime = 'node'
Expand All @@ -23,37 +25,37 @@ function getAbi (target, runtime) {
if (target === process.versions.node) return process.versions.modules
}

var abi
var lastTarget
let abi
let lastTarget

for (var i = 0; i < allTargets.length; i++) {
var t = allTargets[i]
for (let i = 0; i < allTargets.length; i++) {
const t = allTargets[i]
if (t.runtime !== runtime) continue
if (semver.lte(t.target, target) && (!lastTarget || semver.gte(t.target, lastTarget))) {
abi = t.abi
lastTarget = t.target
}
}

if (abi && semver.lt(target, getNextTarget(runtime))) return abi
if (abi && semver.lt(target, _getNextTarget(runtime))) return abi
throw new Error('Could not detect abi for version ' + target + ' and runtime ' + runtime + '. Updating "node-abi" might help solve this issue if it is a new release of ' + runtime)
}

function getTarget (abi, runtime) {
export function getTarget (abi, runtime) {
if (abi && abi !== String(Number(abi))) return abi
if (!runtime) runtime = 'node'

if (runtime === 'node' && !abi) return process.versions.node

var match = allTargets
const match = allTargets
.filter(function (t) {
return t.abi === abi && t.runtime === runtime
})
.map(function (t) {
return t.target
})
if (match.length) {
var betaSeparatorIndex = match[0].indexOf("-")
const betaSeparatorIndex = match[0].indexOf("-")
return betaSeparatorIndex > -1
? match[0].substring(0, betaSeparatorIndex)
: match[0]
Expand All @@ -63,31 +65,31 @@ function getTarget (abi, runtime) {
}

function sortByTargetFn (a, b) {
var abiComp = Number(a.abi) - Number(b.abi)
const abiComp = Number(a.abi) - Number(b.abi)
if (abiComp !== 0) return abiComp
if (a.target < b.target) return -1
if (a.target > b.target) return 1
return 0
}

function loadGeneratedTargets () {
var registry = require('./abi_registry.json')
var targets = {
const registry = JSON.parse(fs.readFileSync('./abi_registry.json', 'utf8'))
const targets = {
supported: [],
additional: [],
future: []
}

registry.forEach(function (item) {
var target = {
const target = {
runtime: item.runtime,
target: item.target,
abi: item.abi
}
if (item.lts) {
var startDate = new Date(Date.parse(item.lts[0]))
var endDate = new Date(Date.parse(item.lts[1]))
var currentDate = new Date()
const startDate = new Date(Date.parse(item.lts[0]))
const endDate = new Date(Date.parse(item.lts[1]))
const currentDate = new Date()
target.lts = startDate < currentDate && currentDate < endDate
} else {
target.lts = false
Expand All @@ -109,9 +111,9 @@ function loadGeneratedTargets () {
return targets
}

var generatedTargets = loadGeneratedTargets()
const generatedTargets = loadGeneratedTargets()

var supportedTargets = [
export const supportedTargets = [
{runtime: 'node', target: '5.0.0', abi: '47', lts: false},
{runtime: 'node', target: '6.0.0', abi: '48', lts: false},
{runtime: 'node', target: '7.0.0', abi: '51', lts: false},
Expand All @@ -129,22 +131,20 @@ var supportedTargets = [
{runtime: 'electron', target: '2.0.0', abi: '57', lts: false},
{runtime: 'electron', target: '3.0.0', abi: '64', lts: false},
{runtime: 'electron', target: '4.0.0', abi: '64', lts: false},
{runtime: 'electron', target: '4.0.4', abi: '69', lts: false}
{runtime: 'electron', target: '4.0.4', abi: '69', lts: false},
...generatedTargets.supported
]

supportedTargets.push.apply(supportedTargets, generatedTargets.supported)

var additionalTargets = [
export const additionalTargets = [
{runtime: 'node-webkit', target: '0.13.0', abi: '47', lts: false},
{runtime: 'node-webkit', target: '0.15.0', abi: '48', lts: false},
{runtime: 'node-webkit', target: '0.18.3', abi: '51', lts: false},
{runtime: 'node-webkit', target: '0.23.0', abi: '57', lts: false},
{runtime: 'node-webkit', target: '0.26.5', abi: '59', lts: false}
{runtime: 'node-webkit', target: '0.26.5', abi: '59', lts: false},
...generatedTargets.additional
]

additionalTargets.push.apply(additionalTargets, generatedTargets.additional)

var deprecatedTargets = [
export const deprecatedTargets = [
{runtime: 'node', target: '0.2.0', abi: '1', lts: false},
{runtime: 'node', target: '0.9.1', abi: '0x000A', lts: false},
{runtime: 'node', target: '0.9.9', abi: '0x000B', lts: false},
Expand All @@ -162,18 +162,9 @@ var deprecatedTargets = [
{runtime: 'electron', target: '0.33.0', abi: '46', lts: false}
]

var futureTargets = generatedTargets.future
export const futureTargets = generatedTargets.future

var allTargets = deprecatedTargets
export const allTargets = deprecatedTargets
.concat(supportedTargets)
.concat(additionalTargets)
.concat(futureTargets)

exports.getAbi = getAbi
exports.getTarget = getTarget
exports.deprecatedTargets = deprecatedTargets
exports.supportedTargets = supportedTargets
exports.additionalTargets = additionalTargets
exports.futureTargets = futureTargets
exports.allTargets = allTargets
exports._getNextTarget = getNextTarget
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"name": "node-abi",
"version": "0.0.0-development",
"description": "Get the Node ABI for a given target and runtime, and vice versa.",
"main": "index.js",
"type": "module",
"exports": "./index.js",
"scripts": {
"test": "tape test/index.js",
"test": "node --test test/index.js",
"update-abi-registry": "node --unhandled-rejections=strict scripts/update-abi-registry.js"
},
"files": [
Expand All @@ -27,14 +28,12 @@
"url": "https://github.com/electron/node-abi/issues"
},
"homepage": "https://github.com/electron/node-abi#readme",
"devDependencies": {
"tape": "^5.3.1"
},
"devDependencies": {},
"dependencies": {
"semver": "^7.3.5"
"semver": "^7.6.3"
},
"engines": {
"node": ">=10"
"node": ">=22.12.0"
},
"publishConfig": {
"provenance": true
Expand Down
9 changes: 5 additions & 4 deletions scripts/update-abi-registry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { writeFile } = require('node:fs/promises')
const path = require('node:path')
import { writeFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url';

const semver = require('semver')
import semver from 'semver'

function sortByElectronVersionFn (a, b) {
const modulesComp = Number(a.modules) - Number(b.modules)
Expand Down Expand Up @@ -127,7 +128,7 @@ async function main () {
...electronTargets,
]

await writeFile(path.resolve(__dirname, '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2))
await writeFile(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'abi_registry.json'), JSON.stringify(supportedTargets, null, 2))
}

main()
Loading

0 comments on commit a9f15fa

Please # to comment.