Skip to content

refactor: Bump commander from 9.4.0 to 13.1.0 #2778

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 3 commits into from
May 3, 2025

Conversation

dependabot[bot]
Copy link
Contributor

@dependabot dependabot bot commented on behalf of github Apr 30, 2025

Bumps commander from 9.4.0 to 13.1.0.

Release notes

Sourced from commander's releases.

v13.1.0

Added

  • support a pair of long option flags to allow a memorable shortened flag, like .option('--ws, --workspace') (#2312)

v13.0.0

Added

  • support multiple calls to .parse() with default settings (#2299)
  • add .saveStateBeforeParse() and .restoreStateBeforeParse() for use by subclasses (#2299)
  • style routines like styleTitle() to add color to help using .configureHelp() or Help subclass (#2251)
  • color related support in .configureOutput() for getOutHasColors(), getErrHasColors(), and stripColor() (#2251)
  • Help property for minWidthToWrap (#2251)
  • Help methods for displayWidth(), boxWrap(), preformatted() et al (#2251)

Changed

  • Breaking: excess command-arguments cause an error by default, see migration tips (#2223)
  • Breaking: throw during Option construction for unsupported option flags, like multiple characters after single - (#2270)
  • Breaking: throw on multiple calls to .parse() if storeOptionsAsProperties: true (#2299)
  • TypeScript: include implicit this in parameters for action handler callback (#2197)

Deleted

  • Breaking: Help.wrap() refactored into formatItem() and boxWrap() (#2251)

Migration Tips

Excess command-arguments

It is now an error for the user to specify more command-arguments than are expected. (allowExcessArguments is now false by default.)

Old code:

program.option('-p, --port <number>', 'port number');
program.action((options) => {
  console.log(program.args);
});

Now shows an error:

$ node example.js a b c
error: too many arguments. Expected 0 arguments but got 3.

You can declare the expected arguments. The help will then be more accurate too. Note that declaring new arguments will change what is passed to the action handler.

... (truncated)

Changelog

Sourced from commander's changelog.

[13.1.0] (2025-01-21)

Added

  • support a pair of long option flags to allow a memorable shortened flag, like .option('--ws, --workspace') (#2312)

[13.0.0] (2024-12-30)

Added

  • support multiple calls to .parse() with default settings (#2299)
  • add .saveStateBeforeParse() and .restoreStateBeforeParse() for use by subclasses (#2299)
  • style routines like styleTitle() to add color to help using .configureHelp() or Help subclass (#2251)
  • color related support in .configureOutput() for getOutHasColors(), getErrHasColors(), and stripColor() (#2251)
  • Help property for minWidthToWrap (#2251)
  • Help methods for displayWidth(), boxWrap(), preformatted() et al (#2251)

Changed

  • Breaking: excess command-arguments cause an error by default, see migration tips (#2223)
  • Breaking: throw during Option construction for unsupported option flags, like multiple characters after single - (#2270)
    • note: support for dual long option flags added in Commander 13.1
  • Breaking: throw on multiple calls to .parse() if storeOptionsAsProperties: true (#2299)
  • TypeScript: include implicit this in parameters for action handler callback (#2197)

Deleted

  • Breaking: Help.wrap() refactored into formatItem() and boxWrap() (#2251)

Migration Tips

Excess command-arguments

It is now an error for the user to specify more command-arguments than are expected. (allowExcessArguments is now false by default.)

Old code:

program.option('-p, --port <number>', 'port number');
program.action((options) => {
  console.log(program.args);
});

Now shows an error:

$ node example.js a b c
error: too many arguments. Expected 0 arguments but got 3.

... (truncated)

Commits

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
  • @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
  • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

Summary by CodeRabbit

  • Chores
    • Updated the "commander" dependency to version 13.1.0.

@dependabot dependabot bot added dependencies Bot label; pull requests that updates a dependency file javascript Pull requests that update javascript code labels Apr 30, 2025
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title refactor: bump commander from 9.4.0 to 13.1.0 refactor: Bump commander from 9.4.0 to 13.1.0 Apr 30, 2025
Copy link

coderabbitai bot commented Apr 30, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The change updates the version of the "commander" package in the package.json file from "9.4.0" to "13.1.0". No other dependencies or configuration settings were modified, and there were no changes to the declarations of exported or public entities.

Changes

File Change Summary
package.json Updated "commander" dependency from 9.4.0 to 13.1.0

Sequence Diagram(s)

No sequence diagram is generated as the change only involves a dependency version update without affecting control flow or feature logic.


🪧 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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in 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.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Apr 30, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Copy link

uffizzi-cloud bot commented Apr 30, 2025

Uffizzi Ephemeral Environment deployment-63403

⌚ Updated May 03, 2025, 10:57 UTC

☁️ https://app.uffizzi.com/github.com/parse-community/parse-dashboard/pull/2778

📄 View Application Logs etc.

What is Uffizzi? Learn more

@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/commander-13.1.0 branch 5 times, most recently from 35a5176 to dd77428 Compare May 3, 2025 01:23
Bumps [commander](https://github.com/tj/commander.js) from 9.4.0 to 13.1.0.
- [Release notes](https://github.com/tj/commander.js/releases)
- [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md)
- [Commits](tj/commander.js@v9.4.0...v13.1.0)

---
updated-dependencies:
- dependency-name: commander
  dependency-version: 13.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@dependabot dependabot bot force-pushed the dependabot/npm_and_yarn/commander-13.1.0 branch from dd77428 to 387230c Compare May 3, 2025 10:51
@mtrezza mtrezza closed this May 3, 2025
Copy link
Contributor Author

dependabot bot commented on behalf of github May 3, 2025

OK, I won't notify you again about this release, but will get in touch when a new version is available. If you'd rather skip all updates until the next major or minor version, let me know by commenting @dependabot ignore this major version or @dependabot ignore this minor version. You can also ignore all major, minor, or patch releases for a dependency by adding an ignore condition with the desired update_types to your config file.

If you change your mind, just re-open this PR and I'll resolve any conflicts on it.

@mtrezza mtrezza reopened this May 3, 2025
Copy link

🚀 Thanks for opening this pull request!

@mtrezza
Copy link
Member

mtrezza commented May 3, 2025

@coderabbitai review

Copy link

coderabbitai bot commented May 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mtrezza
Copy link
Member

mtrezza commented May 3, 2025

@coderabbitai will this major version upgrade likely cause any issues?

Copy link

coderabbitai bot commented May 3, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all files that import or require the commander package
echo "Files using the commander package:"
rg "require\(['\"]commander['\"]|from ['\"]commander['\"]" -l

# Show the actual usage of commander
echo -e "\nCommander usage:"
rg "require\(['\"]commander['\"]|from ['\"]commander['\"]" -A 10 -B 2

# Check package.json to confirm the version change
echo -e "\nPackage.json commander entry:"
grep -A 1 -B 1 "commander" package.json || echo "Not found in package.json"

# Look for any tests related to commander
echo -e "\nTests related to commander:"
rg "commander" --glob "**/*.test.js" --glob "**/*.spec.js" || echo "No tests found"

Length of output: 2052


🌐 Web query:

What are the breaking changes in commander.js from version 9 to version 13?

💡 Result:

Breaking Changes in commander.js from Version 9 to Version 13

Commander.js introduced several breaking changes across versions 9 through 13. Below are the most significant changes, organized by version, with a focus on those most likely to impact existing codebases.


Version 9

  • Node.js Version Requirement: Commander 9 increased the minimum required Node.js version to 12.20.0[1][3].
  • showSuggestionAfterError Defaults: The showSuggestionAfterError option is now on by default, changing the way errors are displayed[1][3].

Version 12

  • Node.js Core Module Prefixes: Requires prefixed imports for Node.js core modules using node: (e.g., import fs from 'node:fs')[2].
  • Removed TypeScript Definition: The unimplemented Option.fullDescription was removed from the TypeScript definitions[2].

Version 13

This version introduces several notable breaking changes[2]:

Change Details
Excess Command Arguments Now Error Supplying more command arguments than declared is now an error by default. Previously, excess arguments were ignored. You can restore the old behavior with allowExcessArguments()[2].
Unsupported Option Flags During Construction Now Throw If you define an option with multiple characters after a single dash (e.g., -foo), an error is now thrown immediately instead of being silently ignored[2].
Multiple Calls to .parse() May Throw Repeated calls to .parse() will throw an error if storeOptionsAsProperties: true is set, which may occur in some legacy code patterns[2].
Help Formatting Refactored The Help.wrap() method was removed and replaced by formatItem() and boxWrap(). If you customized help output, you must update to the new API[2].

Migration Tip Example for Excess Arguments:

It is now an error for the user to specify more command-arguments than are expected. (allowExcessArguments is now false by default.)
You can suppress this error for legacy code by calling program.allowExcessArguments()[2].


Summary Table of Major Breaking Changes (v9–v13)

Version Breaking Change How to Update / Mitigate
9 Minimum Node.js: v12.20.0+ Upgrade your Node.js runtime
13 Excess command-args error by default Explicitly declare expected arguments or call allowExcessArguments()
13 Throw on invalid option flags (e.g., -foo) Use supported option flag formats only
13 .parse() throws if called repeatedly with properties Avoid multiple .parse() calls when using storeOptionsAsProperties: true
13 Help.wrap() removed, replaced by formatItem()/boxWrap() Migrate custom help formatting to the new methods

These breaking changes are especially relevant for projects actively using argument parsing, custom option flags, or custom help output. Upgrading across these versions should be done with careful testing to ensure existing CLI behavior remains correct. For more detailed migration tips, consult the commander.js changelog[2].

Citations:


🏁 Script executed:

#!/bin/bash
# Check the complete usage pattern in the Parse-Dashboard/index.js file
echo "Complete commander usage in Parse-Dashboard/index.js:"
cat Parse-Dashboard/index.js

Length of output: 3200


@mtrezza Based on my analysis, this major version upgrade of "commander" from 9.4.0 to 13.1.0 is unlikely to cause issues in your codebase. Here's why:

  1. The commander package is only used in Parse-Dashboard/index.js with a straightforward pattern of defining options and parsing them once.

  2. The key breaking changes in commander v13 include:

    • Excess command arguments now error by default (but you only use named options)
    • Stricter validation of option flag formats (your options all use the proper format)
    • Multiple calls to .parse() may throw (you only call .parseAsync() once)
    • Help formatting API changes (you don't customize help output)
  3. Your code is already using the modern Commander.js API with program.parseAsync() and program.opts(), which is good.

The usage pattern in your codebase is quite simple and doesn't appear to rely on any of the features that changed between versions 9 and 13. Of course, it's always good practice to test thoroughly after the upgrade, but from code analysis alone, this upgrade looks safe.

@mtrezza
Copy link
Member

mtrezza commented May 3, 2025

@coderabbitai CI job tests fail. Review them and the code and make suggestions on how to fix it.

Copy link

coderabbitai bot commented May 3, 2025

Tip

For best results, initiate chat on the files or code changes.

@mtrezza
Copy link
Member

mtrezza commented May 3, 2025

@coderabbitai

The test "Config options › should reject to start if config and other options are combined" fails at line

program.option('--appId [appId]', 'the app Id of the app you would like to manage.');

With error:

TypeError: program.option is not a function

Copy link

coderabbitai bot commented May 3, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@mtrezza Thanks for providing the specific error. This definitely helps narrow down the issue. The test is failing because the initialization pattern for commander has changed in version 13.

Looking at the error TypeError: program.option is not a function, the problem is that the commander package is not being properly initialized in the new version. Here's how to fix it:

In all files where commander is initialized (especially in Parse-Dashboard/index.js and any test files), you need to change:

// Old pattern (v9)
const program = require('commander');

To the new pattern (v13):

// New pattern (v13)
const { Command } = require('commander');
const program = new Command();

Commander v13 requires explicit instantiation of the Command class, whereas in v9 you could use the module directly. This is a breaking change in the API.

After making this update, the tests should pass since program.option() will properly exist as a method again.


🏁 Script executed:

#!/bin/bash
# Find the test file containing the failing test
echo "Searching for test file with 'should reject to start if config and other options are combined'..."
rg -l "should reject to start if config and other options are combined" --type js

# Look at how commander is initialized in Parse-Dashboard/index.js
echo -e "\nChecking commander initialization in Parse-Dashboard/index.js:"
cat Parse-Dashboard/index.js | head -20

# Look at the test file for related commander usage
echo -e "\nSearching for test files that might use commander..."
rg -l "require\(.*commander" --type js

Length of output: 1838


@mtrezza Based on the investigation, the issue is confirmed. The breaking change in commander v13 requires a different initialization pattern.

In Parse-Dashboard/index.js, you need to update the commander initialization from:

const program = require('commander');

To:

const { Command } = require('commander');
const program = new Command();

This is a breaking change in commander v13 - the package no longer exports a pre-initialized Command instance, but instead requires you to explicitly create one. The test is failing because program.option is no longer a function with the current initialization method.

After making this change, the tests should pass as program.option() will be properly available again. No other changes should be needed if this is the only place where commander is initialized in your codebase.


🏁 Script executed:

#!/bin/bash
# Examine the failing test file
echo "Examining the failing test file:"
cat src/lib/tests/e2e/dashboard.e2e.test.js | grep -A 20 "should reject to start if config and other options are combined"

# Check if the test directly interacts with Parse-Dashboard/index.js
echo -e "\nChecking how test might be importing/using index.js:"
rg -A 5 "require\(.*Parse-Dashboard/index" src/lib/tests/e2e/dashboard.e2e.test.js || echo "No direct import of index.js found"

# Check how commander is initialized in the test
echo -e "\nChecking for commander initialization in the test:"
rg "require\(.*commander" src/lib/tests/e2e/dashboard.e2e.test.js || echo "No commander import found in test"

Length of output: 1486


@mtrezza Now I understand what's happening. The test is spawning the Parse-Dashboard/index.js file as a separate process and passing command-line arguments to it.

The fix is clear: you need to update how commander is initialized in Parse-Dashboard/index.js. Change:

const program = require('commander');

To:

const { Command } = require('commander');
const program = new Command();

This change reflects the new initialization pattern required in commander v13. In version 9, you could directly use the imported module, but in version 13, you need to create an instance of the Command class.

After making this change, the program.option function will be available again, and the test should pass. No changes are needed to the test itself, as it's just passing arguments to the index.js file.


🏁 Script executed:

#!/bin/bash
# Look at the full startParseDashboardAndGetOutput function to understand how it runs index.js
echo "Examining the startParseDashboardAndGetOutput function:"
cat src/lib/tests/e2e/dashboard.e2e.test.js | grep -A 30 "function startParseDashboardAndGetOutput"

# Look at the entire file and check the imports at the top
echo -e "\nChecking the imports in the test file:"
cat src/lib/tests/e2e/dashboard.e2e.test.js | head -20

# Look at how processes are spawned in the test
echo -e "\nChecking how processes are spawned in the test:"
rg "spawn|exec|fork" src/lib/tests/e2e/dashboard.e2e.test.js

Length of output: 1875


@mtrezza Great! I've found the root cause. The test is spawning Parse-Dashboard/index.js as a separate process, and the issue is in how commander is initialized in that file.

The fix is straightforward - you need to update the commander initialization in Parse-Dashboard/index.js from:

const program = require('commander');

To the commander v13 pattern:

const { Command } = require('commander');
const program = new Command();

In commander v9, the package exported a pre-initialized Command instance, but in v13, you need to explicitly create one. This is a breaking change in the API.

After making this change, program.option() will be available again and the test should pass without any further changes.

@mtrezza mtrezza merged commit e2c0398 into alpha May 3, 2025
15 of 19 checks passed
@mtrezza mtrezza deleted the dependabot/npm_and_yarn/commander-13.1.0 branch May 3, 2025 20:22
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 7.2.0-alpha.1

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label May 6, 2025
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 7.2.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Bot label; pull requests that updates a dependency file javascript Pull requests that update javascript code state:released Released as stable version state:released-alpha Released as alpha version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants