Skip to content

Commit bee9695

Browse files
committed
update express pkg to shared config...
and clean up TS errors
1 parent f06846a commit bee9695

File tree

11 files changed

+71
-57
lines changed

11 files changed

+71
-57
lines changed

assistant/typescript-standardization-roadmap.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,19 @@ yarn workspace @vue-skuilder/db build
244244

245245
**COMMIT POINT**: Dual CommonJS/ESM exports working for shared libraries
246246

247-
### ✅ Day 2: Express Package
248-
- [ ] Update `express/tsconfig.json` (extends base, NodeNext)
249-
- [ ] Test: Build express package
250-
- [ ] Verify: No breaking changes in build outputs
247+
### ✅ Day 2: Express Package - COMPLETED
248+
- [x] Update `express/tsconfig.json` (extends base, NodeNext)
249+
- [x] Test: Build express package
250+
- [x] Verify: No breaking changes in build outputs
251+
- [x] Fixed: 20+ TypeScript strict errors (unused parameters, imports)
252+
- [x] Fixed: Composite flag issue preventing JavaScript output
253+
- [x] Fixed: ESM import paths in common package (.js → .mjs)
254+
- [x] Fixed: Runtime import error for EloToNumber function
251255

252256
### ✅ Integration Testing
253-
- [ ] Test: `yarn workspace @vue-skuilder/common build`
254-
- [ ] Test: `yarn workspace @vue-skuilder/db build`
255-
- [ ] Test: `yarn workspace @vue-skuilder/express build`
257+
- [x] Test: `yarn workspace @vue-skuilder/common build`
258+
- [x] Test: `yarn workspace @vue-skuilder/db build`
259+
- [x] Test: `yarn workspace @vue-skuilder/express build`
256260
- [ ] Test: `yarn workspace @vue-skuilder/e2e-db test`
257261
- [ ] Verify: IDE intellisense works across backend packages
258262

@@ -402,25 +406,50 @@ export interface Answer { ... }
402406
- Build system inconsistencies create more complexity than necessary
403407
- Package boundaries need clearer definition between domain and persistence concerns
404408

409+
### ESM Import Path Resolution Issues
410+
411+
#### Problem Discovered:
412+
When building dual CommonJS/ESM packages, simply renaming `.js` files to `.mjs` isn't sufficient - the import statements inside the files must also be updated to reference `.mjs` extensions.
413+
414+
#### Specific Issue:
415+
- Common package generated both `elo.js` (CJS) and `elo.mjs` (ESM)
416+
- ESM `index.mjs` still contained `export * from './elo.js'`
417+
- Express app (running in ESM mode) tried to import ESM version but got wrong file references
418+
- Runtime error: `The requested module '@vue-skuilder/common' does not provide an export named 'EloToNumber'`
419+
420+
#### Root Cause:
421+
ESM requires explicit file extensions and the build process wasn't updating import paths within files when creating the `.mjs` versions.
422+
423+
#### Solution Implemented:
424+
Updated build script to use `sed` to replace `.js` with `.mjs` in import statements:
425+
```bash
426+
find dist-esm -name '*.js' -exec sed -i "s/\.js'/\.mjs'/g; s/\.js\"/\.mjs\"/g" {} \;
427+
```
428+
429+
#### Impact:
430+
This type of import path issue would affect any ESM consumer of workspace packages and demonstrates the complexity of maintaining dual module formats manually.
431+
405432
## Current Status (Session 1 Complete)
406433

407434
### ✅ Completed Today
408435
- Created shared `tsconfig.base.json` with ES2022 target and strict settings
409-
- Migrated `common` and `db` packages to extend base configuration
410-
- Fixed unused parameter strictness issue in common package
436+
- Migrated `common`, `db`, and `express` packages to extend base configuration
437+
- Fixed unused parameter strictness issues across packages
411438
- Added dual CommonJS/ESM exports to shared libraries
412439
- Resolved database type export issues and naming conflicts
413-
- Verified all builds and dev environment still work
440+
- Fixed ESM import path issues (.js → .mjs) in build process
441+
- Verified all builds, dev environment, and express runtime working
414442

