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
Yargs crashes when an invalid package.json is the directory tree. #485
Comments
@avribacki Thanks for reporting this! I can confirm this is a potential problem, and it's not limited to when yargs is bundled. I think adding something to the yargs API to disable the package.json lookup is a good idea. When doing so, we should probably invent another way of specifying the yargs-parser configuration options, possibly by accepting a "parserConfig" object that yargs can pass directly to yargs-parser. Would be nice to accomplish both of these with the same API. Thoughts (from anyone)? |
@nexdrew @avribacki Since package.json data never really is mandatory for yargs to work (it could live without that data), I'm simply not sure whether this is a bug to fix or a new config option to add. Thoughts? What I do like is @nexdrew's idea for letting parser options be passed through yargs' configuration, as it currently is only possible to set parser options in the package.json, not in code. |
I think that it would be much more valuable to add a new way of passing the parser options (avoiding the search for the package.json entirely) than fixing the crash. |
@avribacki @maxrimue Yes, I agree. I think this should be a new API method, as you describe. If parser config is given explicitly via the new API method, then yargs should forgo the package.json lookup; otherwise, keep the current functionality and allow a crash on invalid package.json (has to be the first/nearest one found when traversing up parent directories). |
a couple thoughts:
|
@avribacki give this a spin:
should no longer be crashing on you. |
I'm bundling my application using nexe and it works pretty well except for one particular case.
When there's an invalid package.json along the directory from where I'm executing my application, Yargs crashes. If the package.json is valid, it works as normal.
For instance, if try to run "myapp -h" and there's an empty package.json in the same folder, I get the following error:
This might be a corner case and most likely to happen only when yargs is bundled. Otherwise, it will try to use the package.json of the node package and it will likely be OK.
Once bundled, it can run from any location and there might be an invalid package.json lurking around which will produce this crash, which was not obvious to guess the origin.
Yargs seems a perfect fit for command line tools bundled with nexe, that's why I think this deserves a fix.
When I protected the pkgConfig.sync inside parseArgs method, it no longer crashed:
Not sure if this is the best solution. I think that the ideal would be to have an option to disable this pkgConf.sync call as, in the context I presented, I don't expect that some package.json lost in my file system to change the app behavior.
The text was updated successfully, but these errors were encountered: