A comprehensive library for managing semantic versions and build numbers across React Native iOS and Android projects following SemVer 2.0.0 specification.
- π§ SemVer 2.0.0 Compliance: Strict adherence to semantic versioning specification
- π± Cross-Platform Sync: Automatic version synchronization between package.json, iOS, and Android
- π’ Build Number Management: Proper build number handling for App Store/Google Play requirements
- π CLI Interface: Easy-to-use command-line interface
- π Programmatic API: TypeScript API for Node build scripts (not for RN runtime)
- β‘ Zero Configuration: Works out of the box with standard React Native projects
- π‘οΈ Type Safe: Full TypeScript support with comprehensive type definitions
Install as a development dependency:
npm install --save-dev react-native-semver-sync
# or
yarn add -D react-native-semver-sync# Increment patch version (1.0.0 β 1.0.1)
npx rn-semver patch
# Increment minor version (1.0.1 β 1.1.0, patch resets to 0)
npx rn-semver minor
# Increment major version (1.1.0 β 2.0.0, minor and patch reset to 0)
npx rn-semver major
# Sync current package.json version to platforms
npx rn-semver syncimport { syncVersions, incrementVersion } from 'react-native-semver-sync';
// Sync current package.json version
const result = await syncVersions();
// Increment version and sync
const patchResult = await incrementVersion('patch');
console.log(`Updated to version ${patchResult.version.version}`);This library follows SemVer 2.0.0 specification strictly:
- MAJOR: Breaking changes (incompatible API changes)
- MINOR: New features (backward compatible)
- PATCH: Bug fixes (backward compatible)
- PATCH version MUST be reset to 0 when MINOR is incremented
- PATCH and MINOR MUST be reset to 0 when MAJOR is incremented
- Always increment (never reset)
- Required for App Store/Google Play (must be higher than previous)
- Internal identifier, not visible to users
rn-semver patch # Bug fix release (1.0.0 β 1.0.1)
rn-semver minor # Feature release (1.0.1 β 1.1.0)
rn-semver major # Breaking change release (1.1.0 β 2.0.0)
rn-semver sync # Sync current version to platforms
rn-semver help # Show help information--verbose, -v # Enable verbose logging
--ios-only # Update iOS only
--android-only # Update Android only
--help, -h # Show help# Bug fix with verbose output
rn-semver patch --verbose
# Feature release for iOS only
rn-semver minor --ios-only
# Major release for Android only
rn-semver major --android-onlyUpdates the following in ios/*.xcodeproj/project.pbxproj:
- MARKETING_VERSION: User-facing version (e.g., "1.2.3")
- CURRENT_PROJECT_VERSION: Build number (e.g., "42")
Updates the following in android/app/build.gradle:
- versionName: User-facing version (e.g., "1.2.3")
- versionCode: Build number (e.g., 42)
Syncs the current package.json version to iOS and Android platforms.
import { syncVersions } from 'react-native-semver-sync';
const result = await syncVersions({
platforms: ['ios', 'android'], // Default: both
verbose: true, // Default: false
});Increments the package.json version and syncs to all platforms.
import { incrementVersion } from 'react-native-semver-sync';
const result = await incrementVersion('patch', {
platforms: ['ios'],
verbose: true,
});Note: Convenience functions like
incrementPatch,incrementMinor,incrementMajorare not exported. UseincrementVersion('patch' | 'minor' | 'major')instead, preferably via the CLI.
For advanced usage:
import { VersionManager } from 'react-native-semver-sync';
const manager = new VersionManager({
config: {
iosProjectPath: './ios/MyApp.xcodeproj/project.pbxproj',
androidGradlePath: './android/app/build.gradle',
packageJsonPath: './package.json',
},
platforms: ['ios', 'android'],
verbose: true,
});
const result = await manager.syncVersions();interface SyncResult {
success: boolean;
version: VersionInfo;
build: BuildInfo;
platforms: PlatformUpdateResult[];
errors: string[];
}
interface VersionInfo {
version: string;
major: number;
minor: number;
patch: number;
prerelease?: string;
buildMetadata?: string;
}The library automatically detects standard React Native project structure:
your-project/
βββ package.json # Version source
βββ ios/YourApp.xcodeproj/project.pbxproj # iOS versions
βββ android/app/build.gradle # Android versions
import { syncVersions } from 'react-native-semver-sync';
await syncVersions({
config: {
iosProjectPath: './ios/CustomApp.xcodeproj/project.pbxproj',
androidGradlePath: './android/app/build.gradle',
packageJsonPath: './package.json',
},
});Add to your package.json:
{
"scripts": {
"version:patch": "rn-semver patch",
"version:minor": "rn-semver minor",
"version:major": "rn-semver major",
"version:sync": "rn-semver sync"
}
}Then use:
npm run version:patch
npm run version:minor
npm run version:major
npm run version:syncname: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Increment version
run: npx rn-semver patch
- name: Commit version bump
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "chore: bump version" || exit 0
git pushRun the test suite:
npm test- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Add tests for your changes
- Run tests:
npm test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the need for proper semantic versioning in React Native projects
- Built with react-native-builder-bob
- Follows Semantic Versioning 2.0.0 specification
- π Report Issues
- π¬ Discussions
- π§ Email: iisraromar@gmail.com
Made with β€οΈ for the React Native community