Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: bump engines to Node.js 22 #199

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 22.x
cache: 'yarn'
- name: Install
run: yarn install --frozen-lockfile
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ jobs:
strategy:
matrix:
node-version:
- '20.10'
- '18.18'
- '16.20'
- '14.21'
- '22.x'
- '22.0.0'
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: '22.x'
- 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
46 changes: 23 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var semver = require('semver')
const semver = require('semver')

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 @@ -23,11 +23,11 @@ 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
Expand All @@ -45,15 +45,15 @@ function getTarget (abi, runtime) {

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 +63,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 = require('./abi_registry.json')
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 +109,9 @@ function loadGeneratedTargets () {
return targets
}

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

var supportedTargets = [
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 @@ -134,7 +134,7 @@ var supportedTargets = [

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

var additionalTargets = [
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},
Expand All @@ -144,7 +144,7 @@ var additionalTargets = [

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

var deprecatedTargets = [
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,9 +162,9 @@ var deprecatedTargets = [
{runtime: 'electron', target: '0.33.0', abi: '46', lts: false}
]

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

var allTargets = deprecatedTargets
const allTargets = deprecatedTargets
.concat(supportedTargets)
.concat(additionalTargets)
.concat(futureTargets)
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Get the Node ABI for a given target and runtime, and vice versa.",
"main": "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 +27,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.0.0"
},
"publishConfig": {
"provenance": true
Expand Down
Loading
Loading