feat(react-native): add smart platform detection#46
Closed
Conversation
Automatically detect which platform is needed and skip initialization of the unused platform. This significantly speeds up shell initialization and eliminates confusing warnings. **Features:** 1. **Command-Based Detection** - Examines the command being run: - iOS commands (ios.sh, pod, xcodebuild, etc.) → skip Android - Android commands (android.sh, gradlew, adb, etc.) → skip iOS 2. **Project Structure Detection** - Checks project folders as fallback: - Has ios/ but no android/ → skip Android - Has android/ but no ios/ → skip iOS - Has both → initialize both 3. **Manual Override** - Respects explicit skip flags: - ANDROID_SKIP_SETUP=1 / IOS_SKIP_SETUP=1 always honored - RN_REQUIRE_ALL_PLATFORMS=1 forces both platforms **Performance:** - ~5-6x faster for single-platform commands - Eliminates Android SDK evaluation errors on macOS for iOS commands - Reduces confusing warnings for developers **Backward Compatible:** - Existing skip flags still work (and take precedence) - No breaking changes to existing workflows - Opt-out available via RN_REQUIRE_ALL_PLATFORMS=1 **Use Cases:** - iOS dev on macOS: No more Android SDK errors - Android-only projects: Faster initialization - Cross-platform: Use separate shells or set RN_REQUIRE_ALL_PLATFORMS=1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Closing this PR. The automatic project structure detection in devbox shell could cause unexpected behavior when users expect a full environment but the plugin auto-skips platform initialization based on missing directories. The command-based detection is useful but the tradeoffs of automatic detection don't outweigh the potential UX issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automatically detect which platform is needed and skip initialization of the unused platform. This eliminates Android SDK errors on macOS and speeds up init by 5-6x for single-platform commands.
Problem
Currently, the React Native plugin initializes both Android and iOS platforms on every shell, even when only one is needed. This causes:
Solution
Smart Platform Detection (Automatic)
The plugin now automatically detects which platform you need using two strategies:
1. Command-Based Detection (Primary)
Examines the command being run:
Detected patterns:
ios.sh,pod,xcodebuild,xcrun,simulatorandroid.sh,gradlew,adb,emulator,/android/2. Project Structure Detection (Fallback)
Checks project folders when command detection doesn't apply:
Manual Override (Always Respected)
Existing skip flags still work and take precedence:
Performance Impact
Before (without smart detection)
After (with smart detection)
$ time devbox run start:ios iOS simulator booted real 0m8.5s⚡ 5-6x faster for single-platform commands!
Changes
Modified Files
plugins/react-native/virtenv/scripts/init/init-hook.shRN_REQUIRE_ALL_PLATFORMSopt-outNew Files
plugins/react-native/SMART-PLATFORM-DETECTION.mdBackward Compatibility
✅ Zero Breaking Changes
ANDROID_SKIP_SETUP/IOS_SKIP_SETUPflags still workRN_REQUIRE_ALL_PLATFORMS=1Testing
Manual Testing
CI Testing
This PR will run through:
Use Cases
1. iOS Development on macOS
2. Android-Only Projects
3. Cross-Platform Development
Migration
Projects using manual skip flags can now remove them:
Manual flags still work if you want to keep them!
Related
🤖 Generated with Claude Code