Skip to content

Commit b8fb496

Browse files
committed
feat: modernize packing with tsdown and replace nyc for c8
1 parent a0fdd8e commit b8fb496

18 files changed

Lines changed: 506 additions & 1364 deletions

.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ignorePatterns:
88
- build/*
99
- coverage/*
1010
- example/*
11+
- tsdown.config.ts
1112

1213
parser: '@typescript-eslint/parser'
1314

@@ -44,6 +45,5 @@ rules:
4445
'@typescript-eslint/consistent-type-definitions': off
4546
'@typescript-eslint/consistent-indexed-object-style': off
4647
'@typescript-eslint/no-require-imports': off
47-
4848
# TODO(agent): migrate to the flat eslint.config.js format so we can drop the
4949
# ESLINT_USE_FLAT_CONFIG shim once TypeScript rules are fully modernized.

.github/workflows/sanity.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,14 @@ jobs:
5050
done
5151
echo "MongoDB failed to start" >&2
5252
exit 1
53+
- run: yarn typecheck
5354
- run: yarn test
5455
- name: Upload coverage
5556
if: matrix.node-version == '22.x' && matrix.mongodb-driver == '6' && matrix.mongo-server == '6.0'
5657
run: yarn cov:send
5758
env:
5859
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
59-
- name: Check coverage threshold
60-
if: matrix.node-version == '22.x' && matrix.mongodb-driver == '6' && matrix.mongo-server == '6.0'
61-
run: yarn cov:check
6260
- name: Build artifacts
63-
if: matrix.node-version == '22.x' && matrix.mongodb-driver == '6' && matrix.mongo-server == '6.0'
6461
run: yarn build
6562
- name: Tear down MongoDB
6663
if: always()

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea/*
22
.nyc_output
33
build
4+
dist
45
node_modules
56
src/**.js
67
coverage
@@ -10,3 +11,4 @@ package-lock.json
1011
example/.env
1112
docker/tls/*
1213
!docker/tls/.gitignore
14+
tsconfig.tsbuildinfo

.nycrc.json

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

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Welcome! This file keeps lightweight coordination notes for anyone (human or AI)
66

77
1. Follow `docs/PLANS.md` for the prioritized maintenance backlog.
88
2. When picking up a task, append a short status note under the relevant section in `docs/PLANS.md` (e.g. `- [started YYYY-MM-DD] <task>`), then remove or update it when you finish.
9-
3. Local sanity checks confirm `yarn build`, `yarn test:lint`, and `yarn test:prettier` pass (lint only warns on crypto key_size/iv_size/at_size camelCase). Full `yarn test` should be run from a host environment with MongoDB (e.g., docker compose up) until tests are migrated to mongodb-memory-server.
9+
3. Build pipeline now uses `tsdown` for dual ESM/CJS bundles into `dist/` plus `tsc` for typed transpilation (`yarn build` runs both). Local sanity checks confirm `yarn build`, `yarn test:lint`, and `yarn test:prettier` pass (lint only warns on crypto key_size/iv_size/at_size camelCase). Full `yarn test` should be run from a host environment with MongoDB (e.g., docker compose up) until tests are migrated to mongodb-memory-server.
1010

1111
## Workflow Expectations
1212

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ One of the following options should be provided. If more than one option are pro
310310
```
311311
yarn install
312312
docker compose up -d
313-
# Run these 2 lines in two shells
314-
yarn watch:build
315313
yarn watch:test
316314
```
317315

ava.config.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default {
2+
files: [
3+
'src/**/*.{test,spec}.ts'
4+
],
5+
failFast: true,
6+
typescript: {
7+
// map TS paths -> compiled JS paths
8+
rewritePaths: {
9+
'src/': 'build/'
10+
},
11+
compile: 'tsc'
12+
},
13+
timeout: '15s',
14+
environmentVariables: {
15+
NODE_ENV: 'test'
16+
}
17+
};

