You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dependency of husky run-node might not be suitable on Windows #228
Oh yes, in the shell environment, husky works
well. But in Gitkaren (a git gui tool), it doesn't work anymore. I've heard that in some system gui program will not inherit some environment they shell program will, is that the key ?
I'm using husky on Windows + VSCode + PowerShell but didn't encounter this issue.
This only works if you have access to Git for Windows, which bundles a bash shell and knows how to invoke it natively.
I work on GitHub Desktop, which ships an embedded Git that is stripped of much of the UNIX toolchain that comes with Git for Windows. We had a report about this change breaking for at least one user: desktop/desktop#3860
Unless there are specific features of the Bash shell you plan to use, I'd recommend staying with #!/bin/sh as that will continue to be supported across more setups (I tested this on 0.14.3 and it works fine).
Reacted by Mark Goho, William Shepherd, Herve Fulchiron and Dr. Derek Austin
I imagine that run-node really requires bash and couldn't work with sh only.
I'm not really familiar with run-node, so here's what I did to test this theory. All commands are running in Command Prompt on Windows, to ensure I don't accidentally have a bash shell handy.
I have NodeJS installed, but it's not in my PATH, to ensure we're using run-node as best as possible.
> node'node' is not recognized as an internal or external command,operable program or batch file.
Here's the contents of the package.json file I'm using to demo this:
Here's the contents of a simple pre-commit hook, to ensure it gets invoked by Git:
> type .git\hooks\pre-commit#!/bin/sh./node_modules/.bin/run-node -e "console.log('hello world');"
I've tweaked the run-node.cmd file that NodeJS generated and adds to node_modules/.bin to replace all mentions of /bin/bash to /bin/sh - I'm not sure if this looks at the script header when generating it, I guess so?
And I tweaked the run-node script itself to require /bin/sh. Everything else after the first line is unchanged.
> type node_modules\run-node\run-node#!/bin/sh
# MIT License © Sindre Sorhus...
And then I try to commit without any staged changes:
> git statusOn branch masternothing to commit, working tree clean
> git commit -m "whatever"Couldn't find the Node.js binary. Ensure you have Node.js installed. Open an issue on https://github.com/sindresorhus/run-nodeOn branch masternothing to commit, working tree clean
So this worked fine when I had node on my PATH (it printed hello world before the git output to the console), but without node on my PATH I see it spawn run-node and fail. I don't see anything Windows-specific in the run-node source about it looking at known installation locations, so you're not getting any benefits from using run-node in it's current form on the platform.
Activity
typicode commentedon Jan 31, 2018
Hi @Jack-Works,
Thanks for raising this issue.
When Git runs hooks, it should run them in a shell, so even on Windows it should work (e.g.
v0.14is creating shell scripts https://github.com/typicode/husky/blob/master/src/utils/get-hook-script.js#L52)I'm using husky on Windows + VSCode + PowerShell but didn't encounter this issue.
What are the tools you're using? How did you install Git?
Jack-Works commentedon Jan 31, 2018
Oh yes, in the shell environment, husky works
well. But in Gitkaren (a git gui tool), it doesn't work anymore. I've heard that in some system gui program will not inherit some environment they shell program will, is that the key ?
shiftkey commentedon Feb 1, 2018
This only works if you have access to Git for Windows, which bundles a bash shell and knows how to invoke it natively.
I work on GitHub Desktop, which ships an embedded Git that is stripped of much of the UNIX toolchain that comes with Git for Windows. We had a report about this change breaking for at least one user: desktop/desktop#3860
Unless there are specific features of the Bash shell you plan to use, I'd recommend staying with
#!/bin/shas that will continue to be supported across more setups (I tested this on0.14.3and it works fine).typicode commentedon Feb 2, 2018
Thank you @shiftkey for the detailed explanation. I've just changed default branch to
masteragain (i.e.v0.14) until it's figured out.And
v0.15is behind a@nextflag.I imagine that
run-nodereally requiresbashand couldn't work withshonly.Maybe checking if
bashis available then userun-node, else just fall back tonodecommand and ifnodeisn't available show a message.What do you think?
shiftkey commentedon Feb 2, 2018
I'm not really familiar with
run-node, so here's what I did to test this theory. All commands are running in Command Prompt on Windows, to ensure I don't accidentally have a bash shell handy.I have NodeJS installed, but it's not in my
PATH, to ensure we're usingrun-nodeas best as possible.Here's the contents of the
package.jsonfile I'm using to demo this:Here's the contents of a simple pre-commit hook, to ensure it gets invoked by Git:
I've tweaked the
run-node.cmdfile that NodeJS generated and adds tonode_modules/.binto replace all mentions of/bin/bashto/bin/sh- I'm not sure if this looks at the script header when generating it, I guess so?And I tweaked the
run-nodescript itself to require/bin/sh. Everything else after the first line is unchanged.And then I try to commit without any staged changes:
So this worked fine when I had
nodeon myPATH(it printedhello worldbefore the git output to the console), but withoutnodeon my PATH I see it spawnrun-nodeand fail. I don't see anything Windows-specific in therun-nodesource about it looking at known installation locations, so you're not getting any benefits from usingrun-nodein it's current form on the platform.typicode commentedon Feb 5, 2018
Thanks for all the testing!
v0.15.0-rc.5has been published under@nexttag, it usesshand generates a different script on Windows that doesn't rely onrun-node.So upgrading to this version should fix the issue on GitHub Desktop + Windows.