jjangga0214 / hasura-cli

Hasura CLI as an npm package
https://www.npmjs.com/package/hasura-cli
90 stars 27 forks source link

Executing hasura command opens new CMD console on Windows #19

Closed biased-badger closed 4 years ago

biased-badger commented 4 years ago

OS

Windows 10

Versions

hasura-cli: 1.0.0 Node: v12.13.1 npm: 6.13.4

Description

Not sure if it's a bug or normal behaviour. When running hasura from any terminal other than CMD - it opens new CMD window, executes command and immediately closes. It is not very convenient in case you want to see the output. For example, when executing hasura migrate status

final_5e0b1ed498f7ae0014c7103b_141885

Reproduction

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.61. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

jjangga0214 commented 4 years ago

@uberpwner Thank you for reporting this!

Every published version of hasura-cli passed end-to-end tests on both Windows 10 and Windows 2016. But only CMD was used during the tests. That might be why this behavior was not observed.

I am not so familiar with Windows-specific behavior (help wanted label). So, I'd like to ask 2 things, if possible.

Theoretically, this can be either a Powershell, node, npm, hasura-cli, or Windows problem, or caused by some complex combination. To reduce possibility, if available, do you mind testing with another shell instead of CMD and Powershell (Though I don't know whether there is another kind)?

By the way, for you information, here's how hasura-cli works (in order) on Windows.

  1. User(you) executes hasura <arg>.
  2. hasura in $PATH is a symlink npm created when installed.
  3. The symlink designates your\global\node_modules\hasura-cli\bin\hasura, as hasura is specified on bin in package.json.
  4. your\global\node_modules\hasura-cli\bin\hasura <arg> is given to Windows.
  5. Windows ignores your\global\node_modules\hasura-cli\bin\hasura, but executes your\global\node_modules\hasura-cli\bin\hasura.exe. (A dummy text file hasura and hasura.exe coexists. More detail in hasura-cli#how-does-this-work)
  6. Windows executes your\global\node_modules\hasura-cli\bin\hasura.exe <arg>

And secondly, would you please delete a dummy text file your\global\node_modules\hasura-cli\bin\hasura, and try again? (tip. execute where hasura to track the symlink, if you don't know the path)

Here's another question.

Have you(or someone) experienced(or heard) a similar experience with Powershell or npm (or with something else) before?

Any guess or information that might be possibly helpful is welcome. For example, how a certain process (by hasura.exe in this case) can spawn new "child process" of CMD, or how powershell and CMD are different when it comes to dealing with process.

I will also look into why this happens.

Thank you again, for reporting the issue!

biased-badger commented 4 years ago

@jjangga0214 First of all, I forgot to mention, that I have NVM v1.1.7 to switch between node versions, but I guess it's not relevant to this issue.

As for your questions, I got this results:

Different shells:

I have 3 different shells, CMD, Powershell, and Git Bash.

Executing where hasura produces this output:

C:\Program Files\nodejs\hasura
C:\Program Files\nodejs\hasura.cmd

Opening this path redirects me to C:\Users\misha\AppData\Roaming\nvm\v12.13.1, where I found 3 files: hasura (bash script), hasura.cmd (cmd script) and hasura.ps1 (powershell script). I tryed calling them all from all shells. Here are the results:

Removed dummy text file

So it looks like removing dummy file solves this issue in all shells available to me.

Question about similar experience

No, I have never experienced or heard of such behaviour.

If you need to check more details on Windows environment - I'll be happy to help.

jjangga0214 commented 4 years ago

@uberpwner Great! This information is very helpful 👍 I'll patch and test if it then really works on Windows :) (But a PR on any issue is always welcome if anyone wants to contribute, by the way) The next release will have the patch. Thanks a lot :)

voraczech commented 3 years ago

My solution for bash (in case someone still needs it, I have problems with versions 1.3.1/1.3.2):

1) find your hasura file path

where hasura

2) Open hasura file (not hasura.cmd). You should see this:

"$basedir/node_modules/hasura-cli/hasura"   "$@"
exit $?

3) Replace it with this:

"$(dirname "$0")/node_modules/hasura-cli/hasura"   "$@"
exit $?

I am not a bash expert, so any improvement will be welcomed. Though, this works for me well, so it could help somebody else.