Skip to content

Commit 0ebf980

Browse files
feat: add node v20 support (#105)
* feat: node v20 support * test: remove coverage check on v20 * test: ci * test: ci * test: remove coverage check on v20 * fix: ci * fix: ci * fix: ci * fix: ci
1 parent 55f75c9 commit 0ebf980

File tree

23 files changed

+107
-48
lines changed

23 files changed

+107
-48
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ jobs:
1111
ci:
1212
strategy:
1313
matrix:
14-
node-version: [22, 24]
14+
# Using the latest LTS versions for CI
15+
node-version: [20, 22, 24]
1516
os: [ubuntu-latest]
1617
# Support for 3.6.0 is not available in CI since the Docker image has issues with option management in regard of SASL/OAUTHBEARER.
1718
kafka-version: ['3.5.0', '3.7.0', '3.8.0', '3.9.0', '4.0.0']
@@ -40,6 +41,11 @@ jobs:
4041
env:
4142
KAFKA_VERSION: ${{ matrix.kafka-version }}
4243
- name: Run Tests
43-
run: pnpm run ci
44+
run: |
45+
if [ "${{ matrix.node-version }}" = "20" ]; then
46+
pnpm run test:ci:v20
47+
else
48+
pnpm run ci
49+
fi
4450
env:
4551
KAFKA_VERSION: ${{ matrix.kafka-version }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Install dependencies
4242
run: pnpm install
4343
- name: Bump Version
44-
run: node --experimental-strip-types --disable-warning=ExperimentalWarning scripts/bump-version.ts "${{ inputs.version }}" "${{ github.actor }}"
44+
run: node scripts/bump-version.ts "${{ inputs.version }}" "${{ github.actor }}"
4545
env:
4646
GITHUB_ACTIONS: 'true'
4747
- name: Push changes

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ external/
33
node_modules
44
coverage
55
.eslintcache
6+
.env

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ npm run lint
3232

3333
## Node Requirements
3434

35-
- Node.js >= 22.14.0
35+
- Node.js >= 20.19.4 or >= 22.18.0 or >= 24.6.0

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,28 @@ Many of the methods accept the same options as the client's constructors. The co
281281

282282
## Requirements
283283

284-
- Node.js >= 22.14.0
284+
Node.js LTS versions:
285+
286+
- `20.19.4` or above
287+
- `22.18.0` or above
288+
- `24.6.0` or above
289+
290+
## Testing
291+
292+
To setup the local environment for testing
293+
294+
```bash
295+
cd docker
296+
cp .env.sample .env
297+
```
298+
299+
Edit .env file as needed, enabling or not `JAVA_OPTIONS`
300+
301+
Start Kafka cluster locally
302+
303+
```bash
304+
docker compose -f compose-local.yml up -d
305+
```
285306

286307
## License
287308

benchmarks/consumer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import RDKafka from '@platformatic/rdkafka'
22
import { printResults, Tracker, type Result } from 'cronometro'
33
import { Kafka as KafkaJS, logLevel } from 'kafkajs'
44
import { randomUUID } from 'node:crypto'
5-
import { Consumer, MessagesStreamModes } from '../src/index.ts'
5+
import { Consumer, MessagesStreamModes, PromiseWithResolvers } from '../src/index.ts'
66
import { brokers, topic } from './utils/definitions.ts'
77

88
const iterations = 10000
99

1010
function rdkafkaEvented (): Promise<Result> {
11-
const { promise, resolve, reject } = Promise.withResolvers<Result>()
11+
const { promise, resolve, reject } = PromiseWithResolvers<Result>()
1212
const tracker = new Tracker()
1313

1414
const consumer = new RDKafka.KafkaConsumer(
@@ -68,7 +68,7 @@ function rdkafkaEvented (): Promise<Result> {
6868
}
6969

7070
function rdkafkaStream (): Promise<Result> {
71-
const { promise, resolve, reject } = Promise.withResolvers<Result>()
71+
const { promise, resolve, reject } = PromiseWithResolvers<Result>()
7272
const tracker = new Tracker()
7373

7474
const stream = RDKafka.KafkaConsumer.createReadStream(
@@ -107,7 +107,7 @@ function rdkafkaStream (): Promise<Result> {
107107
}
108108

109109
async function kafkajs (): Promise<Result> {
110-
const { promise, resolve, reject } = Promise.withResolvers<Result>()
110+
const { promise, resolve, reject } = PromiseWithResolvers<Result>()
111111
const tracker = new Tracker()
112112

113113
const client = new KafkaJS({ clientId: 'benchmarks', brokers, logLevel: logLevel.ERROR })
@@ -140,7 +140,7 @@ async function kafkajs (): Promise<Result> {
140140
}
141141

142142
async function platformaticKafka (): Promise<Result> {
143-
const { promise, resolve, reject } = Promise.withResolvers<Result>()
143+
const { promise, resolve, reject } = PromiseWithResolvers<Result>()
144144
const tracker = new Tracker()
145145

146146
const consumer = new Consumer({

benchmarks/producer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import RDKafka from '@platformatic/rdkafka'
22
import { printResults, Tracker, type Result } from 'cronometro'
33
import { Kafka as KafkaJS } from 'kafkajs'
4-
import { ProduceAcks, Producer, stringSerializers } from '../src/index.ts'
4+
import { ProduceAcks, Producer, PromiseWithResolvers, stringSerializers } from '../src/index.ts'
55
import { brokers, topic } from './utils/definitions.ts'
66

77
const iterations = 10000
88
const batchSize = Math.max(iterations / 100, 1)
99

1010
function rdkafka (): Promise<Result> {
11-
const { promise, resolve, reject } = Promise.withResolvers<Result>()
11+
const { promise, resolve, reject } = PromiseWithResolvers<Result>()
1212
const tracker = new Tracker()
1313

1414
const producer = new RDKafka.Producer(

docker/.env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# See supported versions in .github/workflows/ci.yml
2+
KAFKA_VERSION=3.7
3+
4+
# Needed for Docker on Apple Silicon
5+
# Disable if not needed, for example in Ubuntu
6+
# JAVA_OPTIONS='-XX:UseSVE=0'

docker/compose-local.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ services:
3434
# Consumer group options
3535
KAFKA_CFG_GROUP_COORDINATOR_REBALANCE_PROTOCOLS: 'classic,consumer'
3636
KAFKA_CFG_GROUP_INITIAL_REBALANCE_DELAY_MS: '0'
37-
# Do not use this in GitHub CI - Needed for Docker on Apple Silicon
38-
_JAVA_OPTIONS: '-XX:UseSVE=0'
37+
_JAVA_OPTIONS: ${JAVA_OPTIONS}
3938

4039
broker-cluster-2:
4140
image: bitnami/kafka:${KAFKA_VERSION}

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"types": "./dist/index.d.ts",
2727
"scripts": {
2828
"build": "rm -rf dist && tsc -p tsconfig.base.json",
29-
"postbuild": "node --experimental-strip-types scripts/postbuild.ts",
29+
"postbuild": "node scripts/postbuild.ts",
3030
"lint": "eslint --cache",
3131
"typecheck": "tsc -p . --noEmit",
3232
"format": "prettier -w benchmarks playground src test",
@@ -37,9 +37,13 @@
3737
"ci": "npm run build && npm run lint && npm run test:ci",
3838
"prepublishOnly": "npm run build && npm run lint",
3939
"postpublish": "git push origin && git push origin -f --tags",
40-
"generate:apis": "node --experimental-strip-types scripts/generate-apis.ts",
41-
"generate:errors": "node --experimental-strip-types scripts/generate-errors.ts",
42-
"create:api": "node --experimental-strip-types scripts/create-api.ts"
40+
"generate:apis": "node scripts/generate-apis.ts",
41+
"generate:errors": "node scripts/generate-errors.ts",
42+
"create:api": "node scripts/create-api.ts",
43+
"build:v20": "rm -rf dist && tsc -p tsconfig.json",
44+
"postbuild:v20": "cp package.json dist/package.json && node dist/scripts/postbuild.js",
45+
"test:v20": "npm run build:v20 && cp -R test/fixtures dist/test/fixtures && node --env-file=test/config/env --no-warnings --test --test-timeout=300000 dist/test/**/*.test.js",
46+
"test:ci:v20": "npm run build:v20 && cp -R test/fixtures dist/test/fixtures && node --env-file=test/config/env --no-warnings --test --test-timeout=300000 dist/test/**/*.test.js"
4347
},
4448
"dependencies": {
4549
"ajv": "^8.17.1",
@@ -55,7 +59,7 @@
5559
"devDependencies": {
5660
"@platformatic/rdkafka": "^4.0.0",
5761
"@types/debug": "^4.1.12",
58-
"@types/node": "^22.13.5",
62+
"@types/node": "^22.17.2",
5963
"@types/semver": "^7.7.0",
6064
"@watchable/unpromise": "^1.0.2",
6165
"avsc": "^5.7.7",
@@ -78,6 +82,6 @@
7882
"typescript": "^5.7.3"
7983
},
8084
"engines": {
81-
"node": ">= 22.14.0"
85+
"node": ">= 20.19.4 || >= 22.18.0 || >= 24.6.0"
8286
}
8387
}

0 commit comments

Comments
 (0)