Skip to content

Fix electron dependency issue and improve CLI UX#37

Merged
JeongJaeSoon merged 1 commit intomainfrom
fix/electron-dependency-issue
Aug 11, 2025
Merged

Fix electron dependency issue and improve CLI UX#37
JeongJaeSoon merged 1 commit intomainfrom
fix/electron-dependency-issue

Conversation

@JeongJaeSoon
Copy link
Owner

@JeongJaeSoon JeongJaeSoon commented Aug 11, 2025

Summary

  • Move electron from dependencies to optionalDependencies in package.json
  • Enhance CLI with emojis and improved error messages for better user experience
  • Add comprehensive error handling when electron module fails to load

Problem

This addresses two critical issues:

  1. CI/CD Error: electron-builder requires electron to be in devDependencies, causing build failures when electron is listed in dependencies
  2. Global Install Issue: Users installing globally via npm install -g ccusage-widget had to separately install electron, creating friction (issue [Bug] #25)

Solution

Moving electron to optionalDependencies provides the best of both worlds:

  • ✅ electron-builder no longer complains about dependency placement
  • ✅ Global npm install automatically includes electron when possible
  • ✅ Graceful handling when electron isn't available on unsupported platforms
  • ✅ Better error messages guide users to solutions

Benefits for Users

  • Seamless Global Install: No need to separately install electron after global install
  • Better UX: Enhanced CLI with emojis and clear error messages
  • Improved Troubleshooting: Comprehensive error handling with step-by-step solutions
  • Cross-platform Compatibility: Graceful degradation on unsupported platforms

Test Plan

  • Verify global install works without separate electron installation
  • Confirm electron-builder CI passes with new dependency structure
  • Test error handling when electron module is unavailable
  • Validate enhanced CLI messages and help text

Fixes #25

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Friendlier CLI help with clearer wording and iconography.
    • Improved errors for unknown options, including helpful tips.
    • Pre-launch checks detect global vs. local install and display a clear launch message.
    • Graceful handling when Electron isn’t available, with actionable recovery steps instead of crashing.
    • More resilient startup flow for smoother operation.
  • Chores

    • Electron is now an optional dependency to reduce installation friction and improve robustness across environments.

- Move electron from dependencies to optionalDependencies in package.json
- Add emojis and improved error messages in CLI for better user experience
- Enhance error handling when electron module fails to load
- Provide clear troubleshooting steps in error messages

This fixes the CI/CD electron-builder dependency conflict and resolves
the global install issue where users had to separately install electron.

Fixes #25

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Updates the CLI entrypoint to lazily require Electron with guarded error handling, differentiate global vs local installs to decide launch strategy, and revise CLI/help messaging. Adds electron as an optionalDependency in package.json to support global installations without hard failure.

Changes

Cohort / File(s) Summary
CLI launcher and runtime flow
bin/ccusage-widget.js
Converts top-level Electron require to lazy try/catch with detailed diagnostics; adds global vs local install detection and branching (spawn Electron vs npm start); adds pre-launch messaging; revises help/unknown-option output.
Package management metadata
package.json
Adds root-level optionalDependencies with electron ^28.0.0; adjusts JSON structure accordingly; leaves existing dependencies content intact.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant CLI as ccusage-widget (CLI)
  participant E as Electron (optional)
  participant N as npm start (app)

  U->>CLI: Run ccusage-widget [args]
  alt --help / unknown options
    CLI-->>U: Print help or error message
  else Normal launch
    CLI->>CLI: Detect install type (global vs local)
    CLI->>CLI: Try require('electron')
    alt Electron available
      alt Global install
        CLI->>E: Spawn Electron with app path
        E-->>U: App UI launches
      else Local install
        CLI->>N: Run npm start in app directory
        N-->>U: App starts via dev script
      end
    else Electron missing
      CLI-->>U: Print diagnostic and remediation steps
      CLI->>CLI: Exit with non-zero code
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix global install run failure due to missing electron (#25)

Possibly related PRs

Poem

I nudge the console with a careful tap,
“Electron?” I ask—no need for a trap.
If it’s there, we hop; if not, we guide,
With carrots of tips and a wiser stride.
Now global runs don’t fall through a crack—
A happy hare on the fast launch track! 🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32071ae and ca1f715.

📒 Files selected for processing (2)
  • bin/ccusage-widget.js (1 hunks)
  • package.json (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/electron-dependency-issue

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@claude
Copy link
Contributor

claude bot commented Aug 11, 2025

Claude finished @JeongJaeSoon's task —— View job


PR Review: Fix electron dependency issue and improve CLI UX

Review Checklist:

  • Read and analyze changed files
  • Review package.json dependency changes
  • Analyze CLI enhancements in bin/ccusage-widget.js
  • Check for code quality and best practices
  • Identify potential bugs or issues
  • Assess performance considerations
  • Review security implications
  • Evaluate test coverage impact
  • Provide final feedback and recommendations

📋 Code Review Summary

This PR addresses two important issues: CI/CD compatibility with electron-builder and improved user experience for global installations. The changes are well-implemented and solve real problems.

✅ Positive Aspects

1. Smart Dependency Management (package.json:72-74)

  • Moving electron to optionalDependencies is the correct solution for this use case
  • Resolves electron-builder CI issues while maintaining npm install compatibility
  • Follows npm best practices for platform-specific optional dependencies

2. Enhanced Error Handling (bin/ccusage-widget.js:44-66)

  • Comprehensive try-catch block around electron module loading
  • Provides clear, actionable error messages with step-by-step troubleshooting
  • Graceful degradation when electron isn't available

3. Improved User Experience

  • Added emojis and better formatting to help text and error messages
  • Clear launch feedback (🚀 Launching CCUsage Widget...)
  • Maintains backward compatibility

🔍 Code Quality Assessment

Strengths:

  • Clean, readable code structure
  • Proper error handling with meaningful messages
  • Good separation of concerns between CLI logic and execution
  • Consistent coding style throughout

Security: ✅ No security concerns identified

  • No unsafe operations or external command execution
  • Proper use of child process spawning with controlled arguments

Performance: ✅ No performance issues

  • Minimal overhead added by the enhanced error handling
  • Efficient electron path resolution

🐛 Minor Issues & Suggestions

1. Error Message Accuracy (bin/ccusage-widget.js:48)
The comment says "this shouldn't happen with optionalDependencies" but this isn't entirely accurate. Optional dependencies can still fail to install on unsupported platforms or due to network issues.

Suggestion: Update the comment to be more precise:

// Electron not found - can happen on unsupported platforms or failed installs

2. Local Execution Logic (bin/ccusage-widget.js:86-89)
The local execution branch uses exec instead of spawn and doesn't handle the child process properly. This could lead to inconsistent behavior between global and local execution.

Suggestion: Consider using spawn for consistency:

const child = spawn('npm', ['start'], {
  cwd: appPath,
  stdio: 'inherit'
});
child.on('close', (code) => process.exit(code));

3. Missing Launch Message Consistency
The launch message (🚀 Launching CCUsage Widget...) only appears for global installs, not local runs.

📊 Test Coverage Impact

Current State: No automated tests for the CLI script
Recommendation: Consider adding basic CLI tests to verify:

  • Version and help flags work correctly
  • Error handling behaves as expected
  • Both global and local execution paths function

🎯 Final Recommendation: APPROVE

This PR successfully solves the stated problems and significantly improves the user experience. The code is well-written, secure, and follows best practices. The minor suggestions above are enhancements rather than blockers.

Key Benefits Delivered:

  • ✅ Fixes CI/CD issues with electron-builder
  • ✅ Improves global installation experience
  • ✅ Provides better error handling and user guidance
  • ✅ Maintains backward compatibility

The implementation is production-ready and addresses the core issues effectively.


@JeongJaeSoon JeongJaeSoon merged commit a4c5f44 into main Aug 11, 2025
4 of 5 checks passed
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.

[Bug]

1 participant

Comments