Skip to content

Commit bd17a1d

Browse files
committed
add base tsconfig
1 parent cc64ac2 commit bd17a1d

File tree

6 files changed

+466
-25
lines changed

6 files changed

+466
-25
lines changed
Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
# TypeScript Standardization Roadmap
2+
3+
## Overview
4+
Standardize TypeScript configuration across backend packages (common, db, express, e2e-db) to resolve module resolution conflicts, improve IDE support, and enable consistent testing frameworks (specifically fixing the e2e-db Jest issues). Frontend packages (common-ui, courses, platform-ui, standalone-ui) are out of scope.
5+
6+
## Current State Analysis
7+
8+
### Package TypeScript Targets (INCONSISTENT)
9+
- **express**: `ES2022` target, NodeNext modules
10+
- **common**: `es2018` target, NodeNext modules
11+
- **db**: `ES2020` target, bundler resolution
12+
- **e2e-db**: ES2020 target, bundler resolution (FAILING - jest import issues)
13+
14+
### Module Resolution Issues
15+
- **Backend packages**: Mix of `NodeNext` and `bundler` resolution
16+
- **Testing packages**: Mixed resolution causing jest ESM/CommonJS conflicts
17+
18+
### Critical Problems
19+
1. **e2e-db Jest failures**: ESM packages imported by CommonJS Jest
20+
2. **IDE inconsistency**: Different path resolution per package
21+
3. **Type checking variance**: Different strictness levels
22+
4. **Build fragmentation**: Multiple module systems breaking imports
23+
24+
## Implementation Strategy
25+
26+
### Phase 1: Base Configuration (Day 1)
27+
Create shared TypeScript foundation that works for ALL package types.
28+
29+
#### 1.1 Create tsconfig.base.json
30+
```json
31+
{
32+
"compilerOptions": {
33+
"target": "ES2022",
34+
"strict": true,
35+
"skipLibCheck": true,
36+
"forceConsistentCasingInFileNames": true,
37+
"esModuleInterop": true,
38+
"allowSyntheticDefaultImports": true,
39+
"declaration": true,
40+
"declarationMap": true,
41+
"sourceMap": true,
42+
"incremental": true,
43+
"noUnusedLocals": true,
44+
"noUnusedParameters": true,
45+
"noFallthroughCasesInSwitch": true
46+
}
47+
}
48+
```
49+
50+
#### 1.2 Create Package-Specific Extensions
51+
52+
**Backend Services** (express):
53+
```json
54+
{
55+
"extends": "../../tsconfig.base.json",
56+
"compilerOptions": {
57+
"module": "NodeNext",
58+
"moduleResolution": "NodeNext",
59+
"types": ["node"]
60+
}
61+
}
62+
```
63+
64+
**Shared Libraries** (common, db):
65+
```json
66+
{
67+
"extends": "../../tsconfig.base.json",
68+
"compilerOptions": {
69+
"module": "NodeNext",
70+
"moduleResolution": "NodeNext",
71+
"outDir": "dist"
72+
}
73+
}
74+
```
75+
76+
**Testing Packages** (e2e-db):
77+
```json
78+
{
79+
"extends": "../../tsconfig.base.json",
80+
"compilerOptions": {
81+
"module": "CommonJS",
82+
"moduleResolution": "Node",
83+
"types": ["jest", "node"],
84+
"noEmit": true
85+
}
86+
}
87+
```
88+
89+
### Phase 2: Package Migration (Day 1-2)
90+
91+
#### 2.1 Migrate Packages in Dependency Order
92+
1. **common** (no dependencies)
93+
2. **db** (depends on common)
94+
3. **express** (depends on common, db)
95+
4. **e2e-db** (depends on db, common)
96+
97+
#### 2.2 Fix Module Exports for Jest Compatibility
98+
99+
**Update common/package.json**:
100+
```json
101+
{
102+
"main": "dist/index.js",
103+
"module": "dist/index.mjs",
104+
"types": "dist/index.d.ts",
105+
"exports": {
106+
".": {
107+
"types": "./dist/index.d.ts",
108+
"import": "./dist/index.mjs",
109+
"require": "./dist/index.js"
110+
}
111+
}
112+
}
113+
```
114+
115+
**Update db/package.json**:
116+
```json
117+
{
118+
"main": "dist/index.js",
119+
"module": "dist/index.mjs",
120+
"types": "dist/index.d.ts",
121+
"exports": {
122+
".": {
123+
"types": "./dist/index.d.ts",
124+
"import": "./dist/index.mjs",
125+
"require": "./dist/index.js"
126+
},
127+
"./core": {
128+
"types": "./dist/core/index.d.ts",
129+
"import": "./dist/core/index.mjs",
130+
"require": "./dist/core/index.js"
131+
}
132+
}
133+
}
134+
```
135+
136+
### Phase 3: Build System Updates (Day 2)
137+
138+
#### 3.1 Update Build Scripts to Generate Both CJS and ESM
139+
140+
**common build script**:
141+
```json
142+
{
143+
"scripts": {
144+
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.esm.json"
145+
}
146+
}
147+
```
148+
149+
**Create tsconfig.build.json** (CommonJS):
150+
```json
151+
{
152+
"extends": "./tsconfig.json",
153+
"compilerOptions": {
154+
"module": "CommonJS",
155+
"outDir": "dist",
156+
"outExtension": { ".js": ".js" }
157+
}
158+
}
159+
```
160+
161+
**Create tsconfig.esm.json** (ESM):
162+
```json
163+
{
164+
"extends": "./tsconfig.json",
165+
"compilerOptions": {
166+
"module": "ESNext",
167+
"outDir": "dist",
168+
"outExtension": { ".js": ".mjs" }
169+
}
170+
}
171+
```
172+
173+
#### 3.2 Update db Package Build (TSup Configuration)
174+
175+
**Update tsup.config.ts**:
176+
```typescript
177+
import { defineConfig } from 'tsup';
178+
179+
export default defineConfig({
180+
entry: ['src/index.ts', 'src/core/index.ts'],
181+
format: ['cjs', 'esm'],
182+
dts: true,
183+
splitting: false,
184+
sourcemap: true,
185+
clean: true,
186+
outExtension: ({ format }) => ({
187+
js: format === 'esm' ? '.mjs' : '.js'
188+
})
189+
});
190+
```
191+
192+
### Phase 4: Testing Fix (Day 2)
193+
194+
#### 4.1 Update e2e-db Jest Configuration
195+
196+
**jest.config.js**:
197+
```javascript
198+
module.exports = {
199+
preset: 'ts-jest',
200+
testEnvironment: 'node',
201+
setupFilesAfterEnv: ['<rootDir>/src/setup/jest-setup.ts'],
202+
testTimeout: 30000,
203+
testMatch: ['<rootDir>/src/tests/**/*.test.ts'],
204+
moduleNameMapper: {
205+
'^@/(.*)$': '<rootDir>/src/$1'
206+
},
207+
// Force Jest to use CommonJS exports from workspace packages
208+
modulePathIgnorePatterns: ['<rootDir>/../../packages/.*/dist/.*\\.mjs$']
209+
};
210+
```
211+
212+
#### 4.2 Rebuild Dependencies with New CommonJS Support
213+
```bash
214+
yarn workspace @vue-skuilder/common build
215+
yarn workspace @vue-skuilder/db build
216+
```
217+
218+
## Implementation Checklist
219+
220+
### ✅ Pre-Implementation
221+
- [x] Create backup branch: Already in fresh branch
222+
- [x] Verify all packages currently build without errors: Confirmed working
223+
224+
### ✅ Day 1: Base Configuration - COMPLETED
225+
- [x] Create `master/tsconfig.base.json`
226+
- [x] Create package-specific tsconfig templates
227+
- [x] Update `common/tsconfig.json` (extends base)
228+
- [x] Update `db/tsconfig.json` (extends base)
229+
- [x] Test: `yarn workspace @vue-skuilder/common build`
230+
- [x] Test: `yarn workspace @vue-skuilder/db build`
231+
- [x] Fixed unused parameter issue in common package
232+
- [x] Verified all packages build and dev environment works
233+
234+
### ✅ Day 1: Build System Updates - READY FOR NEXT SESSION
235+
- [ ] Update `common/package.json` exports
236+
- [ ] Add dual CommonJS/ESM build to common
237+
- [ ] Update `db/tsup.config.ts` for dual output
238+
- [ ] Update `db/package.json` exports
239+
- [ ] Test: Rebuild common and db packages
240+
- [ ] Verify: Both CJS and ESM outputs generated
241+
242+
**COMMIT POINT**: Base TypeScript configuration standardized across backend packages
243+
244+
### ✅ Day 2: Express Package
245+
- [ ] Update `express/tsconfig.json` (extends base, NodeNext)
246+
- [ ] Test: Build express package
247+
- [ ] Verify: No breaking changes in build outputs
248+
249+
### ✅ Integration Testing
250+
- [ ] Test: `yarn workspace @vue-skuilder/common build`
251+
- [ ] Test: `yarn workspace @vue-skuilder/db build`
252+
- [ ] Test: `yarn workspace @vue-skuilder/express build`
253+
- [ ] Test: `yarn workspace @vue-skuilder/e2e-db test`
254+
- [ ] Verify: IDE intellisense works across backend packages
255+
256+
### ✅ Day 2: Testing Package Fix
257+
- [ ] Update `e2e-db/tsconfig.json` (extends base, CommonJS)
258+
- [ ] Update `e2e-db/jest.config.js` for CommonJS imports
259+
- [ ] Test: `yarn workspace @vue-skuilder/e2e-db test`
260+
- [ ] Verify: Jest imports workspace packages successfully
261+
262+
### ✅ Documentation
263+
- [ ] Update `CLAUDE.md` with new TypeScript patterns
264+
- [ ] Document backend package tsconfig patterns
265+
- [ ] Create migration guide for future backend packages
266+
267+
## In-Scope Packages
268+
269+
### Backend Packages Only
270+
- **common**: Pure TypeScript library (es2018 → ES2022)
271+
- **db**: TSup bundler (ES2020 → ES2022, add CommonJS exports)
272+
- **express**: Node.js service (ES2022, NodeNext - already compatible)
273+
- **e2e-db**: Jest testing (ES2020 → ES2022, CommonJS for Jest)
274+
275+
### Out of Scope (Frontend/UI)
276+
- **platform-ui, standalone-ui**: Vite + Vue apps (complex Vite configs)
277+
- **common-ui, courses**: Component libraries (Vue SFC compilation)
278+
279+
## Success Criteria
280+
281+
### ✅ e2e-db Jest Tests Pass
282+
- Jest can import `@vue-skuilder/db` and `@vue-skuilder/common`
283+
- No ESM/CommonJS module resolution errors
284+
- All database tests execute successfully
285+
286+
### ✅ Consistent TypeScript Behavior
287+
- Same compiler target (ES2022) across all packages
288+
- Unified strict settings and error reporting
289+
- Consistent path resolution and IDE support
290+
291+
### ✅ Build System Integrity
292+
- All packages build successfully with new configurations
293+
- Dual CommonJS/ESM exports for shared libraries
294+
- No breaking changes for existing consumers
295+
296+
### ✅ Developer Experience
297+
- Single TypeScript mental model across packages
298+
- Consistent error messages and IDE behavior
299+
- Clear patterns for future package creation
300+
301+
## Risk Mitigation
302+
303+
### High Risk: Breaking Changes
304+
- **Mitigation**: Test builds after each package migration
305+
- **Rollback**: Maintain separate branch until full validation
306+
- **Testing**: Run full test suite after each phase
307+
308+
### Medium Risk: Build Performance
309+
- **Mitigation**: Build performance benchmarking is out of scope
310+
- **Optimization**: Use TypeScript incremental compilation
311+
- **Focus**: Maintain existing build speed
312+
313+
### Low Risk: IDE Compatibility
314+
- **Testing**: Verify VS Code/WebStorm intellisense
315+
- **Documentation**: Update workspace settings if needed
316+
317+
## Timeline
318+
319+
- **Day 1 Morning**: Base configuration + common/db packages
320+
- **Day 1 Afternoon**: Build system updates + dual exports
321+
- **Day 2 Morning**: Component libraries + applications
322+
- **Day 2 Afternoon**: e2e-db fix + integration testing
323+
324+
**Total Effort**: 2 days
325+
**Primary Goal**: Fix e2e-db Jest issues while establishing backend TypeScript consistency
326+
**Secondary Benefits**: Improved IDE support for backend packages, consistent type checking, future-proofed backend configuration
327+
**Scope**: Backend packages only (common, db, express, e2e-db)
328+
329+
## Current Status (Session 1 Complete)
330+
331+
### ✅ Completed Today
332+
- Created shared `tsconfig.base.json` with ES2022 target and strict settings
333+
- Migrated `common` and `db` packages to extend base configuration
334+
- Fixed unused parameter strictness issue in common package
335+
- Verified all builds and dev environment still work
336+
337+
### 🎯 Next Session Goals
338+
- Add dual CommonJS/ESM exports to shared libraries
339+
- Update express package to use base config
340+
- Fix e2e-db Jest import issues
341+
- Complete backend TypeScript standardization
342+
343+
### 📊 Progress Metrics
344+
- **Packages Standardized**: 2/4 backend packages (common, db)
345+
- **Build Status**: ✅ All packages building successfully
346+
- **Dev Environment**: ✅ yarn dev working
347+
- **Type Consistency**: ✅ ES2022 target across standardized packages

packages/common/src/course-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function prepareNote55(
1313
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1414
data: any,
1515
author: string,
16-
tags: string[],
16+
_tags: string[],
1717
uploads?: { [x: string]: PouchDB.Core.FullAttachment }
1818
): DisplayableData {
1919
const dataShapeId = NameSpacer.getDataShapeString({

packages/common/tsconfig.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
{
2+
"extends": "../../tsconfig.base.json",
23
"compilerOptions": {
3-
"declaration": true,
44
"outDir": "dist",
55
"rootDir": "src",
66
"module": "NodeNext",
7-
"moduleResolution": "nodenext",
8-
"target": "es2018",
9-
"strict": true,
10-
"esModuleInterop": true,
11-
"skipLibCheck": true,
12-
"forceConsistentCasingInFileNames": true
7+
"moduleResolution": "NodeNext"
138
},
149
"include": ["src/**/*"],
1510
"exclude": ["node_modules", "dist"]

0 commit comments

Comments
 (0)