Skip to content

Warn when onboarding outside Capacitor root#478

Merged
riderx merged 2 commits intomainfrom
riderx/dar-es-salaam
Jan 30, 2026
Merged

Warn when onboarding outside Capacitor root#478
riderx merged 2 commits intomainfrom
riderx/dar-es-salaam

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented Jan 30, 2026

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

  • New Features
    • Added project-root validation during initialization: the initializer now detects the nearest Capacitor config, warns when started outside the project root, and prompts users to continue or exit.
    • Improved onboarding messaging to guide running commands from the project root.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 30, 2026 01:27
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 30, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Added a Capacitor root validation preflight to initApp that searches parent directories for Capacitor config files, warns when onboarding is started outside the project root, shows nearest config info if found, and prompts the user to continue or exit.

Changes

Cohort / File(s) Summary
Capacitor Root Validation
src/init.ts
Added capacitorConfigFiles list, findNearestCapacitorConfig(startDir) and warnIfNotInCapacitorRoot helpers. Integrated preflight check into initApp. Augmented node:path imports (path, dirname, join). Adjusted control flow to prompt/exit when not in project root.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped up paths to seek a file,
Sniffed parent folders for a config style,
I warned and asked if we should stay,
Or leap back to root to find the way,
A tiny hop, a safer mile. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Warn when onboarding outside Capacitor root' directly and clearly describes the main change: adding a warning when the onboarding process runs outside the Capacitor project root directory.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch riderx/dar-es-salaam

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.',
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Suggested change
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.',

Copilot uses AI. Check for mistakes.
src/init.ts Outdated
}

const pathSegments = currentDir.split(path.sep).filter(Boolean)
if (pathSegments.includes('ios') || pathSegments.includes('android')) {
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if (pathSegments.includes('ios') || pathSegments.includes('android')) {
const currentFolder = pathSegments[pathSegments.length - 1]
if (currentFolder === 'ios' || currentFolder === 'android') {

Copilot uses AI. Check for mistakes.
@riderx riderx merged commit ab8c258 into main Jan 30, 2026
13 of 14 checks passed
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants