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(run): pass cli args to nw process #156

Merged
merged 9 commits into from
Apr 27, 2024
Merged

fix(run): pass cli args to nw process #156

merged 9 commits into from
Apr 27, 2024

Conversation

ayushmanchhabra
Copy link
Collaborator

@ayushmanchhabra ayushmanchhabra commented Apr 26, 2024

Fixes: #150

@ayushmanchhabra
Copy link
Collaborator Author

ayushmanchhabra commented Apr 26, 2024

I am able to verify that arguments are passed to nw by creating the UserData dir in a custom location. Executing npm run demo creates it under test/fixture/user-data

@ayushmanchhabra
Copy link
Collaborator Author

@ronny1982 ping, do you wanna test this PR?

Steps to test:

  1. npm uninstall nw
  2. npm install https://github.com/nwjs/npm-installer/tree/dev-150-2

src/run.js Outdated Show resolved Hide resolved
src/cli.js Outdated Show resolved Hide resolved
@ronny1982
Copy link

ronny1982 commented Apr 26, 2024

The command-line help is incorrect

# nw --help
(node:13867) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Usage: nw [options] [app]

Options:
  --version <string>
  --flavor <flavor>
  --platform <platform>
  --arch <arch>
  --cacheDir <cacheDir>
  -h, --help             display help for command

The [options] are listed before [app], but it should be vice versa.
There is also a JSON import warning shown.

@ronny1982
Copy link

ronny1982 commented Apr 26, 2024

If no cache directory is present, path.resolve('.', 'node_modules', 'nw') is used in parse.js as default.
Since path.resolve uses the working directory this may lead to invalid results (e.g., when using NPM workspaces).

Maybe it would be more reliable to use the application path itself as base e.g., something like path.resolve(path.dirname(process.argv[1]), '..', 'nw').

@ronny1982
Copy link

ronny1982 commented Apr 26, 2024

@ronny1982 ping, do you wanna test this PR?

Steps to test:

  1. npm uninstall nw
  2. npm install https://github.com/nwjs/npm-installer/tree/dev-150-2

Tested locally and added feedback/findings related to command-line args processing in the comment section.

@ayushmanchhabra
Copy link
Collaborator Author

If no cache directory is present, path.resolve('.', 'node_modules', 'nw') is used in parse.js as default. Since path.resolve uses the working directory this may lead to invalid results (e.g., when using NPM workspaces).

Maybe it would be more reliable to use the application path itself as base e.g., something like path.resolve(path.dirname(process.argv[1]), '..', 'nw').

Not sure how nw would fail in a workspace - could you give an example/repro? Btw, this is should be addressed in another PR.

@ayushmanchhabra ayushmanchhabra changed the title fix(run): pass cli args to nw process and unref child process fix(run): pass cli args to nw process Apr 27, 2024
@ronny1982
Copy link

Not sure how nw would fail in a workspace - could you give an example/repro? Btw, this is should be addressed in another PR.

Created #157

@ayushmanchhabra
Copy link
Collaborator Author

ayushmanchhabra commented Apr 27, 2024

Although unknown args are now accepted, there are a few issues:

  1. setting --log-level=verbose does not pipe logs to stdout
  2. log-level values are actually from 0 to 3 but when setting to a valid number, it still does not pipe to stdout

Copy link

@ronny1982 ronny1982 left a comment

Choose a reason for hiding this comment

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

Implementation looks good to me.
Functionality was not further tested/verified.

src/postinstall.js Outdated Show resolved Hide resolved
@ronny1982
Copy link

ronny1982 commented Apr 27, 2024

Although unknown args are now accepted, there are a few issues:

  1. setting --log-level=verbose does not pipe logs to stdout
  2. log-level values are actually from 0 to 3 but when setting to a valid number, it still does not pipe to stdout

The issue was focusing on passing args to the NW.js app, which is solved by this PR.
I probably picked a bad example which implies further functionality, this was not intended.
Could probably have used a more appropriate example such as --my-app-theme=darkmode.

@ayushmanchhabra ayushmanchhabra merged commit e5d6fb1 into main Apr 27, 2024
3 checks passed
@ayushmanchhabra ayushmanchhabra deleted the dev-150-2 branch April 27, 2024 13:03
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.

CLI arguments are not passed through to NW.js app
2 participants