-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat(cli): allow running scripts with custom shell (#4248) #5133
Conversation
This change will increase the build size from 10.39 MB to 10.4 MB, an increase of 1.43 KB (0%)
|
9b55799
to
790c4ae
Compare
I didn't know NPM could do this. It's, IMO, a dangerous idea to change shells. People's package install scripts are tested to work in Take a look at #4951 for an example of a glob pattern that changes between shells. I haven't looked into the NPM behavior, but I would say that if we only used this setting for |
This is really only needed on Windows, where lots of scripts assume *sh (see the original issue report) and use features that aren't available in cmd.exe (example). As such, I don't expect people to use this on *nix (as you said, there's hardly a good reason to). Edit: I checked the NPM docs and it says that it's only used for I'll modify the PR. |
@rally25rs I made the requested change and manually tested the behavior again. I'm wondering if |
Thanks! |
After some wrangling, I managed to add the test. Just for reference, NPM only tests the passed arguments as well: https://github.com/npm/npm/blob/b2b03733f8cf8983892076d15b830b5913891adb/test/tap/run-script.js#L319 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done. Thanks for the contribution! 👍
@rally25rs a main use for this is to override: https://github.com/yarnpkg/yarn/pull/5133/files#diff-939cc0d319704d4f0d98baf9167ba850R191 My team mandates windows users use bash, and even with cross-env, we still had issues with some scripts on windows. this setting fixed the issues with glad to see this finally land, though too late now that my entire team went to linux heh. |
@BYK why do you think it reverts it? Users have to opt into this, and never binaries still work under git bash just fine? |
@aikar - this PR changes the execution command for all cases, regardless of them using this new option or not: https://github.com/yarnpkg/yarn/pull/5133/files#diff-939cc0d319704d4f0d98baf9167ba850R218 |
@BYK but if a shell isn't set, it would fall into the same windows specific check. The desire here is to explicitly opt out of that code. If shell isn't set, it looks like it behaves the same? |
@BYK I can't seem to reproduce that issue on my computer (Windows 10 x64, Node.js 8.9.3, script-shell not set): I think there's a likely chance that fixCmdWinSlashes fixed it. There actually is an issue replaced to sh backslash handling if script-shell is set, however (I didn't encounter this as I didn't know this was a feature): This can be fixed by assuming a sh-compatible shell if script-shell is set (same as in execute-lifecycle-script): yunyu@691ee08 |
When I say opt out, I meant to opt out of the cmd.exe stuff. Shouldn't it be the user's problem if they set it to a shell that does not handle windows commands correctly? |
@aikar - Although the code looked identical, using the
I think this is the reason why it is not an issue right now since this is what changed in-between that may affect running commands.
I don't think to assume a sh-compatible shell is a good idea on Windows. PowerShell is a common shell replacement for instance. All that said, this is why I think this feature is not a great idea. It adds complexity without covering important edge cases. It is a band-aid solution to this problem that will likely create more issues. The docs for
And the "Default Windows Shell" section states the following:
So essentially, this whole feature can be replaced by simply defining |
@BYK Well if somethings still off, seems rather trivial to simply special case 'shell: true' to the previous behavior. From my understanding, script-shell should be overriding the shell used, and not use comspec if script-shell is set. So this PR satisfies that situation correctly. if script-shell isn't set, then shell shouldn't be changed? https://github.com/yarnpkg/yarn/pull/5133/files#diff-fd065890a349a1c304804a9a9dafe02dR84 |
@BYK the main problem with setting the shell value in opts or setting $COMSPEC is that Node assumes shells on Windows are CMD-compatible, and that shells on *nix are sh compatible: https://github.com/nodejs/node/blob/master/lib/child_process.js#L477 This results in Git Bash/WSL not working (as they don't recognize the |
My team members on Windows used 'npm set script-shell bash', and work specifically out of Git Bash/WSL, so the intent was to stay within the bash ecosystem and not ever jump back through cmd.exe. Based on @yunyu 's response, looks like everythings working correctly and this PR is fine? |
The only problem right now is described in #5133 (comment), but that doesn't break anything that was previously working without a shell set. For compatibility with NPM and targeting the most common use case,, I personally think that assuming a sh-compatible shell is the best approach, but I'm open to discussion. Should I file a new issue for that? |
Summary
This fixes issue #4248, based off of what NPM does.
Test plan
I'm not actually sure how to write a test suite for this (as testing any alternate shell would involve additional installations), but it passes all of the current tests. Any feedback/advice would be appreciated!
Here's how I am manually confirming that the change works (see the
echo $SHELL
output):The Windows terminal emulator (which I am using) doesn't support emojis, which causes the weird characters before the Done message. However, MinTTY should.