Skip to content

Commit 1ae375e

Browse files
authored
Fix broken windows (#415)
Includes: - Update to ESLint 9 - Switch to vite for packaging and testing - Switch to named export (update readme) - Remove Node 16 support #411
1 parent 2f1ce8f commit 1ae375e

File tree

10 files changed

+122
-112
lines changed

10 files changed

+122
-112
lines changed

.eslintrc

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node: [16, 18, 20]
12+
node: [18, 20, 22]
1313
name: Node v${{ matrix.node }}
1414
steps:
1515
- uses: actions/checkout@v3

eslint.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import js from "@eslint/js"
2+
import prettier from "eslint-plugin-prettier/recommended"
3+
import ts from "typescript-eslint"
4+
5+
export default ts.config({
6+
extends: [js.configs.recommended, ...ts.configs.recommended, prettier],
7+
rules: {
8+
"prefer-const": 0,
9+
"@typescript-eslint/no-explicit-any": 0,
10+
"@typescript-eslint/no-unused-vars": [
11+
"error",
12+
{
13+
argsIgnorePattern: "^_",
14+
caughtErrorsIgnorePattern: "^_",
15+
destructuredArrayIgnorePattern: "^_",
16+
varsIgnorePattern: "^_",
17+
ignoreRestSiblings: true,
18+
},
19+
],
20+
},
21+
ignores: ["dist/**"],
22+
})

index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface RedisStoreOptions {
2626
disableTouch?: boolean
2727
}
2828

29-
class RedisStore extends Store {
29+
export class RedisStore extends Store {
3030
client: NormalizedRedisClient
3131
prefix: string
3232
scanCount: number
@@ -204,5 +204,3 @@ class RedisStore extends Store {
204204
return keys
205205
}
206206
}
207-
208-
export default RedisStore

index_test.ts

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,117 @@
1-
import test from "blue-tape"
21
import {Cookie} from "express-session"
32
import {Redis} from "ioredis"
43
import {promisify} from "node:util"
54
import {createClient} from "redis"
6-
import RedisStore from "./"
5+
import {expect, test} from "vitest"
6+
import {RedisStore} from "./"
77
import * as redisSrv from "./testdata/server"
88

99
test("setup", async () => {
1010
await redisSrv.connect()
1111
})
1212

13-
test("defaults", async (t) => {
13+
test("defaults", async () => {
1414
let client = createClient({url: `redis://localhost:${redisSrv.port}`})
1515
await client.connect()
1616

1717
let store = new RedisStore({client})
1818

19-
t.ok(store.client, "stores client")
20-
t.equal(store.prefix, "sess:", "defaults to sess:")
21-
t.equal(store.ttl, 86400, "defaults to one day")
22-
t.equal(store.scanCount, 100, "defaults SCAN count to 100")
23-
t.equal(store.serializer, JSON, "defaults to JSON serialization")
24-
t.equal(store.disableTouch, false, "defaults to having `touch` enabled")
25-
t.equal(store.disableTTL, false, "defaults to having `ttl` enabled")
19+
expect(store.client).toBeDefined()
20+
expect(store.prefix).toBe("sess:")
21+
expect(store.ttl).toBe(86400) // defaults to one day
22+
expect(store.scanCount).toBe(100)
23+
expect(store.serializer).toBe(JSON)
24+
expect(store.disableTouch).toBe(false)
25+
expect(store.disableTTL).toBe(false)
2626
await client.disconnect()
2727
})
2828

29-
test("redis", async (t) => {
29+
test("redis", async () => {
3030
let client = createClient({url: `redis://localhost:${redisSrv.port}`})
3131
await client.connect()
3232
let store = new RedisStore({client})
33-
await lifecycleTest(store, client, t)
33+
await lifecycleTest(store, client)
3434
await client.disconnect()
3535
})
3636

37-
test("ioredis", async (t) => {
37+
test("ioredis", async () => {
3838
let client = new Redis(`redis://localhost:${redisSrv.port}`)
3939
let store = new RedisStore({client})
40-
await lifecycleTest(store, client, t)
40+
await lifecycleTest(store, client)
4141
client.disconnect()
4242
})
4343

4444
test("teardown", redisSrv.disconnect)
4545

46-
async function lifecycleTest(
47-
store: RedisStore,
48-
client: any,
49-
t: test.Test,
50-
): Promise<void> {
46+
async function lifecycleTest(store: RedisStore, client: any): Promise<void> {
5147
const P = (f: any) => promisify(f).bind(store)
5248
let res = await P(store.clear)()
5349

5450
let sess = {foo: "bar"}
5551
await P(store.set)("123", sess)
5652

5753
res = await P(store.get)("123")
58-
t.same(res, sess, "store.get")
54+
expect(res).toEqual(sess)
5955

6056
let ttl = await client.ttl("sess:123")
61-
t.ok(ttl >= 86399, "check one day ttl")
57+
expect(ttl).toBeGreaterThanOrEqual(86399)
6258

6359
ttl = 60
6460
let expires = new Date(Date.now() + ttl * 1000).toISOString()
6561
await P(store.set)("456", {cookie: {expires}})
6662
ttl = await client.ttl("sess:456")
67-
t.ok(ttl <= 60, "check expires ttl")
63+
expect(ttl).toBeLessThanOrEqual(60)
6864

6965
ttl = 90
7066
let expires2 = new Date(Date.now() + ttl * 1000).toISOString()
7167
await P(store.touch)("456", {cookie: {expires: expires2}})
7268
ttl = await client.ttl("sess:456")
73-
t.ok(ttl > 60, "check expires ttl touch")
69+
expect(ttl).toBeGreaterThan(60)
7470

7571
res = await P(store.length)()
76-
t.equal(res, 2, "stored two keys length")
72+
expect(res).toBe(2) // stored two keys length
7773

7874
res = await P(store.ids)()
7975
res.sort()
80-
t.same(res, ["123", "456"], "stored two keys ids")
76+
expect(res).toEqual(["123", "456"])
8177

8278
res = await P(store.all)()
8379
res.sort((a: any, b: any) => (a.id > b.id ? 1 : -1))
84-
t.same(
85-
res,
86-
[
87-
{id: "123", foo: "bar"},
88-
{id: "456", cookie: {expires}},
89-
],
90-
"stored two keys data",
91-
)
80+
expect(res).toEqual([
81+
{id: "123", foo: "bar"},
82+
{id: "456", cookie: {expires}},
83+
])
9284

9385
await P(store.destroy)("456")
9486
res = await P(store.length)()
95-
t.equal(res, 1, "one key remains")
87+
expect(res).toBe(1) // one key remains
9688

9789
res = await P(store.clear)()
9890

9991
res = await P(store.length)()
100-
t.equal(res, 0, "no keys remain")
92+
expect(res).toBe(0) // no keys remain
10193

10294
let count = 1000
10395
await load(store, count)
10496

10597
res = await P(store.length)()
106-
t.equal(res, count, "bulk count")
98+
expect(res).toBe(count)
10799

108100
await P(store.clear)()
109101
res = await P(store.length)()
110-
t.equal(res, 0, "bulk clear")
102+
expect(res).toBe(0)
111103

112104
expires = new Date(Date.now() + ttl * 1000).toISOString() // expires in the future
113105
res = await P(store.set)("789", {cookie: {expires}})
114106

115107
res = await P(store.length)()
116-
t.equal(res, 1, "one key exists (session 789)")
108+
expect(res).toBe(1)
117109

118110
expires = new Date(Date.now() - ttl * 1000).toISOString() // expires in the past
119111
await P(store.set)("789", {cookie: {expires}})
120112

121113
res = await P(store.length)()
122-
t.equal(res, 0, "no key remains and that includes session 789")
114+
expect(res).toBe(0) // no key remains and that includes session 789
123115
}
124116

125117
async function load(store: RedisStore, count: number) {

package.json

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
22
"name": "connect-redis",
33
"description": "Redis session store for Connect",
4-
"version": "7.1.1",
4+
"version": "8.0.0",
55
"author": "TJ Holowaychuk <[email protected]>",
66
"contributors": [
77
"Marc Harter <[email protected]>"
88
],
99
"license": "MIT",
10-
"main": "./dist/esm/index.js",
10+
"type": "module",
11+
"main": "./dist/connect-redis.cjs",
12+
"module": "./dist/connect-redis.js",
13+
"types": "./dist/connect-redis.d.ts",
1114
"exports": {
1215
".": {
13-
"import": "./dist/esm/index.js",
14-
"require": "./dist/cjs/index.js",
15-
"default": "./dist/esm/index.js"
16+
"import": "./dist/connect-redis.js",
17+
"require": "./dist/connect-redis.cjs"
1618
}
1719
},
18-
"types": "./dist/esm/index.d.ts",
1920
"scripts": {
20-
"prepublishOnly": "rm -rf dist && tsc & tsc --project tsconfig.esm.json && echo '{\"type\":\"module\"}' > dist/esm/package.json",
21-
"build": "npm run prepublishOnly",
22-
"test": "nyc ts-node node_modules/blue-tape/bin/blue-tape \"**/*_test.ts\"",
23-
"lint": "tsc --noemit && eslint --max-warnings 0 --ext ts testdata *.ts",
21+
"prepublishOnly": "vite build",
22+
"build": "vite build",
23+
"test": "vitest run --silent --coverage",
24+
"lint": "tsc --noemit && eslint --max-warnings 0 testdata *.ts",
2425
"fmt": "prettier --write .",
2526
"fmt-check": "prettier --check ."
2627
},
@@ -29,28 +30,31 @@
2930
"url": "[email protected]:tj/connect-redis.git"
3031
},
3132
"devDependencies": {
32-
"@types/blue-tape": "^0.1.36",
33-
"@types/express-session": "^1.17.10",
34-
"@types/node": "^20.11.5",
35-
"@typescript-eslint/eslint-plugin": "^6.19.0",
36-
"@typescript-eslint/parser": "^6.19.0",
37-
"blue-tape": "^1.0.0",
38-
"eslint": "^8.56.0",
33+
"@eslint/js": "^9.15.0",
34+
"@types/eslint__js": "^8.42.3",
35+
"@types/express-session": "^1.18.1",
36+
"@types/node": "^20.17.8",
37+
"@vitest/coverage-v8": "^2.1.6",
38+
"eslint": "^9.15.0",
3939
"eslint-config-prettier": "^9.1.0",
40-
"express-session": "^1.17.3",
41-
"ioredis": "^5.3.2",
42-
"nyc": "^15.1.0",
43-
"prettier": "^3.2.4",
44-
"prettier-plugin-organize-imports": "^3.2.4",
45-
"redis": "^4.6.12",
40+
"eslint-plugin-prettier": "^5.2.1",
41+
"express-session": "^1.18.1",
42+
"ioredis": "^5.4.1",
43+
"prettier": "^3.4.1",
44+
"prettier-plugin-organize-imports": "^4.1.0",
45+
"redis": "^4.7.0",
4646
"ts-node": "^10.9.2",
47-
"typescript": "^5.3.3"
47+
"typescript": "^5.7.2",
48+
"typescript-eslint": "^8.16.0",
49+
"vite": "^6.0.1",
50+
"vite-plugin-dts": "^4.3.0",
51+
"vitest": "^2.1.6"
4852
},
4953
"peerDependencies": {
5054
"express-session": ">=1"
5155
},
5256
"engines": {
53-
"node": ">=16"
57+
"node": ">=18"
5458
},
5559
"bugs": {
5660
"url": "https://github.com/tj/connect-redis/issues"

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ npm install ioredis connect-redis express-session
2828
Import using ESM/Typescript:
2929

3030
```js
31-
import RedisStore from "connect-redis"
31+
import {RedisStore} from "connect-redis"
3232
```
3333

3434
Require using CommonJS:
3535

3636
```js
37-
const RedisStore = require("connect-redis").default
37+
const {RedisStore} = require("connect-redis")
3838
```
3939

4040
## API
4141

4242
Full setup using [`redis`][1] package:
4343

4444
```js
45-
import RedisStore from "connect-redis"
45+
import {RedisStore} from "connect-redis"
4646
import session from "express-session"
4747
import {createClient} from "redis"
4848

tsconfig.esm.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

tsconfig.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
22
"compilerOptions": {
3-
"target": "es2020",
4-
"module": "commonjs",
5-
"isolatedModules": true,
3+
"target": "es2022",
4+
"module": "esnext",
65
"strict": true,
6+
"isolatedModules": true,
7+
"skipLibCheck": true,
78
"noImplicitReturns": true,
89
"noUnusedLocals": true,
9-
"skipLibCheck": true,
1010
"forceConsistentCasingInFileNames": true,
1111
"moduleResolution": "node",
12-
"declaration": true,
13-
"outDir": "./dist/cjs",
1412
"esModuleInterop": true,
15-
"resolveJsonModule": true,
13+
"resolveJsonModule": true
1614
},
17-
"exclude": ["node_modules", "dist"],
15+
"exclude": ["node_modules", "dist"]
1816
}

0 commit comments

Comments
 (0)