Warn when onboarding outside Capacitor root#478
Conversation
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdded a Capacitor root validation preflight to Changes
Sequence Diagram(s)sequenceDiagram
participant User as User (CLI)
participant Init as initApp
participant FS as Filesystem
participant Prompt as Prompt/Console
User->>Init: run init/onboarding
Init->>FS: findNearestCapacitorConfig(startDir)
FS-->>Init: nearest config path or undefined
Init->>Prompt: warnIfNotInCapacitorRoot(nearest)
Prompt-->>User: display warning + choices (Continue / Cancel)
alt User continues
User-->>Init: confirm
Init->>Init: proceed with onboarding
else User cancels
User-->>Init: cancel
Init->>Prompt: exit(1)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds a guard to the Capacitor onboarding flow that warns users when running the onboarding command outside the Capacitor project root directory. The guard detects nearby config files in parent directories and prompts users to cancel if auto-configuration is likely to fail.
Changes:
- Added a helper function to search for Capacitor config files in parent directories
- Added a warning function that executes early in the onboarding process to detect incorrect working directory
- Provides specific guidance when user appears to be in a platform-specific folder (ios/android)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/init.ts
Outdated
| } | ||
|
|
||
| const continueAnyway = await pConfirm({ | ||
| message: 'Are you sure you want to continue? If that happens, the auto-configuration will probably not work from here.', |
There was a problem hiding this comment.
The phrase "If that happens" in the confirmation message is grammatically awkward and unclear. The message would be clearer as: "Are you sure you want to continue? The auto-configuration will probably not work from here." or "Are you sure you want to continue? If you do, the auto-configuration will probably not work from here."
| message: 'Are you sure you want to continue? If that happens, the auto-configuration will probably not work from here.', | |
| message: 'Are you sure you want to continue? If you do, the auto-configuration will probably not work from here.', |
src/init.ts
Outdated
| } | ||
|
|
||
| const pathSegments = currentDir.split(path.sep).filter(Boolean) | ||
| if (pathSegments.includes('ios') || pathSegments.includes('android')) { |
There was a problem hiding this comment.
The platform folder detection logic checks if 'ios' or 'android' appears anywhere in the full directory path, which can produce false positives. For example, a user in /Users/ios/myproject or /home/android-dev/project would be incorrectly identified as being inside a platform folder. Consider checking only the last path segment, or checking if the current directory is a direct child of a directory containing a Capacitor config file.
| if (pathSegments.includes('ios') || pathSegments.includes('android')) { | |
| const currentFolder = pathSegments[pathSegments.length - 1] | |
| if (currentFolder === 'ios' || currentFolder === 'android') { |
|



Adds a guard that warns when onboarding is run outside the Capacitor project root. The flow now detects nearby config files and lets the user cancel if auto-configuration is likely to fail.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.