Contributing to otplib
Thank you for your interest in contributing to otplib! This guide covers everything you need to get started.
Development Setup
Environment
- Node.js >= 24.11.0
- pnpm >= 11.26.0
Getting Started
# Clone the repository
git clone https://github.com/yeojz/otplib.git
cd otplib
# Install dependencies
pnpm installCommon Commands
# Development
pnpm install # Install dependencies
pnpm build # Build all packages (required before testing)
pnpm test # Run all tests
pnpm test:ci # Run tests with coverage
pnpm fix # Lint + format (run before commits)
pnpm typecheck # TypeScript validation
# Single package testing
pnpm --filter @otplib/core test -- --project packages
pnpm --filter otplib-cli test -- --project otplib-cli
# Run specific test file
pnpm vitest run packages/core/src/utils.test.ts
# Multi-runtime distribution tests (See #Testing)
pnpm test:dist-bun # Bun distribution tests
pnpm test:dist-deno # Deno distribution tests
# OR
pnpm test:docker bun-1
# Documentation
pnpm docs:dev # Start docs dev server. (Requires a manual pnpm run build before running)
pnpm docs:build # Build documentation
# Other
pnpm size # Build production bundles and check their sizesProject Structure
packages/- Published packages in theotplibecosystem (core, hotp, totp, uri, otplib bundle, crypto/base32 plugins)apps/- Applications built on top ofpackages/(docs site, CLI)internal/- Internal tooling, not published (shared build configuration, distribution tests, benchmarks, fuzz tests, test utilities)
Testing Requirements
packages/- 100% test coverage strictly required
- Test must pass on all supported runtimes and environments.
apps/- Test must pass tests. Preferably reaching full coverage.
- Coverage thresholds dependent on application.
- Strive for full coverage and provide reason for deciding not to.
Test Types
Unit Tests (packages/*/src/*.test.ts)
- Test source code directly using Vitest
- Run with
pnpm testorpnpm test:ci(with coverage)
Distribution Tests (internal/distribution-tests/)
- Test built artifacts (dist/) across Node.js 22/24, Deno, and Bun
- Ensures published packages work correctly in all target runtimes
- Run with
pnpm build && pnpm test:dist-node
Local Testing
# Unit tests (source code)
pnpm test
pnpm test:ci # with coverage
# Distribution tests (built artifacts)
pnpm build # Required: build packages first
pnpm test:dist-node # Node.js distribution tests
pnpm test:dist-bun # Bun distribution tests (requires Bun)
pnpm test:dist-deno # Deno distribution tests (requires Deno)Docker-based Multi-Runtime Testing
Since this library supports multiple runtimes (Bun 1.x, Deno 1.x/2.x, Node 22/24), you can use Docker to test across all environments without installing them locally.
The Node targets are node-22 and node-24. Node.js 20 reached end-of-life in April 2026 and has left the main CI matrix; it is still exercised on main by the non-blocking Node.js Compatibility workflow (.github/workflows/node-compat.yml).
# Test a specific runtime
./scripts/test-docker.sh node-22
./scripts/test-docker.sh bun
./scripts/test-docker.sh deno-2
# Test all runtimes
./scripts/test-docker.sh allAvailable runtimes: bun-1, deno-1, deno-2, node-22, node-24
See docker/docker-compose.yml for configuration details.
Making Changes
Branching Strategy
- Create feature branches from
main - Use descriptive branch names:
feat/add-feature,fix/issue-123,docs/update-guide
Code Style
- TypeScript strict mode enabled
- oxlint for linting and oxfmt for formatting, configured in
.oxlintrc.jsonand.oxfmtrc.json - Editor support comes from the Oxc extension (
oxc.oxc-vscode), which uses theoxlintandoxfmtinstalled in the workspace - Run
pnpm fixbefore committing
Commit Messages
Follow conventional commits:
feat: add new feature
fix: resolve issue with token generation
docs: update API documentation
test: add edge case tests
refactor: simplify validation logic
chore: update dependenciesPull Request Guidelines
- Create an issue first for significant changes
- Keep PRs focused - one feature or fix per PR
- Include tests for new functionality
- Update documentation if adding/changing APIs
- Run all checks before submitting:bash
pnpm fix && pnpm typecheck && pnpm test:ci
PR Checklist
Release Process (For Maintainers)
Releases are managed by maintainers:
- Merge PRs: Review and merge contributor PRs to
main - Version Bump: Update package versions in
package.jsonfiles as needed - Publish: Trigger the Publish to npm workflow via
workflow_dispatch(Actions tab) to build and publish packages.pnpm run audit(production dependencies) blocks every CI run and the publish dry run; tickskip-auditon the publish dispatch only for an explicitly accepted risk
AI Usage Guidelines
Code or other content generated in whole or in part using AI tools can be contributed to the project, provided that it satisfies the following conditions:
AI Tool Terms Compatibility
- Ensure the AI tool's terms don't conflict with the project's open source license, IP policies, or Open Source Definition
Third-Party Content in AI Output
- Verify permission to use any third-party copyrighted materials (e.g., via compatible open source license or public domain)
- Provide attribution and license information for any third-party content included
Responsible AI Usage
- You are responsible for reviewing, testing, and verifying any AI-assisted changes.
- If AI tools generated significant parts of your contribution, mention this in your PR so reviewers can provide appropriate guidance.
Questions?
- Open a GitHub Issues
- Check the documentation
License
By contributing, you agree that your contributions will be licensed under the MIT License.