Contributing to Lyt.js
Thank you for your interest in contributing to Lyt.js! This guide will help you get started with the development process.
How to Contribute
There are many ways to contribute to Lyt.js:
- Bug reports: Submit issues for bugs you encounter
- Feature requests: Suggest new features or improvements
- Documentation: Improve or translate documentation
- Code contributions: Submit pull requests for bug fixes or new features
- Community support: Help other users in discussions
Development Environment Setup
Prerequisites
- Node.js >= 18.0
- npm >= 9.0 or pnpm >= 8.0
- Git >= 2.30
- TypeScript >= 5.0
Fork and Clone
bash
# Fork the repository on Gitee, then clone it
git clone https://gitee.com/YOUR_USERNAME/lytjs.git
cd lytjs
# Add upstream remote
git remote add upstream https://gitee.com/lytjs/lytjs.gitInstall Dependencies
bash
# Install dependencies
npm install
# Or use pnpm (recommended)
pnpm installBuild the Project
bash
# Build all packages
npm run build
# Build a specific package
npm run build --workspace=@lytjs/coreRun Tests
bash
# Run all tests
npm test
# Run tests for a specific package
npm test --workspace=@lytjs/core
# Run tests with coverage
npm test -- --coverage
# Run tests in watch mode
npm test -- --watchStart Development Server
bash
# Start the docs development server
npm run docs:dev
# Start the example app
npm run exampleProject Structure
lytjs/
├── packages/
│ ├── core/ # Core package (createApp, h, plugin system)
│ ├── reactivity/ # Reactivity system (ref, reactive, computed, watch)
│ ├── component/ # Component system (defineComponent, lifecycle, slots)
│ ├── renderer/ # Renderer (DOM, SSR, Vapor modes)
│ ├── compiler/ # Template compiler (parse, transform, generate)
│ ├── router/ # Router package
│ ├── store/ # State management package
│ ├── components/ # UI component library
│ └── cli/ # CLI tool
├── docs/ # Documentation
├── examples/ # Example applications
├── tests/ # Test suites
└── scripts/ # Build and utility scriptsCoding Standards
TypeScript
- Use TypeScript for all new code
- Enable
strictmode - Provide proper type annotations for public APIs
- Avoid
any— useunknownor specific types instead
Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Files (source) | camelCase | reactiveEffect.ts |
| Files (test) | camelCase + .test | reactiveEffect.test.ts |
| Directories | kebab-case | reactivity-system/ |
| Variables | camelCase | const isActive = true |
| Constants | UPPER_SNAKE_CASE | const MAX_SIZE = 100 |
| Functions | camelCase | function createApp() |
| Classes | PascalCase | class ComponentInstance |
| Interfaces | PascalCase with I prefix (optional) | interface VNode |
| Types | PascalCase | type PropType = ... |
| Enums | PascalCase | enum ShapeFlags |
Code Style
- Use 2 spaces for indentation (no tabs)
- Use single quotes for strings
- Add semicolons at the end of statements
- Add trailing commas in multi-line objects/arrays
- Maximum line length: 100 characters
Example
typescript
import { ref, computed, type Ref } from '@lytjs/reactivity'
interface CounterOptions {
initialValue?: number
step?: number
}
function useCounter(options: CounterOptions = {}) {
const { initialValue = 0, step = 1 } = options
const count: Ref<number> = ref(initialValue)
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value += step
}
function decrement() {
count.value -= step
}
function reset() {
count.value = initialValue
}
return {
count,
doubleCount,
increment,
decrement,
reset,
}
}
export { useCounter }
export type { CounterOptions }Comments
- Use JSDoc for public API documentation
- Add comments for complex logic
- Use
// TODO:for pending work - Use
// FIXME:for known issues
typescript
/**
* Creates a reactive reference.
* @param value - The initial value
* @returns A reactive Ref object
*/
export function ref<T>(value: T): Ref<T> {
// Implementation
}Commit Messages
Follow the Conventional Commits specification:
<type>(<scope>): <subject>
<body>
<footer>Types
| Type | Description |
|---|---|
feat | New feature |
fix | Bug fix |
docs | Documentation changes |
style | Code style changes (formatting, semicolons, etc.) |
refactor | Code refactoring (no new features or bug fixes) |
perf | Performance improvements |
test | Adding or updating tests |
build | Build system or dependency changes |
ci | CI/CD configuration changes |
chore | Other changes (maintenance, etc.) |
revert | Revert a previous commit |
Examples
feat(core): add nextTick API support
fix(reactivity): resolve memory leak in watch cleanup
docs(en): add English documentation for reactivity API
test(component): add unit tests for slot rendering
refactor(renderer): optimize patch algorithm for static nodesPull Request Process
1. Create a Branch
bash
# Create a feature branch from main
git checkout main
git pull upstream main
git checkout -b feat/your-feature-name
# Or a bugfix branch
git checkout -b fix/issue-description2. Make Changes
- Write clean, well-documented code
- Add tests for new features or bug fixes
- Update documentation if needed
- Ensure all existing tests pass
3. Run Checks
bash
# Run linter
npm run lint
# Run type checking
npm run type-check
# Run all tests
npm test
# Build the project
npm run build4. Commit Changes
bash
git add .
git commit -m "feat(core): add your feature description"5. Push and Create PR
bash
# Push to your fork
git push origin feat/your-feature-name
# Create a Pull Request on Gitee
# Go to https://gitee.com/lytjs/lytjs/pulls and click "New Pull Request"PR Checklist
Before submitting your PR, make sure:
- [ ] Code follows the project's coding standards
- [ ] All tests pass (
npm test) - [ ] Linter passes (
npm run lint) - [ ] Type checking passes (
npm run type-check) - [ ] New features include tests
- [ ] Documentation is updated (if applicable)
- [ ] Commit messages follow the Conventional Commits format
- [ ] PR description clearly explains the changes
Code Review Process
Review Criteria
Reviewers will evaluate PRs based on:
- Correctness — Does the code do what it's supposed to?
- Code quality — Is the code clean, readable, and well-structured?
- Test coverage — Are there adequate tests?
- Documentation — Is the documentation updated?
- Performance — Are there any performance implications?
- Compatibility — Does it maintain backward compatibility?
Review Workflow
- Automated checks — CI runs tests, linter, and type checking
- Peer review — At least one maintainer reviews the code
- Feedback — Reviewer provides feedback or requests changes
- Approval — After addressing feedback, the PR is approved
- Merge — A maintainer merges the PR
Addressing Review Feedback
- Respond to all comments promptly
- Make requested changes in new commits
- Push updates to the same branch
- Mark resolved conversations
Reporting Bugs
When reporting a bug, please include:
- Lyt.js version
- Node.js version and OS
- Minimal reproduction code
- Expected behavior
- Actual behavior
- Steps to reproduce
- Error messages or stack traces
Bug Report Template
**Lyt.js Version:** x.x.x
**Node.js Version:** xx.x.x
**OS:** macOS / Windows / Linux
**Description:**
A clear description of the bug.
**Reproduction Code:**
```javascript
// Minimal code that reproduces the bugExpected Behavior: What you expected to happen.
Actual Behavior: What actually happened.
Steps to Reproduce:
- Step 1
- Step 2
- Step 3
---
## Feature Requests
When requesting a feature, please include:
1. **Use case** — Why do you need this feature?
2. **Proposed API** — How would you like the API to look?
3. **Examples** — Code examples showing the desired usage
4. **Alternatives** — Any workarounds you've considered
---
## License
By contributing to Lyt.js, you agree that your contributions will be licensed under the project's license.
---
## Thank You
Thank you for contributing to Lyt.js! Every contribution, no matter how small, helps make the project better.