Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This PR bumps up our version of
commander
, which is woefully out of date. The motivation here is to reduce friction to make further improvements to our CLI, since commander's API has changed a lot in the last few years.Note that
commander@11
was the latest major version that supports Node 16, while 13 is the current latest major version.Changes
This migration was done by reading the CHANGELOG.md for
commander
and ensuring that everything compiled in TypeScript.Here's a brief explanation of all the changes.
Named exports
The main
program
object is now a named export.Options syntax
Options for each command are now accessed via the
program.opts()
function rather than being extended on theprogram
object itself.Reading from
package.json
Getting the Forge version is necessary to get the
--version
flag to work. We did this inconsistently across our various CLI commands (either viafs.readJson
orrequire
call). TypeScript has theresolveJsonModule
config flag as of TS 2.9.Unknown command handling
We previously handled unknown commands with a custom
command:*
event listener, but newer versions ofcommander
automatically exit with an error when given an unknown subcommand.forge/packages/api/cli/src/electron-forge.ts
Lines 43 to 47 in ec9ba21
Note that I had to move from a
command:*
listener to apreSubcommand
hook becausecommand:*
would swallow any unknown command errors.Pass through arguments
Forge supports passing args through to the Electron executable app via CLI. This was previously implemented by monkeypatching the
program.executeSubCommand
helper function, but that function is no longer part ofcommander
's public API.Instead, the
program.passThroughOptions
helper enables this behaviour directly. Previously, the monkeypatching was done in the rootelectron-forge
command, but this PR changes it to only pass through options onelectron-forge start
.I tested this with a minimal tester app that just printed out
process.argv
in the main process:Adding help text
In theory, we're supposed to add a bit of helper text to instruct users how to pass through args to their Electron application.
forge/packages/api/cli/src/electron-forge-start.ts
Lines 37 to 43 in ec9ba21
However, this doesn't work as of Forge 7.6.1:
This PR fixes that by calling the
addHelpText()
helper function.