Skip to content

Commit 18f99e2

Browse files
committed
test and support older versions of node
1 parent c3cdc2d commit 18f99e2

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
container: "node:${{matrix.node}}"
1414
strategy:
1515
matrix:
16-
node: ["16"]
16+
node: ["12", "14", "16"]
1717
services:
1818
redis-single-instance:
1919
image: redis

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
"prepare": "yarn build",
5757
"prepublishOnly": "yarn install && yarn lint && yarn build && yarn test"
5858
},
59-
"dependencies": {},
59+
"dependencies": {
60+
"node-abort-controller": "^2.0.0"
61+
},
6062
"type": "module",
6163
"exports": "./dist/index.js"
6264
}

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { randomBytes, createHash } from "crypto";
22
import { EventEmitter } from "events";
33

4+
// AbortController became available as a global in node version 16. Once version
5+
// 14 reaches its end-of-life, this can be removed.
6+
import PolyfillAbortController from "node-abort-controller";
7+
48
import { Redis as IORedisClient } from "ioredis";
59
type Client = IORedisClient;
610

@@ -679,7 +683,11 @@ export default class Redlock extends EventEmitter {
679683
// The AbortController/AbortSignal pattern allows the routine to be notified
680684
// of a failure to extend the lock, and subsequent expiration. In the event
681685
// of an abort, the error object will be made available at `signal.error`.
682-
const controller = new AbortController();
686+
const controller =
687+
typeof AbortController === "undefined"
688+
? new PolyfillAbortController()
689+
: new AbortController();
690+
683691
const signal = controller.signal as RedlockAbortSignal;
684692

685693
function queue(): void {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"lib": ["es2020"],
4-
"target": "es2020",
4+
"target": "es2018",
55
"module": "es2020",
66
"outDir": "./dist",
77
"declaration": true,

0 commit comments

Comments
 (0)