Thank you for your interest in contributing to dtsx! This guide will help you get started.
- Getting Started
- Development Setup
- Project Structure
- Making Changes
- Testing
- Code Style
- Pull Request Process
- Adding New Features
- Fixing Bugs
- Bun >= 1.0.0
- Git
- A code editor (VS Code recommended)
- Fork the repository on GitHub
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/dtsx.git
cd dtsx- Add the upstream remote:
git remote add upstream https://github.com/stacksjs/dtsx.gitbun installbun run buildbun testbun test test/generator.test.tsdtsx/
├── packages/
│ ├── dtsx/ # Core library
│ │ ├── src/
│ │ │ ├── generator.ts # Main generation entry point
│ │ │ ├── extractor.ts # Declaration extraction
│ │ │ ├── processor.ts # Declaration processing
│ │ │ ├── formatter.ts # Output formatting
│ │ │ ├── bundler.ts # Declaration bundling
│ │ │ ├── cache.ts # Incremental build cache
│ │ │ ├── plugins.ts # Plugin system
│ │ │ ├── lsp.ts # Language server
│ │ │ └── ...
│ │ ├── test/
│ │ │ ├── fixtures/ # Test input/output files
│ │ │ └── *.test.ts # Test files
│ │ └── bin/
│ │ └── cli.ts # CLI entry point
│ ├── vite-plugin/ # Vite integration
│ ├── esbuild-plugin/ # esbuild integration
│ ├── webpack-plugin/ # webpack integration
│ └── bun-plugin/ # Bun integration
├── ARCHITECTURE.md # Architecture documentation
├── TODO.md # Roadmap and tasks
└── ...
git checkout -b feature/your-feature-name
# or
git checkout -b fix/your-bug-fixfeature/- New featuresfix/- Bug fixesdocs/- Documentation updatesrefactor/- Code refactoringtest/- Test additions/improvementsperf/- Performance improvements
# Run all tests
bun test
# Run with verbose output
bun test --verbose
# Run specific test file
bun test test/generator.test.ts
# Run tests matching a pattern
bun test --grep "should extract"Tests use Bun's built-in test runner. Create test files in packages/dtsx/test/.
// test/my-feature.test.ts
import { describe, expect, it } from 'bun:test'
import { myFunction } from '../src/my-module'
describe('myFunction', () => {
it('should do something', () => {
const result = myFunction('input')
expect(result).toBe('expected')
})
it('should handle edge cases', () => {
expect(() => myFunction(null)).toThrow()
})
})- Add input files to
test/fixtures/input/example/ - Add expected output to
test/fixtures/output/ - Add the test case to
test/dts.test.ts
// In test/dts.test.ts
const testCases = [
// ... existing cases
'0099', // Your new test case
]- Use TypeScript for all code
- Use meaningful variable and function names
- Keep functions small and focused
- Add JSDoc comments for public APIs
- Avoid
anytypes when possible
The project uses ESLint for code formatting:
# Check formatting
bun run lint
# Fix formatting issues
bun run lint:fix- Enable strict mode in TypeScript
- Use explicit return types for public functions
- Avoid type assertions unless necessary
// Good
export function extractType(source: string): TypeDeclaration | null {
// ...
}
// Avoid
export function extractType(source: string) {
return result as any
}- Ensure tests pass:
bun test - Check linting:
bun run lint - Update documentation if needed
- Add tests for new functionality
## Summary
Brief description of changes
## Changes
- Change 1
- Change 2
## Testing
How to test these changes
## Related Issues
Fixes #123- Submit your PR
- Maintainers will review within a few days
- Address any requested changes
- Once approved, your PR will be merged
- Check TODO.md for existing plans
- Open an issue to discuss large features
- Consider backward compatibility
Create a new module in src/:
// src/my-feature.ts
/**
* Configuration for my feature
*/
export interface MyFeatureConfig {
option1: string
option2?: boolean
}
/**
* Main function description
* @param input - Input description
* @param config - Configuration options
* @returns Output description
*/
export function myFeature(input: string, config: MyFeatureConfig): string {
// Implementation
}Add your export to src/index.ts:
export * from './my-feature'Update bin/cli.ts:
case 'my-feature':
await handleMyFeature(args)
break// test/my-feature.test.ts
describe('myFeature', () => {
it('should work with basic input', () => {
// ...
})
})- Add JSDoc comments
- Update README.md if needed
- Update TODO.md to mark as complete
Create a minimal reproduction:
// In a test file
it('reproduces bug #123', () => {
const input = `...`
const result = processDeclarations(input, [], {})
// This fails before the fix
expect(result).not.toContain('incorrect output')
})- Use debugger or console.log
- Check related code paths
- Review recent changes
- Keep changes minimal
- Don't refactor unrelated code
- Add a regression test
# Run all tests
bun test
# Run specific related tests
bun test --grep "related feature"Use Bun's debugger:
bun --inspect test/my-test.tsOr add console.log statements:
console.log('Debug:', JSON.stringify(value, null, 2))Run benchmarks:
bun run benchmark.ts
bun run benchmark.ts --quick # Faster, less accurateThe extractor uses TypeScript's compiler API:
import ts from 'typescript'
const sourceFile = ts.createSourceFile(
'file.ts',
sourceCode,
ts.ScriptTarget.Latest,
true,
)
ts.forEachChild(sourceFile, (node) => {
if (ts.isFunctionDeclaration(node)) {
// Process function
}
})Add a new declaration type:
- Update
DeclarationTypeintypes.ts - Add extraction logic in
extractor.ts - Add processing logic in
processor.ts - Add tests
Add a new CLI command:
- Add case in
bin/cli.ts - Implement handler function
- Update help text
- Add tests
Add a new plugin hook:
- Add hook to
PluginHooksinterface inplugins.ts - Call hook at appropriate point in pipeline
- Document in README
- Open a GitHub Issue
- Check existing issues for answers
- Review the Architecture Guide
By contributing, you agree that your contributions will be licensed under the MIT License.