Skip to content
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

fix(start): pass app args with correct amount of -- #3879

Merged
merged 1 commit into from
Mar 12, 2025

Conversation

erickzhao
Copy link
Member

Problem statement

Fixes #3873.

In #3848, we upgraded the commander library from v4 to v11, which brought in half a decade's worth of updates.

This change required us to use the newer passThroughOptions() setting to pass args to process.argv instead of to the program itself. I had previously tested that this worked specifically with the following invocation:

yarn start -- --inspect-electron -- --arg1 --arg2

However, as reported in the aforementioned issue, this approach didn't work with yarn start yarn start -- -- --arg1 --arg2 when attempting to pass in app args without passing any args to Forge.

Root cause

By inspecting the value of process.argv at the top level of electron-forge-start.ts, I noticed that the -- values were being swallowed, leading to args being passed straight to the CLI instead of the app itself. However, all -- args were being passed properly to the top-level electron-forge.ts file.

I think I had passThroughOptions misconfigured by not setting it at the top level, meaning that electron-forge would swallow one set of -- params even before it would touch the electron-forge start command level.

Test cases

We don't have CLI-level tests in Forge, so I went around and tested this manually.

With npm start:

$ npm start -- -- --remote-debugging-port=9222

> [email protected] start
> electron-forge start -- --remote-debugging-port=9222

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [0.1s]
✔ Running generateAssets hook
✔ Running preStart hook


DevTools listening on ws://127.0.0.1:9222/devtools/browser/9c325fd8-49ce-4f9e-aa34-82ba23742c6d

With yarn start:

$ yarn start -- -- --remote-debugging-port=9222

yarn start -- -- --remote-debugging-port=9222
yarn run v1.22.22
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ electron-forge start -- --remote-debugging-port=9222
✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [0.1s]
✔ Running generateAssets hook
✔ Running preStart hook


DevTools listening on ws://127.0.0.1:9222/devtools/browser/4988f349-e621-470d-9150-6473f90f51e1

With npx electron-forge start:

$ npx electron-forge start -- --remote-debugging-port=9222
✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [0.1s]
✔ Running generateAssets hook
✔ Running preStart hook


DevTools listening on ws://127.0.0.1:9222/devtools/browser/34d362be-29c5-49a5-9e37-dd70e7153ff2

Validating that there are no regressions with passing a CLI flag to Forge before passing additional args to the Electron app:

> npx electron-forge start --inspect-electron -- --remote-debugging-port=9222
✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [0.1s]
✔ Running generateAssets hook
✔ Running preStart hook

Debugger listening on ws://127.0.0.1:9229/06515d95-2934-4e72-8763-6c4831f545d9
For help, see: https://nodejs.org/en/docs/inspector

DevTools listening on ws://127.0.0.1:9222/devtools/browser/f837a86f-a45c-464d-89ad-4750579c7701

@erickzhao erickzhao requested a review from a team as a code owner March 11, 2025 23:12
@erickzhao erickzhao added this pull request to the merge queue Mar 12, 2025
Merged via the queue into main with commit d9323d7 Mar 12, 2025
12 checks passed
@erickzhao erickzhao deleted the fix/start-app-args branch March 12, 2025 01:21
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.

-- Command Arguments Cannot Be Passed to Electron
2 participants