415443
### 🎯 Next Session Goals
416-
- Update express package to use base config
417444
- Fix e2e-db Jest import issues with new CommonJS exports
418445
- Complete backend TypeScript standardization
419446
- Test full integration with Jest consuming CommonJS exports
447+
- Verify IDE intellisense works across all backend packages
420448

421449
### 📊 Progress Metrics
422-
- **Packages Standardized**: 2/4 backend packages (common, db)
450+
- **Packages Standardized**: 3/4 backend packages (common, db, express)
423451
- **Build Status**: ✅ All packages building successfully with dual outputs
424452
- **Dev Environment**: ✅ yarn dev working
453+
- **Runtime Status**: ✅ Express app running with ESM imports
425454
- **Type Consistency**: ✅ ES2022 target across standardized packages
426455
- **Module Exports**: ✅ CommonJS/ESM dual exports ready for Jest

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
},
1616
"scripts": {
17-
"build": "rm -rf dist dist-esm && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && find dist-esm -name '*.js' -exec sh -c 'mv \"$1\" \"${1%.js}.mjs\"' _ {} \\; && cp -r dist-esm/* dist/ && rm -rf dist-esm",
17+
"build": "rm -rf dist dist-esm && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && find dist-esm -name '*.js' -exec sed -i \"s/\\.js'/\\.mjs'/g; s/\\.js\\\"/\\.mjs\\\"/g\" {} \\; && find dist-esm -name '*.js' -exec sh -c 'mv \"$1\" \"${1%.js}.mjs\"' _ {} \\; && cp -r dist-esm/* dist/ && rm -rf dist-esm",
1818
"dev": "tsc --watch"
1919
},
2020
"packageManager": "yarn@4.6.0",

packages/express/src/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface VueClientRequest extends express.Request {
5858
body: ServerRequest;
5959
}
6060