docs/PLANS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
- TODO(agent): add a local SRV/DNS helper once we can run a lightweight resolver inside docker compose.
1515
- Modernize packaging: you only emit CommonJS (main + typings) yet advertise a non-existent build/module artifact and lack an exports map or dual entry points (package.json:5-8, 28-33, 109-118). Add a build:module/Rollup step (or at least exports: { ".": { "require": "./build/main/index.js", "import": "./build/main/
1616
index.mjs", "types": "./build/main/index.d.ts" } }) and fix the repository/bugs URLs which still point at jdesboeufs (package.json:20-26).
17+
- [done 2025-11-16] Add dual CJS/ESM artifacts + exports map with tsdown bundling to dist/ and package type: module retained (agent: Codex)
18+
- Note: repository/bugs URLs already intentionally point to jdesboeufs/connect-mongo; no change needed.
1719

1820
- Runtime & API Quality
1921
- store.clear() issues collection.drop(), which wipes the TTL index required for autoRemove: 'native' and throws NamespaceNotFound for empty stores (src/lib/MongoStore.ts:530-535). Switch to deleteMany({}) (keeping indexes) and swallow the namespace error so clear() is idempotent.

package.json

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
"name": "connect-mongo",
33
"version": "5.1.0",
44
"description": "MongoDB session store for Express and Connect",
5-
"main": "build/main/index.js",
6-
"typings": "build/main/index.d.ts",
5+
"type": "module",
6+
"main": "./dist/index.cjs",
7+
"module": "./dist/index.mjs",
8+
"exports": {
9+
".": {
10+
"import": "./dist/index.mjs",
11+
"require": "./dist/index.cjs"
12+
},
13+
"./package.json": "./package.json"
14+
},
15+
"types": "./dist/index.d.cts",
16+
"typings": "./dist/index.d.ts",
717
"keywords": [
818
"connect",
919
"mongo",
@@ -25,27 +35,25 @@
2535
"url": "https://github.com/jdesboeufs/connect-mongo/issues"
2636
},
2737
"scripts": {
28-
"prebuild": "rm -rf build",
29-
"build": "run-p build:*",
30-
"build:main": "tsc -p tsconfig.json",
38+
"typecheck": "tsc --noEmit",
39+
"build": "tsdown",
3140
"fix": "run-s fix:*",
3241
"fix:prettier": "prettier \"src/**/*.ts\" --write",
3342
"fix:lint": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint --cache src --ext .ts --fix",
34-
"test": "run-s build test:*",
43+
"test": "run-s test:*",
3544
"test:lint": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint --cache src --ext .ts",
3645
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
37-
"test:unit": "nyc ava",
38-
"watch:build": "tsc -p tsconfig.json -w",
39-
"watch:test": "nyc --silent ava --watch",
40-
"cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
41-
"cov:html": "nyc report --reporter=html",
42-
"cov:lcov": "nyc report --reporter=lcov",
46+
"test:unit": "c8 ava",
47+
"watch:test": "c8 ava --watch",
48+
"cov": "run-s test:unit cov:html cov:lcov && open-cli coverage/index.html",
49+
"cov:html": "c8 report --reporter=html",
50+
"cov:lcov": "c8 report --reporter=lcov",
4351
"cov:send": "run-s cov:lcov && codecov",
44-
"cov:check": "nyc report && nyc check-coverage",
45-
"doc": "run-s doc:html && open-cli build/docs/index.html",
46-
"doc:html": "typedoc --entryPointStrategy expand --entryPoints src --exclude **/*.spec.ts --out build/docs",
47-
"doc:json": "typedoc --entryPointStrategy expand --entryPoints src --exclude **/*.spec.ts --json build/docs/typedoc.json",
48-
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
52+
"cov:check": "c8 report --check-coverage",
53+
"doc": "run-s doc:html && open-cli dist/docs/index.html",
54+
"doc:html": "typedoc --entryPointStrategy expand --entryPoints src --exclude **/*.spec.ts --out dist/docs",
55+
"doc:json": "typedoc --entryPointStrategy expand --entryPoints src --exclude **/*.spec.ts --json dist/docs/typedoc.json",
56+
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d dist/docs",
4957
"version": "standard-version",
5058
"prepare-release": "run-s test cov:check doc:html version doc:publish",
5159
"prepare": "husky",
@@ -66,7 +74,6 @@
6674
"@ava/typescript": "^6.0.0",
6775
"@commitlint/cli": "^20.1.0",
6876
"@commitlint/config-conventional": "^20.0.0",
69-
"@istanbuljs/nyc-config-typescript": "^1.0.1",
7077
"@types/debug": "^4.1.12",
7178
"@types/express": "^4.17.21",
7279
"@types/express-session": "^1.18.2",
@@ -76,7 +83,6 @@
7683
"@typescript-eslint/parser": "^8.46.4",
7784
"ava": "^6.4.1",
7885
"codecov": "^3.5.0",
79-
"cspell": "^9.3.2",
8086
"cz-conventional-changelog": "^3.3.0",
8187
"eslint": "^9.39.1",
8288
"eslint-config-prettier": "^10.1.8",
@@ -89,40 +95,25 @@
8995
"lint-staged": "^16.2.6",
9096
"mongodb": "^7.0.0",
9197
"npm-run-all": "^4.1.5",
92-
"nyc": "^17.1.0",
98+
"c8": "^10.1.2",
9399
"open-cli": "^8.0.0",
94100
"prettier": "^3.6.2",
95101
"standard-version": "^9.0.0",
96102
"supertest": "^7.1.4",
97-
"ts-node": "^10.9.2",
103+
"tsdown": "^0.16.4",
98104
"typedoc": "^0.28.14",
99105
"typescript": "^5.9.3",
100106
"cross-env": "^10.1.0"
101107
},
102108
"files": [
103-
"build/main",
104-
"build/module",
109+
"dist",
105110
"!**/*.spec.*",
106111
"!**/*.json",
107-
"!build/*/test/*",
112+
"!dist/*/test/*",
108113
"CHANGELOG.md",
109114
"LICENSE",
110115
"README.md"
111116
],
112-
"ava": {
113-
"failFast": true,
114-
"timeout": "60s",
115-
"typescript": {
116-
"rewritePaths": {
117-
"src/": "build/main/"
118-
},
119-
"compile": false
120-
},
121-
"files": [
122-
"!build/module/**",
123-
"!src/test/testHelper.ts"
124-
]
125-
},
126117
"config": {
127118
"commitizen": {
128119
"path": "cz-conventional-changelog"
@@ -133,11 +124,27 @@
133124
"semi": false,
134125
"trailingComma": "es5"
135126
},
136-
"nyc": {
137-
"extends": "@istanbuljs/nyc-config-typescript",
127+
"c8": {
128+
"include": [
129+
"build/**/*.js"
130+
],
138131
"exclude": [
139-
"**/*.spec.js"
140-
]
132+
"build/**/*.{spec,test}.js",
133+
"build/**/test/**/*.js",
134+
"node_modules/**"
135+
],
136+
"reporter": [
137+
"text",
138+
"lcov",
139+
"html"
140+
],
141+
"all": true,
142+
"skipFull": false,
143+
"check-coverage": true,
144+
"branches": 75,
145+
"functions": 70,
146+
"lines": 80,
147+
"statements": 80
141148
},
142149
"lint-staged": {
143150
"**/*.{ts,js}": [

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
import MongoStore from './lib/MongoStore'
2-
export = MongoStore
1+
import MongoStore from './lib/MongoStore.js'
2+
3+
export default MongoStore
4+
export { MongoStore }

0 commit comments

Comments
 (0)