Skip to content

refactor: do without yargs #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2025
Merged

refactor: do without yargs #138

merged 2 commits into from
Feb 24, 2025

Conversation

j9t
Copy link
Owner

@j9t j9t commented Feb 24, 2025

Summary by CodeRabbit

  • Chores
    • Updated the package version and streamlined dependency management for improved overall efficiency.
  • Refactor
    • Enhanced command-line option processing to provide a smoother, more reliable execution experience for users.

j9t added 2 commits February 24, 2025 11:51
Replaced yargs-based argument parsing with native `parseArgs` API, improving performance and reducing dependencies. Simplified the codebase by removing unused modules and adopting a more streamlined configuration setup.

(This commit message was AI-generated.)

Signed-off-by: Jens Oliver Meiert <[email protected]>
Removed "yargs" from dependencies, marked several packages as dev dependencies, and updated the package version to 4.2.0 in package.json and package-lock.json. This change ensures cleaner dependency management and alignment with intended usage.

(This commit message was AI-generated.)

Signed-off-by: Jens Oliver Meiert <[email protected]>
Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

The update removes the yargs dependency from the project and updates the package version from 4.1.4 to 4.2.0 in the package.json file. In addition, changes in src/index.js modify the command-line argument parsing by removing the hideBin import from yargs/helpers and replacing it with Node’s built-in parseArgs function. An options object is now defined with properties dry, ignore, and staged to manage the argument parsing. These changes streamline dependency management and adjust how CLI inputs are processed.

Changes

File(s) Change Summary
package.json Removed "yargs": "^17.7.2" dependency; updated version from "4.1.4" to "4.2.0".
src/index.js Removed import of hideBin from yargs/helpers; added import of parseArgs from node:util; restructured CLI argument parsing using an options object with properties dry, ignore, and staged.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI_Script
    participant NodeUtil as parseArgs

    User->>CLI_Script: Execute command
    CLI_Script->>CLI_Script: Define options {dry, ignore, staged}
    CLI_Script->>NodeUtil: Call parseArgs with process.argv and options
    NodeUtil-->>CLI_Script: Return parsed arguments (argv)
    CLI_Script->>CLI_Script: Process arguments based on returned argv
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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. (Beta)
  • @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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/index.js (1)

9-14: LGTM! Clean implementation of parseArgs.

The migration from yargs to Node's built-in parseArgs is well-structured:

  • Clear type definitions for each option
  • Maintains the same functionality as before
  • Reduces external dependencies

Consider documenting these CLI options in the README to help users transition from yargs to the new implementation.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3820893 and c12db42.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (2 hunks)
  • src/index.js (1 hunks)
🔇 Additional comments (3)
package.json (2)

43-43: LGTM! Version bump follows semver.

The version bump from 4.1.4 to 4.2.0 correctly follows semantic versioning for feature changes (removing a dependency).


12-12:

✅ Verification successful

Verify the simple-git version for security advisories.

Let's ensure the fixed version of simple-git is secure and up-to-date.


🏁 Script executed:

#!/bin/bash
# Description: Check for security advisories and latest versions of the simple-git library.

# Check npm for latest versions
curl -s https://registry.npmjs.org/simple-git | jq '.["dist-tags"].latest'

# Check for security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "simple-git") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 1272


Security Verification Complete: simple-git Version 3.27.0 is Secure

  • The npm registry confirms we are using simple-git version 3.27.0.
  • All reported vulnerabilities (affecting versions below 3.5.0, 3.15.0, 3.16.0, and 3.3.0) have been patched above our current version.

No changes are needed regarding the simple-git version.

src/index.js (1)

5-5:

❓ Verification inconclusive

Verify Node.js version compatibility for parseArgs.

The parseArgs function was introduced in Node.js v16.17.0. Let's ensure the project's minimum Node.js version is compatible.


🌐 Web query:

When was node:util parseArgs introduced and what is its current status?

💡 Result:

The node:util module's parseArgs function was introduced in Node.js v18.3.0 (released June 2022)[2][7]. Initially marked as experimental[2][7], it has since evolved into a stable feature for parsing command-line arguments without requiring external dependencies[1][5].

As of Node.js v23.8.0 (current documentation):

  • It supports boolean and string option types with short/long aliases[1][4]
  • Handles positional arguments and option terminators (--)[4]
  • Provides tokenized parsing details when using tokens: true[1]
  • Supports default values and multiple occurrences[3][4]
  • Is considered a core utility for CLI development[5][7]

Key milestones:

  • v18.11.0 (2022): Added default value support[10]
  • v18.7.0: Introduced token tracking[10]
  • Current implementation shows no experimental warnings in official docs[1], indicating full stability.

Example from current implementation:

import { parseArgs } from 'node:util';

const options = {
  verbose: { type: 'boolean', short: 'v' },
  file: { type: 'string' }
};

const { values } = parseArgs({ options });
console.log(values); // { verbose: true, file: 'data.txt' }

Citations:


Ensure Project Uses Node.js v18.3.0 or Later for parseArgs

Our investigation confirms that the parseArgs function in the node:util module was introduced in Node.js v18.3.0 and is now stable. If your project’s minimum Node.js version is below v18.3.0, please update the required version (e.g., in the package.json engines field) to prevent potential runtime issues. Also, if supporting older versions is necessary, consider alternative approaches or polyfills.

  • File: src/index.js, Line 5
  • Action: Verify and update the Node.js version requirement if necessary.

@j9t j9t merged commit 23db03b into main Feb 24, 2025
3 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.

1 participant