61-
app.get('/courses', async (req: Request, res: Response) => {
61+
app.get('/courses', async (_req: Request, res: Response) => {
6262
try {
6363
const courses = await CourseLookup.allCourses();
6464
res.send(courses.map((c) => `${c._id} - ${c.name}`));
@@ -164,11 +164,11 @@ app.post('/', (req: Request, res: Response) => {
164164
postHandler(req, res);
165165
});
166166

167-
app.get('/version', (req: Request, res: Response) => {
167+
app.get('/version', (_req: Request, res: Response) => {
168168
res.send(ENV.VERSION);
169169
});
170170

171-
app.get('/', (req: Request, res: Response) => {
171+
app.get('/', (_req: Request, res: Response) => {
172172
let status = `Express service is running.\nVersion: ${ENV.VERSION}\n`;
173173

174174
CouchDB.session()

packages/express/src/attachment-preprocessing/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import CouchDB, { useOrCreateDB } from '../couchdb/index.js';
1+
import CouchDB from '../couchdb/index.js';
22
import nano from 'nano';
33
import { normalize } from './normalize.js';
44
import AsyncProcessQueue, { Result } from '../utils/processQueue.js';
@@ -186,11 +186,11 @@ async function processDocAttachments(
186186
return resp;
187187
}
188188

189-
interface DatabaseChangesResultItemWithDoc
190-
extends nano.DatabaseChangesResultItem {
191-
doc: nano.DocumentGetResponse;
192-
courseID: string;
193-
}
189+
// interface _DatabaseChangesResultItemWithDoc
190+
// extends nano.DatabaseChangesResultItem {
191+
// doc: nano.DocumentGetResponse;
192+
// courseID: string;
193+
// }
194194

195195
interface AttachmentProcessingRequest {
196196
courseID: string;

packages/express/src/client-requests/classroom-requests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface lookupData {
2323
uuid: string;
2424
}
2525

26-
async function deleteClassroom(classroom_id: string) {}
26+
// async function deleteClassroom(_classroom_id: string) {}
2727

2828
async function getClassID(joinCode: string) {
2929
try {
@@ -55,7 +55,7 @@ async function writeClassroomConfig(config: ClassroomConfig, classID: string) {
5555
...config,
5656
});
5757
})
58-
.catch((err) => {
58+
.catch((_err) => {
5959
studentDB.insert({
6060
_id: CLASSROOM_CONFIG,
6161
...config,
@@ -70,7 +70,7 @@ async function writeClassroomConfig(config: ClassroomConfig, classID: string) {
7070
...config,
7171
});
7272
})
73-
.catch((err) => {
73+
.catch((_err) => {
7474
teacherDB.insert({
7575
_id: CLASSROOM_CONFIG,
7676
...config,

packages/express/src/client-requests/course-requests.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import hashids from 'hashids';
21
import { log } from 'util';
32
import { CreateCourse } from '@vue-skuilder/common';
4-
import CouchDB, { SecurityObject, useOrCreateDB } from '../couchdb/index.js';
3+
import CouchDB, { SecurityObject } from '../couchdb/index.js';
54
import { postProcessCourse } from '../attachment-preprocessing/index.js';
65
import AsyncProcessQueue from '../utils/processQueue.js';
76
import nano from 'nano';
8-
import { Status } from '@vue-skuilder/common';
7+
98
import logger from '@/logger.js';
109
import { CourseLookup } from '@vue-skuilder/db';
1110
import { courseDBDesignDocs } from '../design-docs.js';

packages/express/src/couchdb/authentication.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function requestIsAdminAuthenticated(req: VueClientRequest) {
3636
const isLoggedInUser = s.userCtx.name === username;
3737
return isAdmin && isLoggedInUser;
3838
})
39-
.catch((err) => {
39+
.catch((_err) => {
4040
return false;
4141
});
4242
}
@@ -78,7 +78,7 @@ export async function requestIsAuthenticated(req: VueClientRequest) {
7878
logger.info(`AuthUser: ${JSON.stringify(s)}`);
7979
return s.userCtx.name === username;
8080
})
81-
.catch((err) => {
81+
.catch((_err) => {
8282
return false;
8383
});
8484
}

packages/express/src/routes/logs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import express, { Request, Response } from 'express';
22
import { promises as fs } from 'fs';
33
import path from 'path';
4-
import { requestIsAdminAuthenticated } from '../couchdb/authentication.js';
4+
55
import logger from '../logger.js';
66
import process from 'process';
77

88
const router = express.Router();
99

1010
// Get list of available log files
11-
router.get('/', async (req: Request, res: Response) => {
11+
router.get('/', async (_req: Request, res: Response) => {
1212
// [ ] add an auth mechanism. Below fcn is based on
1313
// the CouchDB auth mechanism, forwarded from the web-app (not direct-access of server).
1414
//

packages/express/src/utils/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dotenv from 'dotenv';
22
import process from 'process';
3-
import fs from 'fs';
3+
44
import { initializeDataLayer } from '@vue-skuilder/db';
55

66
dotenv.config({

packages/express/src/utils/processQueue.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IServerRequest } from '@vue-skuilder/common';
22

3-
interface Request {}
3+
44
export interface Result {
55
status: 'ok' | 'awaiting' | 'warning' | 'error';
66
ok: boolean;
@@ -88,8 +88,7 @@ export default class AsyncProcessQueue<
8888
reject();
8989
}
9090
},
91-
intervals[depth],
92-
jobID
91+
intervals[depth]
9392
);
9493
});
9594

@@ -102,7 +101,7 @@ export default class AsyncProcessQueue<
102101
});
103102
}
104103

105-
public async getResult(jobID: number, depth = 0): Promise<R> {
104+
public async getResult(jobID: number, _depth = 0): Promise<R> {
106105
const status = this.jobStatus(jobID);
107106

108107
if (status === 'complete') {

0 commit comments

Comments
 (0)