7.2 KiB
Development Guide
This document outlines the development workflow, testing, and release process for the prettier-plugin-openapi package.
Prerequisites
Getting Started
-
Clone the repository
git clone https://github.com/lukehagar/prettier-plugin-openapi.git cd prettier-plugin-openapi -
Install dependencies
bun install -
Verify setup
bun run validate
Development Workflow
Available Scripts
bun run dev- Start development mode with TypeScript watchbun run build- Build the projectbun run test- Run all testsbun run test:coverage- Run tests with coverage reportbun run test:watch- Run tests in watch modebun run lint- Run ESLintbun run lint:fix- Fix ESLint issues automaticallybun run format- Format code with Prettierbun run format:check- Check code formattingbun run type-check- Run TypeScript type checkingbun run validate- Run all validation checks (type-check, lint, test)bun run clean- Clean build artifacts
Code Quality
The project uses several tools to maintain code quality:
- ESLint - Code linting with TypeScript support
- Prettier - Code formatting
- TypeScript - Type checking
Commit Message Format
This project follows the Conventional Commits specification:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Types:
feat: A new featurefix: A bug fixdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasks
Examples:
feat: add support for OpenAPI 3.1
fix: correct key ordering for components
docs: update README with usage examples
Testing
Running Tests
# Run all tests
bun run test
# Run tests with coverage
bun run test:coverage
# Run tests in watch mode
bun run test:watch
# Run tests for CI
bun run test:ci
Test Structure
test/plugin.test.ts- Core plugin functionality teststest/file-detection.test.ts- File detection and parsing teststest/integration.test.ts- Integration tests with real OpenAPI filestest/key-ordering.test.ts- Key ordering and sorting teststest/options.test.ts- Plugin options and configuration teststest/vendor.test.ts- Vendor extension teststest/custom-extensions.test.ts- Custom extension tests
Adding Tests
When adding new features or fixing bugs:
- Write tests first (TDD approach)
- Ensure tests cover edge cases
- Add integration tests for complex features
- Update existing tests if behavior changes
Building
Development Build
bun run dev
This starts TypeScript in watch mode, automatically rebuilding when files change.
Production Build
bun run build
This creates a production build in the dist/ directory.
Build Verification
After building, verify the output:
# Check build artifacts
ls -la dist/
# Test the built package
node -e "console.log(require('./dist/index.js'))"
Release Process
Version Management
The project uses semantic versioning (semver):
- Patch (1.0.1): Bug fixes (automated via GitHub Actions)
- Minor (1.1.0): New features (manual)
- Major (2.0.0): Breaking changes (manual)
Automated Releases
Releases are automatically triggered on every push to main:
-
Smart versioning
- Checks if the current version already exists on NPM
- If version exists: bumps patch version and publishes
- If version doesn't exist: publishes current version
- Runs tests and linting before publishing
-
Automatic process
- Every push to the
mainbranch triggers the release workflow - The workflow will automatically:
- Run tests and linting
- Check NPM for existing version
- Bump patch version if needed
- Build and publish to NPM
- Create GitHub release with commit message
- Every push to the
Manual Minor/Major Releases
For minor or major releases:
-
Update version manually
# For minor release bun run version:minor # For major release bun run version:major -
Push to main
git push origin main -
Automated release
- The release workflow will automatically:
- Detect the new version
- Build and test the package
- Publish to NPM
- Create GitHub release
- The release workflow will automatically:
CI/CD Pipeline
GitHub Actions Workflows
-
CI Pipeline (
.github/workflows/ci.yml)- Runs on every push and PR
- Tests on multiple Node.js and Bun versions
- Runs linting, type checking, and tests
- Generates coverage reports
- Builds the package
- Runs security audits
-
Release Pipeline (
.github/workflows/release.yml)- Runs on every push to main
- Smart versioning: checks NPM for existing versions
- Automatically bumps patch version if needed
- Builds, tests, and publishes to NPM
- Creates GitHub release with commit message
Required Secrets
Set up the following secrets in your GitHub repository:
NPM_TOKEN: NPM authentication token for publishingSNYK_TOKEN: Snyk token for security scanning (optional)
Troubleshooting
Common Issues
-
Build failures
- Check TypeScript errors:
bun run type-check - Verify all dependencies are installed:
bun install
- Check TypeScript errors:
-
Test failures
- Run tests individually to isolate issues
- Check test setup and mocks
-
Linting errors
- Run
bun run lint:fixto auto-fix issues - Check ESLint configuration
- Run
-
Release issues
- Check if version already exists on NPM
- Verify NPM_TOKEN secret is set correctly
- Check workflow logs for specific error messages
Debug Mode
Enable debug logging:
DEBUG=prettier-plugin-openapi:* bun run test
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes
- Add tests for new functionality
- Run the full validation:
bun run validate - Commit with conventional commit format
- Push and create a pull request
Pull Request Process
- Ensure all CI checks pass
- Request review from maintainers
- Address feedback and update PR
- Merge after approval
Performance Considerations
- The plugin processes files in memory
- Large OpenAPI files (>1MB) may take longer to format
- Consider file size limits for optimal performance
- Monitor memory usage with very large files
Security
- Regular dependency updates
- Security audits via GitHub Actions
- No external network requests during formatting
- Input validation for all parsed content
Release Workflow Benefits
The new consolidated release workflow provides:
- Smart Versioning: Automatically detects if versions exist on NPM
- No Manual Intervention: Patch releases happen automatically on every push
- Efficient Publishing: Only bumps versions when necessary
- Comprehensive Testing: Full test suite runs before every release
- Automatic Documentation: GitHub releases created with commit messages
- Seamless Integration: Works with both automatic and manual version bumps