Thank you for your interest in contributing to ts-json-rpc! This document provides guidelines and information for contributors.
- Node.js >= 20.0.0
- npm
- Git
-
Fork and Clone
git clone https://github.com/YOUR_USERNAME/ts-json-rpc.git cd ts-json-rpc -
Install Dependencies
npm install
-
Build All Packages
npm run build
-
Run Tests
npm test -
Verify Linting
npm run lint
This is a TypeScript monorepo with three packages:
ts-json-rpc/
├── packages/
│ ├── core/ # Core types and utilities
│ │ ├── src/
│ │ │ ├── index.ts
│ │ │ └── __tests__/
│ │ ├── package.json
│ │ └── tsconfig.json
│ ├── client/ # JSON-RPC client
│ │ ├── src/
│ │ │ ├── index.ts
│ │ │ └── __tests__/
│ │ ├── package.json
│ │ └── tsconfig.json
│ └── server/ # JSON-RPC server
│ ├── src/
│ │ ├── index.ts
│ │ └── __tests__/
│ ├── package.json
│ └── tsconfig.json
├── .eslintrc.js # ESLint configuration
├── .prettierrc.js # Prettier configuration
├── tsconfig.json # Base TypeScript configuration
└── package.json # Root package with workspaces
We use ESLint and Prettier to maintain consistent code style:
- ESLint: Enforces TypeScript best practices and import organization
- Prettier: Handles code formatting with 4-space indentation, single quotes, and trailing commas
- TypeScript: Strict mode enabled with comprehensive type checking
Run formatting and linting:
npm run format # Format with Prettier
npm run lint # Check with ESLintWe follow Conventional Commits:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Types:
feat: A new featurefix: A bug fixdocs: Documentation only changesstyle: Changes that do not affect the meaning of the coderefactor: A code change that neither fixes a bug nor adds a featureperf: A code change that improves performancetest: Adding missing tests or correcting existing testsbuild: Changes that affect the build system or external dependenciesci: Changes to CI configuration files and scriptschore: Other changes that don't modify src or test files
Examples:
feat(client): add batch request support
fix(server): handle null id in error responses
docs(core): update README with new examples
test(server): add tests for notification handling
All packages must maintain high test coverage (80%+ target):
- Unit Tests: Test individual functions and classes
- Integration Tests: Test package interactions
- Test Framework: Vitest for fast, modern testing
- Coverage: Use
npm testto run tests with coverage reporting
Writing Tests:
- Place tests in
__tests__directories - Use descriptive test names
- Test both success and error cases
- Mock external dependencies
- Follow AAA pattern (Arrange, Act, Assert)
Running Tests:
npm test # All packages
npm test --workspace=@ts-json-rpc/core # Specific packageThis project prioritizes type safety:
- Use strict TypeScript configuration
- Avoid
anytypes unless absolutely necessary - Provide comprehensive type definitions
- Export all public types
- Use type guards for runtime type checking
This project follows the Git Flow workflow for organized development and releases.
We maintain two primary branches:
main: Production-ready code with official release historydevelop: Integration branch where features are merged for testing
-
Feature Branches
- Prefix:
feature/ - Created from:
develop - Merged into:
develop - Example:
feature/batch-request-support
- Prefix:
-
Release Branches
- Prefix:
release/ - Created from:
develop - Merged into:
mainanddevelop - Example:
release/0.2.0
- Prefix:
-
Hotfix Branches
- Prefix:
hotfix/ - Created from:
main - Merged into:
mainanddevelop - Example:
hotfix/critical-error-fix
- Prefix:
-
Install Git Flow (optional but recommended):
# macOS brew install git-flow-avh # Ubuntu/Debian sudo apt-get install git-flow # Windows # Download from: https://github.com/petervanderdoes/gitflow-avh
-
Initialize Git Flow (if using git-flow extensions):
git flow init # Accept defaults: main/develop branches # Feature prefix: feature/ # Release prefix: release/ # Hotfix prefix: hotfix/
-
Start a Feature
# With git-flow git flow feature start your-feature-name # Or manually git checkout develop git pull origin develop git checkout -b feature/your-feature-name
-
Develop the Feature
- Follow coding standards
- Add comprehensive tests
- Update documentation
- Ensure all checks pass
-
Test Your Changes
npm run build npm test npm run lint -
Finish the Feature
# With git-flow (creates PR to develop) git flow feature finish your-feature-name # Or manually git checkout develop git pull origin develop git merge feature/your-feature-name git branch -d feature/your-feature-name
-
Start a Release (maintainers only)
# With git-flow git flow release start 0.2.0 # Or manually git checkout develop git pull origin develop git checkout -b release/0.2.0
-
Prepare Release
- Update version numbers
- Update CHANGELOG.md
- Final testing and bug fixes
- No new features
-
Finish Release (maintainers only)
# With git-flow git flow release finish 0.2.0 # Or manually git checkout main git merge release/0.2.0 git tag -a v0.2.0 -m "Release version 0.2.0" git checkout develop git merge release/0.2.0 git branch -d release/0.2.0
-
Start a Hotfix
# With git-flow git flow hotfix start critical-fix # Or manually git checkout main git pull origin main git checkout -b hotfix/critical-fix
-
Fix the Issue
- Make minimal changes
- Add regression tests
- Update version number
-
Finish Hotfix
# With git-flow git flow hotfix finish critical-fix # Or manually git checkout main git merge hotfix/critical-fix git tag -a v0.1.1 -m "Hotfix version 0.1.1" git checkout develop git merge hotfix/critical-fix git branch -d hotfix/critical-fix
-
mainbranch is protected and requires:- Pull request reviews
- All status checks passing
- Up-to-date branches
-
developbranch requires:- Pull request for feature merges
- All tests passing
Before Submitting:
- Ensure all tests pass
- Update documentation if needed
- Add tests for new features
- Follow commit message conventions
- Rebase on latest main branch
PR Description Should Include:
- Clear description of changes
- Motivation for the changes
- Any breaking changes
- Testing instructions
- Related issue numbers
PR Title:
Use conventional commit format: feat: add new feature
Please include:
- Environment: Node.js version, OS, package versions
- Steps to Reproduce: Minimal reproduction case
- Expected Behavior: What should happen
- Actual Behavior: What actually happens
- Additional Context: Error messages, stack traces
Please include:
- Use Case: Why this feature is needed
- Proposed Solution: How it might work
- Alternatives: Other approaches considered
- Additional Context: Examples, references
- Statements: 80%+
- Branches: 80%+
- Functions: 80%+
- Lines: 80%+
-
Core Package Tests
- Type creation functions
- Type guard functions
- Error creation utilities
- Constants validation
-
Client Package Tests
- Request/response handling
- Error handling
- Transport integration
- Notification sending
- Concurrent operations
-
Server Package Tests
- Request parsing
- Method dispatching
- Error handling
- Batch processing
- Context passing
- Logging
- README Files: Each package must have a comprehensive README
- API Documentation: JSDoc comments for all public APIs
- Examples: Working code examples in documentation
- Type Definitions: Exported TypeScript types
- Use clear, concise language
- Provide working code examples
- Include both basic and advanced usage
- Document error conditions
- Keep documentation up to date with code changes
Releases are managed by maintainers:
- Version bumping follows semantic versioning
- All packages are versioned together
- Changelog is generated from conventional commits
- Releases are tagged and published to npm
- Issues: Create an issue for bugs or feature requests
- Discussions: Use GitHub Discussions for questions
- Documentation: Check package READMEs and code examples
We are committed to providing a welcoming and inclusive experience for everyone.
- Use welcoming and inclusive language
- Be respectful of differing viewpoints
- Accept constructive criticism gracefully
- Focus on what is best for the community
- Show empathy towards other community members
Project maintainers are responsible for clarifying standards and may take corrective action in response to unacceptable behavior.
By contributing to ts-json-rpc, you agree that your contributions will be licensed under the same MIT license that covers the project.