Contributing
Guide for contributing to React Native Tailwind.
Project Setup
Section titled “Project Setup”Clone Repository
Section titled “Clone Repository”git clone https://github.com/mgcrea/react-native-tailwind.gitcd react-native-tailwindpnpm installpnpm build # Full buildpnpm build:babel # Compile TypeScriptpnpm build:babel-plugin # Bundle Babel pluginpnpm build:types # Generate type declarationsTesting
Section titled “Testing”pnpm test # Run all testspnpm lint # ESLintpnpm check # TypeScript type checkpnpm spec # Jest testsExample App
Section titled “Example App”pnpm dev # Run example app# orcd example && npm run dev -- --reset-cacheArchitecture Overview
Section titled “Architecture Overview”Build System
Section titled “Build System”The project uses a dual-build system:
-
Main Package (ESM):
src/→dist/via Babel- Compiled as ES modules
- Excludes
src/babel/directory
-
Babel Plugin (CommonJS):
src/babel/→dist/babel/index.cjsvia esbuild- Must be CommonJS (Babel requirement)
- Bundled into single self-contained file
- Includes all parser code inline (~25KB)
Key Directories
Section titled “Key Directories”src/├── babel/│ ├── plugin.ts # Main Babel plugin│ ├── config-loader.ts # Tailwind config discovery│ └── utils/ # Utility functions│ ├── attributeMatchers.ts│ ├── componentSupport.ts│ ├── dynamicProcessing.ts│ ├── modifierProcessing.ts│ ├── styleTransforms.ts│ ├── styleInjection.ts│ └── twProcessing.ts├── parser/│ ├── index.ts # Parser orchestrator│ ├── spacing.ts # Spacing utilities│ ├── colors.ts # Color utilities│ └── ... # Other parsers├── utils/│ └── styleKey.ts # Style key generation└── index.ts # Main exportMaking Changes
Section titled “Making Changes”Adding New Utility Classes
Section titled “Adding New Utility Classes”-
Determine category: Does it fit in an existing parser or need a new one?
-
Edit/create parser in
src/parser/:
export function parseYourCategory(cls: string): StyleObject | null { if (cls === 'your-class') { return { yourStyle: 'value' }; } return null;}- Register parser in
src/parser/index.ts:
import { parseYourCategory } from './your-category';
const parsers = [ parseSpacing, parseColor, parseYourCategory, // Add here // ...];-
Export constants (if applicable) in
src/index.ts -
Add tests in
src/parser/__tests__/your-category.test.ts -
Rebuild:
pnpm build
Modifying Babel Plugin
Section titled “Modifying Babel Plugin”- Edit
src/babel/plugin.tsor utilities insrc/babel/utils/ - Run
pnpm build(runs esbuild bundler) - Test in example app
- Add/update tests
Testing Changes
Section titled “Testing Changes”- Unit tests:
pnpm spec- Example app:
cd examplenpm run dev -- --reset-cache- Type checking:
pnpm check- Linting:
pnpm lintPull Request Process
Section titled “Pull Request Process”- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name- Make your changes
- Add tests for new functionality
- Run all checks:
pnpm test- Commit your changes:
git commit -m "feat: add your feature"Follow Conventional Commits:
feat:- New featurefix:- Bug fixdocs:- Documentation changesrefactor:- Code refactoringtest:- Test changeschore:- Build/tooling changes
- Push to your fork:
git push origin feature/your-feature-name- Create a Pull Request on GitHub
Code Style
Section titled “Code Style”- Use TypeScript for type safety
- Follow existing code patterns
- Add comments for complex logic
- Keep functions focused and small
- Use meaningful variable names
Testing Guidelines
Section titled “Testing Guidelines”- Write tests for new features
- Ensure existing tests pass
- Test edge cases
- Use descriptive test names
Example:
describe('parseSpacing', () => { it('should parse margin classes', () => { expect(parseSpacing('m-4')).toEqual({ margin: 16 }); });
it('should return null for invalid classes', () => { expect(parseSpacing('invalid')).toBeNull(); });});Documentation
Section titled “Documentation”- Update README.md for new features
- Add JSDoc comments for public APIs
- Include examples in documentation
- Update type definitions
Getting Help
Section titled “Getting Help”- Questions: Open a Discussion
- Bugs: Open an Issue
- Features: Open an Issue with proposal
License
Section titled “License”By contributing, you agree that your contributions will be licensed under the MIT License.
Authors
Section titled “Authors”Thank you for contributing! 🎉