Skip to content

Commit 895c595

Browse files
Ts migration review (#228)
# TypeScript Migration: 0.19.0 Release ## Overview This PR introduces the TypeScript migration for KaibanJS, providing enhanced type safety and developer experience. This is the first alpha release (v0.19.0-alpha) with TypeScript support while maintaining backward compatibility. ## Key Changes - Complete conversion of JavaScript codebase to TypeScript - Added comprehensive type definitions for core functionality - **Migrated all tools to TypeScript with proper typing** - Updated build system to handle TypeScript compilation - Added TypeScript tests to validate type safety - Maintained backward compatibility by preserving `.js` files as `.deprecated.js` - Enhanced documentation with TypeScript usage examples - Updated Jest configuration to support TypeScript tests ## Tool Improvements - All tools now include strong type definitions for inputs and outputs - Type-safe tool registration and execution flow - Enhanced error handling with typed error responses - Better intellisense support when creating custom tools - Type guards for runtime validation of tool responses ## Benefits for Developers - Improved autocompletion in modern IDEs - Better error detection during development - Self-documenting code with type signatures - Enhanced refactoring capabilities - Stronger guarantees around API contracts - Easier custom tool creation with TypeScript interfaces ## Usage ```bash npm install kaibanjs ``` TypeScript users can now enjoy native type support without additional configuration. ## Testing - All existing tests have been migrated to TypeScript - New type-specific tests have been added - Tool-specific type tests ensure proper input/output handling - All functionality remains identical to the JavaScript version ## Migration for Existing Users No breaking changes have been introduced for JavaScript users. The existing API remains fully compatible, and JavaScript projects using KaibanJS will continue to work without any changes. ## Next Steps - Gather feedback from the community on type definitions - Refine types based on real-world usage - Prepare for stable release - Expand TypeScript-specific documentation ## Special Thanks Thanks to [original PR author] for their initial TypeScript migration work, which served as the foundation for this improved implementation. Additional contributions from the community that helped refine the types and testing approach are greatly appreciated. --- Please provide feedback on the type definitions and report any issues you encounter with the alpha release!
2 parents 26abeb8 + 060839d commit 895c595

File tree

115 files changed

+15730
-1349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+15730
-1349
lines changed

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: 'current' } }],
4+
'@babel/preset-typescript',
5+
],
6+
};

jest.config.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
/** @type {import('jest').Config} */
12
module.exports = {
3+
roots: ['<rootDir>/src', '<rootDir>/tests'],
4+
testEnvironment: 'node',
25
transform: {
3-
'^.+\\.[t|j]sx?$': 'babel-jest',
6+
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
47
},
8+
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'],
9+
coverageDirectory: './coverage',
10+
collectCoverageFrom: ['src/**/*.js', 'src/**/*.ts'],
11+
coveragePathIgnorePatterns: ['/node_modules/', '/tests/'],
12+
testPathIgnorePatterns: ['/node_modules/'],
513
moduleNameMapper: {
614
'^kaibanjs$': '<rootDir>/dist/bundle.cjs',
715
},
816
testTimeout: 300000, // Sets global timeout to 10 seconds for all tests
9-
testEnvironment: 'node', // Use Node.js environment for executing tests,
1017
verbose: true, // Make Jest more verbose
1118
silent: false, // Ensure Jest is not silent (though this is not directly related to console.log output)
1219
// testMatch: ['**/tests/e2e/**/eventPlanningTeam.test.js'], // Run tests only in the specific directory

package-lock.json

Lines changed: 1914 additions & 553 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"build": "npx rollup -c",
3030
"build:test": "NODE_ENV=development TEST_ENV=mocked-llm-apis npx rollup -c",
3131
"dev": "NODE_ENV=development npx rollup -c -w",
32+
"tsc": "NODE_ENV=development npx rollup -c",
3233
"test": "npm run build:test && npm run test:integration",
3334
"test:watch": "TEST_ENV=mocked-llm-apis jest --testPathPattern='tests/e2e' --watch",
3435
"test:debug": "TEST_ENV=mocked-llm-apis node --inspect-brk node_modules/.bin/jest --runInBand --verbose --testPathPattern='tests/e2e'",
@@ -112,14 +113,17 @@
112113
"@babel/core": "^7.24.9",
113114
"@babel/plugin-syntax-import-meta": "^7.10.4",
114115
"@babel/preset-env": "^7.24.8",
116+
"@babel/preset-typescript": "^7.27.0",
115117
"@eslint/js": "^9.11.0",
116118
"@rollup/plugin-babel": "6.0.4",
117119
"@rollup/plugin-commonjs": "26.0.1",
118-
"@rollup/plugin-node-resolve": "15.2.3",
120+
"@rollup/plugin-inject": "^5.0.5",
121+
"@rollup/plugin-node-resolve": "^15.3.1",
119122
"@rollup/plugin-replace": "5.0.7",
120123
"@rollup/plugin-terser": "^0.4.4",
121-
"@rollup/plugin-typescript": "^11.1.6",
124+
"@rollup/plugin-typescript": "^12.1.2",
122125
"@types/init-package-json": "^1.10.3",
126+
"@types/jest": "^29.5.14",
123127
"@typescript-eslint/eslint-plugin": "^8.6.0",
124128
"@typescript-eslint/parser": "^8.6.0",
125129
"babel-jest": "^29.7.0",
@@ -135,7 +139,11 @@
135139
"prettier": "2.3.2",
136140
"rollup": "4.21.1",
137141
"rollup-plugin-dts": "6.1.1",
142+
"rollup-plugin-esbuild": "^6.2.1",
143+
"rollup-plugin-node-polyfills": "^0.2.1",
138144
"rollup-plugin-peer-deps-external": "2.2.4",
145+
"terser-webpack-plugin": "^5.3.14",
146+
"ts-loader": "^9.5.2",
139147
"tslib": "^2.7.0",
140148
"typescript": "^5.5.4",
141149
"typescript-eslint": "^8.6.0"

0 commit comments

Comments
 (0)